VB.NET Stampa un PDF utilizzando Foxit Reader o Adobe Reader
-
13-11-2019 - |
Domanda
Ho un problema con Adobe Reader e Foxit Reader quando provo a stampare un documento PDF. Entrambi i problemi sono diversi ma una soluzione a uno mi permetterà di risolvere il mio problema.
Il problema che sto riscontrando con Adobe Reader quando provo a stampare utilizzando il seguente codice è che non lo stamperà sulla stampante di rete che specifico, ma solo sulla stampante predefinita.
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()
Ho anche provato il codice sopra con doppie citazioni attorno al nome del documento e al nome della stampante.
Il problema che sto riscontrando con Foxit è che quando provo a stampare con il seguente codice, lancerà questo errore "Nessuna applicazione è associata al file specificato per questa operazione" su 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()
Con il codice sopra ho anche provato ad avere doppie citazioni attorno alle variabili, ma anche questo non ha funzionato.
Qualsiasi aiuto in questo problema sarebbe molto apprezzato.
MODIFICARE
Inoltre ho dimenticato di dire che sia la stampante che il file PDF si trovano su un server, quindi sto cercando di utilizzare una stampante condivisa e PDF tramite percorsi di rete ( server file.pdf).
Soluzione
Consiglierei di dare un'occhiata a cosa fanno Pdfsharp Utilizzando Adobe Reader / Acrobat per la stampa:http://pdfsharp.codeplex.com/sourcecontrol/changeset/view/51421#707803
Credo che abbiano trovato un modo per aggirare il problema della stampante predefinito nei loro commenti:
// 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.