Question

I am having an issue with both Adobe Reader and FoxIt Reader when trying to print a PDF document. Both issues are different but a solution to either one will allow me to fix my issue.

The issue I am having with Adobe Reader when trying to print using the following code is that it will not print it to the network printer I specify but just the default printer.

Dim AdobeReader As New Process
AdobeReader.StartInfo.CreateNoWindow = False
AdobeReader.StartInfo.Verb = "print"
AdobeReader.StartInfo.FileName = SQLdr("DocumentName") & ".pdf"
Select Case SQLdr("Priority")
    Case 1
        AdobeReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority1)
    Case 2
        AdobeReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority2)
    Case 3
        AdobeReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority3)
    Case 4
        AdobeReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority4)
    Case 5
        AdobeReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority5)
End Select

AdobeReader.Start()
AdobeReader.WaitForExit(10000)
AdobeReader.Close()

I have also tried the above code with double quotes around the document name and printer name.

The issue I am having with FoxIt is that when I try and print with the following code it will throw this error "No application is associated with the specified file for this operation " on FoxItReader.Start.

Dim FoxItReader As New Process
FoxItReader.StartInfo.CreateNoWindow = False
FoxItReader.StartInfo.Verb = "print"
FoxItReader.StartInfo.FileName = "C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"
Select Case SQLdr("Priority")
    Case 1
        FoxItReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority1)
    Case 2
        FoxItReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority2)
    Case 3
        FoxItReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority3)
    Case 4
        FoxItReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority4)
    Case 5
        FoxItReader.StartInfo.Arguments = String.Format("/t {0} {1}", SQLdr("DocumentName") & ".pdf", printPriority5)
End Select

FoxItReader.Start()
FoxItReader.WaitForExit(10000)
FoxItReader.Close()

With the above code I have also tried having double quotes around the variables but that also didn't work.

Any help with this issue would be much appreciated.

EDIT

Also I forgot to say that both the printer and the PDF file are located on a server so I am trying to use a shared printer and PDF via network paths(\\SERVER\FILE.PDF).

Was it helpful?

Solution

I'd recommend taking a look at what they do in PDFsharp using Adobe Reader / Acrobat to print: http://pdfsharp.codeplex.com/SourceControl/changeset/view/51421#707803

I believe that they have found a way around the default printer issue in their comments:

// AcroRd32.exe /t path printername drivername portname    Executes the reader and prints a file
//                                                         while suppressing the Acrobat print
//                                                         dialog box, then terminating the Reader.
//
// The four parameters of the /t option evaluate to strings.
// printername     The name of the Printer.
// drivername      Your printer drivers name i.e. whatever apperars in the Driver Used box when viewing printer properties.
// portname        The printers port. portname cannot contain any "/" characters; if it does, output is routed to
//                 the default port for that printer.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top