Print PDF File

J

Jeff Mason

Hi,

I'm looking for a component or code which will allow me to print an existing PDF file
from a VB.NET app.

I need the ability to specify the PDF file and the printer name on which it is to
print, then have the document, er, print.

That's it.

I've tried google, but all I've found are many (many) products which will do all
sorts of things like convert files to PDF as well as print them. They are full
featured applications to do way, way more than I need.

I already have the PDF files, I just need the ability for a user to identify the
document he wants to print, and where to print it.

Can anyone offer some suggestions?

Thanks,
 
E

Eric Moreau

To print a PDF document, you can use this code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myProcess As Process = New Process
'myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.FileName = "C:\!emoreau_misc\Doc\UG-Gestion des
utilisateurs.pdf"
myProcess.StartInfo.Verb = "Print"
myProcess.StartInfo.UseShellExecute = True
myProcess.Start()
myProcess.WaitForInputIdle()

If myProcess.Responding Then
myProcess.CloseMainWindow()
Else
myProcess.Kill()
End If
End Sub

You can read my article of December 2003 titled "The Process component" from
http://emoreau.s2i.com/.

To select a printer, I have another article : "Setting Windows default
printer" (March 2005)

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/
 
J

Jeff Mason

To print a PDF document, you can use this code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myProcess As Process = New Process
'myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.FileName = "C:\!emoreau_misc\Doc\UG-Gestion des
utilisateurs.pdf"
myProcess.StartInfo.Verb = "Print"
myProcess.StartInfo.UseShellExecute = True
myProcess.Start()
myProcess.WaitForInputIdle()

If myProcess.Responding Then
myProcess.CloseMainWindow()
Else
myProcess.Kill()
End If
End Sub

You can read my article of December 2003 titled "The Process component" from
http://emoreau.s2i.com/.

To select a printer, I have another article : "Setting Windows default
printer" (March 2005)

Thanks.

I am aware of the method using ShellExecute. One problem with this for me is that
this presumes that some suitable renderer for the PDF file has been previously
installed on the system and that an appropriate file association has been set up, so
this method requires Acrobat or something like it. Another is that requests will
come from users asking that a given document be printed on a printer specified by the
user. This would mean that I would have to mess with setting the default printer,
which is ugly at best, IMO. I've never seen a satisfactory solution to this issue
either, since it requires the Windows Scripting Host. Yuck.

I'm looking for a solution that doesn't involve Acrobat or the Reader, if possible,
though I admit I didn't state so.

The main issue with Acrobat, et al, is that the code which will be doing the printing
will run on a server, and as I understand it, Adobe licenses don't allow Acrobat to
be used that way.

My Google searches have turned up many products wich will print a PDF file, among a
whole lot of extraneous (for my purposes) features, so it is clear that Acrobat is
not needed to print a PDF.

What is?
 
D

David Browne

Jeff Mason said:
Thanks.

I am aware of the method using ShellExecute. One problem with this for me
is that
this presumes that some suitable renderer for the PDF file has been
previously
installed on the system and that an appropriate file association has been
set up, so
this method requires Acrobat or something like it. Another is that
requests will
come from users asking that a given document be printed on a printer
specified by the
user. This would mean that I would have to mess with setting the default
printer,
which is ugly at best, IMO. I've never seen a satisfactory solution to
this issue
either, since it requires the Windows Scripting Host. Yuck.

I'm looking for a solution that doesn't involve Acrobat or the Reader, if
possible,
though I admit I didn't state so.

The main issue with Acrobat, et al, is that the code which will be doing
the printing
will run on a server, and as I understand it, Adobe licenses don't allow
Acrobat to
be used that way.

That is my understanding too.

You need either a PDF renderer, or a translator to translate PDF to a
language supported by your printer.

I had this same issue and here's the best tool I could find: XPDF


Xpdf is an open source viewer for Portable Document Format (PDF)
files. (These are also sometimes also called 'Acrobat' files, from the name
of Adobe's PDF software.) The Xpdf project also includes a PDF text
extractor, PDF-to-PostScript converter, and various other utilities.




http://www.foolabs.com/xpdf/download.html

This included a command line tool pdftops which will transform a PDF file to
a Postscript file. The postscript file can then be copied to a postscript
printer.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top