Help w/ Printing Please!

So far I have been able to set up the document I wish to print, but once I initiate printing I am pretty much lost. I use the following code:

'Print Setup
PrintDocument.DocumentName = (FilePath & "\print.pdf")
PrintDialog.Document = PrintDocument

Dim Result As DialogResult = PrintDialog.ShowDialog()

If (Result = DialogResult.OK) Then
PrintDocument.Print()
End If

Now I am aware that I need to have a subroutine that wil handle the actual printing, but this is where I am stuck. The documents that I wish to print are always going to be in PDF form, but I have no clue what I am supposed to put in here:

'Actual Print Handler
Private Sub PrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage

End Sub

Any help would be greatly appreciated! Thanks!



Answer this question

Help w/ Printing Please!

  • larimore

    I keep getting this error if it helps:

    An unhandled exception of type 'System.ArgumentNullException' occurred in system.drawing.dll

    Additional information: Value cannot be null.


  • pathakn

    I still suggest using the Acrobat component (named AxAcroPDF1 on the forms).
    The user would click your "Print" button.
    Instead of the print dialog, you would show the pdf file in the "AxAcroPDF1" window, which includes the usual Acrobat tools to view, zoom, and print. Selecting the Print button within the Acro window would be no more effort than responding to the print-dialog.

    the code would look something like
    AxAcroPDF1.Visible = True
    AxAcroPDF1.LoadFile(filename)
    AxAcroPDF1.setZoom("100")
    This would be a nearly free solution (no cost for the user) and you would not need to extract images or other fragments of the pdf file. Acrobat effectively takes care of the printing.

    I've also found making my own pdf files gives a better results than the "line" graphics of VB, and I can then print them. That requires knowing the structure of the pdf files, and there is apparently not a user friendly IDE for learning and testing.


  • GRH65

    I have a single "Print" button that the user will push. Other than the "OK" button on the printdialog box, I hope to have no more user interaction. I can get the PDF files into graphic objects (bmp, jpg, or png) to make this task easier, but I haven't been able to print a graphic image from a file either.

    So far this is my expected routine:

    1. User presses "Print" button on form.
    2. Printdialog prompt is displayed & user selects option.
    3. If user selects "OK," then automatically print.

    If sending PDF data to the printer cannot be easily accomplished on my own behalf (or without spending money on third party software) then I can convert the PDF file (two pages at the most) to (a) graphic image(s) and then send this data to the printer.

    You SHOULD be able to send an image to the printer without too much trouble, but as I stated before, I'm just not doing something correctly. Either I send blank pages to the printer or I get an error (shown above). Hasn't anyone ever needed to print automatically before

    Any and all help is greatly appreciated. Thanks!


  • Amit Puri

    My main computer just blew is motherboard so i am trying to use my Toshiba Satellite laptop to print out some past and current year tax forms (irs). When I try to print a form I get a message about a program called acro pdf.dll is running and won't let me continue. Can you help this reasonably geeky tax preparer

  • Brian Gordon

    If it makes the question easier, how would I go about doing this task with an image

    Under the Private Sub PrintDocument_PrintPage I have tried to define a new System.Drawing.Image as the image I want to print. I thought you could use the following code but I get an error. what am I doing wrong

    Dim pImage As System.Drawing.Image
    Dim pPoint As New Point(0, 0)

    pImage.FromFile(FilePath & "\print_1.png")
    e.Graphics.DrawImage(pImage, pPoint)


  • Ali D

    OK, I'm dying here. I've been looking everywhere and I can't find a single tutorial on printing an image from a file. All that keeps happening is that my printer keeps shooting blanks (and I can't believe that I'm telling a bunch of strangers that!).

    I'll explain my dilema in hopes that the VB.NET fairy will magically help me find a solution:

    I have a file that I would like to print out from my program. The file is in PDF form but I can render it to a graphic if need be (jpeg, bmp, png, etc...). I have setup a "Print" button that is supposed to do this action but nothing comes out on paper! When I try certain things, the code tells me that I have an error (shown above) and now I am completely stumped. Is printing supposed to be this damn hard Someone PLEASE throw me a life vest. I'm drowning and all I can do at this point is to ask for help!

    Thanks...


  • Brent Clements

    You want to print a pdf file. Do you want to print it from a code command (no user intervention), or do you accept that you need to click at least one more button

    I suggest you use the Adobe Acrobat ActiveX (COM). You select that component, make sure it gets to your toolbox, then pull it from the Toolbox to your form. You then have access to code commands to size it, make it visible (or not) and to Load pdf files. You can display the file within a window on your form (Load) - you then use the commands available within the Acro window - such as Zoom and finally (what you requested) Print.

    You need a full version of Acrobat to develop your program, but other uses only need the free Reader.


  • Help w/ Printing Please!