Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
STAMPARE UN PDF CON System.Drawing.Printing
martedì 27 novembre 2007 - 17.03
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
AndreaKpr
Profilo
| Senior Member
265
messaggi | Data Invio:
mar 27 nov 2007 - 17:03
Ciao ragazzi.
Ho già smanettato a nastro, ma ho bisogno di un consulto con voi.
Ho un Pdf salvato su disco e devo effettuare la stampa passanfo da System.Drawing.Printing.
Ma è possibile effettuare tal operazione ???
Ho trovato poco in rete...
Io immaginavo che all' oggetto System.Drawing.Printing.PrintDocument, bastava passagli il Pdf
in formato binario da stampare ed il gioco era fatto...
Ma mi sa che che non è cosi semplice. Qualche dritta ???
RAGA DATEME NA MANO !
fabrizio.
Profilo
| Newbie
4
messaggi | Data Invio:
mer 28 nov 2007 - 10:02
Ciao.
Io ho utilizzato il namespace System.Diagnostics per far partire un processo.
Impostando il .Verb = "Print" invio automaticamente in stampa un file passato come path alla sub PrintAdobePDF.
In pratica si apre la finestra dell'Acrobat Reader che invia subito in stampa il documento (come succede cliccando col tasto destro su un fle pdf nell'esplora risorse e selezionando la voce Print).
Spero questo codice possa esserti di aiuto.
Fabrizio
Imports System.Diagnostics
Sub PrintAdobePDF(ByVal Filename As String)
Dim myProcess As New Process
Try
'Point the process to our Acrobat file
myProcess.StartInfo.FileName = Filename
myProcess.StartInfo.WorkingDirectory = New IO.FileInfo(Filename).DirectoryName
'Since we don't want to see Acrobat's UI (we just want the report printed)
'then suppress the UI and pass the "Print" verb to force Acrobat to only print
myProcess.StartInfo.CreateNoWindow = True
'myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.Verb = "Print"
myProcess.Start()
'Wait until Acrobat has finished heavy processing,
'or 10 seconds whichever comes first
If Not myProcess.HasExited Then
myProcess.WaitForInputIdle(10000)
'Attempt to close Acrobat so it's UI
'doesn't sit on the user's task bar
'loop until we suceed or until we timeout.
'If we timeout, kill Adobe
Dim i As Integer = 1
Dim lbRunning As Boolean = True
While lbRunning And i <= 20
'sleep for 1 second
System.Threading.Thread.Sleep(1000)
'See if the Adobe will exit gracefully Select
Select Case myProcess.HasExited
Case True : lbRunning = False
Case False : lbRunning = Not myProcess.CloseMainWindow
End Select
i += 1
End While
'If it never closed gracefuly, force it out of memory
If lbRunning AndAlso Not myProcess.HasExited Then myProcess.Kill()
myProcess.Dispose()
End If
Catch ex As System.ComponentModel.Win32Exception
'A process error throws a somewhat generic
'Win32Exception object when the source file is not found.
'Capture the Win32Exception object and examine it for a
'File Not Found state. If found, throw a more specific exception
Const ERROR_FILE_NOT_FOUND As Integer = 2
Select Case ex.NativeErrorCode
Case ERROR_FILE_NOT_FOUND : Throw New System.IO.FileNotFoundException
Case Else : Throw New Exception(ex.Message & " (PrintAdobePDF)")
End Select
Catch ex As Exception
'Bubble up the exception and concatinate the name of this procedure
'as a poor man's route trace
Throw New Exception(ex.Message & " (PrintAdobeFile)")
End Try
End Sub
AndreaKpr
Profilo
| Senior Member
265
messaggi | Data Invio:
mer 28 nov 2007 - 10:32
Grazie Fabrizio.
Avevo già pensato a questa metodologia, ma cosi facendo non sono sicuro che la stampante
abbia termiato correttamente la stampa.
O se la stampante sia andata in errore...
babbubba
Profilo
| Senior Member
232
messaggi | Data Invio:
mer 25 nov 2009 - 20:59
Hai trovato una soluzione? Anche io sto cercando un sistema per convertire uno stream da file pdf in un'immagine o qaulcosa da usare con graphics.draw... dentro l'evento print di un printdocument...
Babbubba
www.babbubba.net
Chiedere è curiosità ... rispondere è educazione.
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !