Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I'm in need of some help to figure out a problem I have printing PDF documents using Process.Start() with the correct parameters. I use Acrobat Reader with the silent printing parameter. My documents are printing (for the most part at least), but they're not coming out in the desired order.
I'm doing this in VB.NET using MS Visual Studio Express 2010.

I use 9 Checkbox controls (CB2 to CB10) and a series of corresponding If--End If's to guide the printing (each Checkbox corresponds to a group of pdf documents). I use a Button_Click event to launch the printing.

The order is not respected, in that, if all 9 Checkboxes are Checked, I get pdf's from Checkbox2, miscellaneous pdf's, then pdf's from Checkbox10, 9, 8...4 with the pdf's from Checkbox3 apparently being ignored for some reason.

Example of my code:
If CheckBox2.Checked = True Then
   PrintFiche2(TextBox4.Text + "Comptabilite.pdf", tempprinter)  'print header page
   ArrayFiches = pdfDir.GetFiles("Contrat\*.pdf") 'Build temp array of files names
   Print2(ArrayFiches, tempprinter) 'print the array of pdfs
   ...get more arrays and print them
End if

If CheckBox3.Checked = True Then
...
End if
...up until CheckBox10


Is there a property I'm not aware of that I can use to really control the order of my documents? The logic is very simple, it's just that this problem is keeping this project from being delivered to the users...
I get the same results whichever printer I use, even a pdf printer, so at least it's not a random kind of thing.

Any guidance would be greatly appreciated!

Thank you!
Posted

You're not showing the code that actually starts the printing so we can only guess. My bet would that you're kicking off print jobs for each of these documents without waiting for the previous document to finish printing. Since the documents are taking different amounts of time to print, but printing all at the same time, you'll get them in the order that each document takes to finish, not the order that you kicked them off in.

If your code waits for the previous document to finish printing before starting a new print job, you'll get them in the correct order.
 
Share this answer
 
Yes, that's what I was thinking too, however I don't know how to go about doing that.

Here is the code that I use to print the jobs:
VB
Sub Print2(ByVal ArrayFiches, ByVal Imprimante)
    Dim Fichier As IO.FileInfo
    Dim pdfName As String
    Dim proc As New Process

    proc.StartInfo.Verb = "print"
    proc.StartInfo.CreateNoWindow = True
    If ArrayFiches.Length > 0 Then
        For Each Fichier In ArrayFiches
            pdfName = Fichier.FullName
            proc.StartInfo.FileName = pdfName
            proc.StartInfo.Arguments = "/t " & pdfName & Imprimante
            proc.Start()
        Next
        proc.Dispose()
    End If
End Sub


There are 9 departments which need pdf documents from 18 possible directories.
Depending on which department (hence my CheckBoxes representing a particular department), I will fetch arrays of pdfs from several of those directories (depending on the needs of each department) and call the above Subroutine for each of these arrays.
Each directory can possibly have several pdfs or none at all.

And so each print job can easily consist of several dozen pdf files being sent to the printer.

I use the latest Acrobat Reader to do the printing and have set it as the default program to open pdf files. I have also set Acrobat Reader to select the paper format according to each page.

Thank you!
 
Share this answer
 
Comments
Dave Kreskowiak 19-Dec-11 10:43am    
First, you don't need the proc.Dispose line.

If you read the documentation on the Process class, you'd see thata it has a WaitForExit method. All you have to do is add that call after your call to Start.
Thanks!

I added:
VB
proc.WaitForExit()
but I get the same results.


And I think it's normal since the process doesn't end, it just gets reused for the next file. In fact, the Acrobat reader remains open in the end which confirms this.

So, in effect, I'm not getting any feedback from Acrobat reader. Unless there are specific events "secretly" generated by AcroRd32.exe I can trap to pause the next call to Start(), I don't know how else I can go about this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900