Print PDF File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Mason

    #1

    Print PDF File

    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,
  • Eric Moreau

    #2
    Re: Print PDF File

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

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim myProcess As Process = New Process
    'myProcess.Star tInfo.WindowSty le = ProcessWindowSt yle.Hidden
    myProcess.Start Info.FileName = "C:\!emoreau_mi sc\Doc\UG-Gestion des
    utilisateurs.pd f"
    myProcess.Start Info.Verb = "Print"
    myProcess.Start Info.UseShellEx ecute = True
    myProcess.Start ()
    myProcess.WaitF orInputIdle()

    If myProcess.Respo nding Then
    myProcess.Close MainWindow()
    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)


    "Jeff Mason" <je.mason@comca st.net> wrote in message
    news:t1hvk11kra ege5j5oepmq8de5 gh2suef8f@4ax.c om...[color=blue]
    > 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,[/color]


    Comment

    • Jeff Mason

      #3
      Re: Print PDF File

      On Fri, 14 Oct 2005 11:44:20 -0400, "Eric Moreau"
      <eric.moreau_N_ O_S_P_A_M@video tron.ca> wrote:
      [color=blue]
      >To print a PDF document, you can use this code:
      >
      >Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      >System.EventAr gs) Handles Button1.Click
      >Dim myProcess As Process = New Process
      >'myProcess.Sta rtInfo.WindowSt yle = ProcessWindowSt yle.Hidden
      >myProcess.Star tInfo.FileName = "C:\!emoreau_mi sc\Doc\UG-Gestion des
      >utilisateurs.p df"
      >myProcess.Star tInfo.Verb = "Print"
      >myProcess.Star tInfo.UseShellE xecute = True
      >myProcess.Star t()
      >myProcess.Wait ForInputIdle()
      >
      >If myProcess.Respo nding Then
      >myProcess.Clos eMainWindow()
      >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)[/color]

      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?

      Comment

      • David Browne

        #4
        Re: Print PDF File


        "Jeff Mason" <je.mason@comca st.net> wrote in message
        news:38qvk1hr6n i2r4cg96htuarf1 mpka7209p@4ax.c om...[color=blue]
        > On Fri, 14 Oct 2005 11:44:20 -0400, "Eric Moreau"
        > <eric.moreau_N_ O_S_P_A_M@video tron.ca> wrote:
        >[color=green]
        >>To print a PDF document, you can use this code:
        >>
        >>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        >>System.EventA rgs) Handles Button1.Click
        >>Dim myProcess As Process = New Process
        >>'myProcess.St artInfo.WindowS tyle = ProcessWindowSt yle.Hidden
        >>myProcess.Sta rtInfo.FileName = "C:\!emoreau_mi sc\Doc\UG-Gestion des
        >>utilisateurs. pdf"
        >>myProcess.Sta rtInfo.Verb = "Print"
        >>myProcess.Sta rtInfo.UseShell Execute = True
        >>myProcess.Sta rt()
        >>myProcess.Wai tForInputIdle()
        >>
        >>If myProcess.Respo nding Then
        >>myProcess.Clo seMainWindow()
        >>Else
        >>myProcess.Kil l()
        >>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)[/color]
        >
        > 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.[/color]

        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.






        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


        Comment

        Working...