0

I am using Foxit Reader (a PDF Reader) and passing command line arguments to print a pdf pro-grammatically. I understand that we cannot specify the number of copies through command line as from this discussion.

I am developing a win-forms desktop application and for printing multiple copies of PDF document I am using the below code

string foxitReaderInstalledPath = GetFoxitReaderInstalledPath();
while (noOfCopies > 0)
{
Process process = new System.Diagnostics.Process();
process.EnableRaisingEvents = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = foxitReaderInstalledPath;
string arguments = String.Format(@"-t ""{0}"" ""{1}""", this.Path, printerName);
process.StartInfo.Arguments = arguments;
process.Start();
process.WaitForExit();
noOfCopies = noOfCopies - 1;
}

Issue happens when multiple users are giving muliple copies of print to the same printer. The issue is the printed documents gets mixed up in the order in which they get printed. Anyone please let me know how I can avoid this issue?

Many thanks.

Community
  • 1
  • 1
Bhaskar
  • 1,680
  • 7
  • 26
  • 40
  • is the printer a networked printer (TCP/IP)? – Mark Kram Sep 12 '11 at 15:45
  • @Mark, yeah it is a networked printer. Multiple users will giving printouts to it concurrently or at different time. – Bhaskar Sep 12 '11 at 15:47
  • I had a application that I wrote that pages from the same document printed in random order. My work around was to print each page individually so that they would print in the proper order. I think it had something to do with the way the packets were delivered to the printer. – Mark Kram Sep 12 '11 at 15:49

1 Answers1

1

You can't avoid this client-side...

IF you really want to avoid it the "client" app which is used by the users has to just send the file to some "centralized server process" with all relevant params... this "centralized process" can then "serialize" the printing so it occurs in correct order...

BUT if the printer you are printing to is accessible from the users systems then it could still happen that a user sends something to the printer (like an image or word document...) which will be printed and disturbing the order a bit...

I think it would make much more sense if you described what your goal is... perhaps there is some better way to solve all this... are you implementing a print server ?

EDIT - as per comment:

Put the location for the PDF files on a network share... and run your printing code on the same machine which provides the share... ideally the printer is directly connected to that machine... this should provide enough performance and since it is only one central application accessing the printer it should work fine...

I would strongly recommend the use of a PDF library or Acrobat reader so that the printing can use a parameter for NumberOfCopies !

EDIT 2 - as per comment:

Some PDF Libraries:

Community
  • 1
  • 1
Yahia
  • 69,653
  • 9
  • 115
  • 144
  • THe issue is that FoxIt doesn't support "print multiple copies", so the OP has to fake it by submitting multiple copies of the same job. If the only program that does printing is this one, you can implement a mutex so that only one copy can multiprint at a time. This obviously won't help case where somebody goes to Excel and prints at the same time. Another thing you could try is to use the print spooler API to set the `NextJobId` of each job so they run contiguously. (You need print administrator privileges to reorder jobs, though.) – Raymond Chen Sep 12 '11 at 14:15
  • 1
    @Raymond I don't understand your comment... IF you follow the link in the OPs question you can see that he accepted my answer on the other discussion that Foxit doesn't support multiple copies via commandline param... which resulted in the loop... since he writes "multiple users" - the "mutex" you suggest would have to be LAN-wide... my answer provides a "possible solution" / serialized printing (with the exception of "Excel printing user") via a centralized process... – Yahia Sep 12 '11 at 14:24
  • I think we're in agreement. Such a mutex would have yo be cross-machine, which comes with its own issues. – Raymond Chen Sep 12 '11 at 14:31
  • @Yahia Thanks Yahia again for ur care to answer. We had a centrally deployed application which did the printing previously. It was very slow and had poor performance. So we are replacing that with this client side printing. 1. User will be giving print from various applications, PDFs will be generated and stored in a location specific to the user. My application will pick the files and will start to print. Is there a way that we could implement a change to the application to fix this issue. Thanks – Bhaskar Sep 12 '11 at 15:39
  • Thanks, using Acrobat Reader I found that we cannot specify the number of copies while printing. Any suggestion for a good PDF Library? – Bhaskar Sep 12 '11 at 16:03