How to print an image with vb.net 2006

Example requests & Code samples for GdPicture Toolkits.
Post Reply
Ivan Rodriguez
Posts: 3
Joined: Tue Sep 04, 2007 10:54 pm

How to print an image with vb.net 2006

Post by Ivan Rodriguez » Thu Sep 06, 2007 1:02 am

Hi all

I am just new to the forum, bought the pro viewer yesterday

Special thanks to Loic for all her help getting me off the ground.

I am searching for some examples of how to print an image from the pro viewer. I have a vb.net 2006 windows project, and a windows form has an image already loaded in the GD image control with the zoom to fit option.

I would like to add a button that would allow me to request which printer to use, set the printer margins and print the image on a fit to page basis initially, subsequently would lke to print just some heading text on the page and then the image in a slightly smaller size than the page.

Any samples out there.

Thanks

Ivan Rodriguez (Miami Florida)

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Post by Loïc » Thu Sep 06, 2007 10:14 pm

Ivan, let me one day. Today I formatted my development computer.

Tomorow I will install the vb.net 2005 express and I will tell you few steps.

Best regards,

Loïc
Last edited by Loïc on Thu Oct 04, 2007 4:59 pm, edited 1 time in total.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Post by Loïc » Sun Sep 09, 2007 10:55 pm

Hi,

To me, you have 3 solutions with the .NET framework:

First:

You can try to interact with the PrintDialog class of the .net framework.
It is a bit dificult because you need to catch all the user options selected by the user in order to report it into the GdViewer Printing configuration.

I give you a start point (vb.net):

Code: Select all

Dim PrintDialog As New PrintDialog

PrintDialog.AllowPrintToFile = False
PrintDialog.AllowCurrentPage = True
PrintDialog.AllowSelection = False
PrintDialog.AllowSomePages = True
PrintDialog.PrinterSettings.MaximumPage = AxGdViewer1.NumPages
PrintDialog.PrinterSettings.FromPage = 1
PrintDialog.PrinterSettings.ToPage = AxGdViewer1.NumPages
If PrintDialog.ShowDialog() Then
   AxGdViewer1.PrintSetActivePrinter(PrintDialog.PrinterSettings.PrinterName)
   AxGdViewer1.PrintSetFromToPage(PrintDialog.PrinterSettings.FromPage, PrintDialog.PrinterSettings.ToPage)
   AxGdViewer1.PrintSetCopies(PrintDialog.PrinterSettings.Copies)
  AxGdViewer1.PrintImage()
End If

Second:

You can use only the .net framework classes like:
PrintDialog
PrintDocument
PrintPreviewControl
PrintPreviewDialog

I think this is the hardest method but to my mind, its offers to you many extended possibility. I can't give you a sample using this method because I never learned these classes. However I think that Google & MSDN can be a good guides ;)
PS: you can export an Image from the GdViewer object to the .net framework using the GetHBitmap() method:

Code: Select all

Dim Image As System.Drawing.Bitmap
Image.FromHbitmap(AxGdViewer1.GetHBitmap())
Then, it will be easy with a documentation to see how to print an Image in .NET.

Third:

You can build your own printing dialog using the Print methods of the GdViewer classe...


I think there are many other solutions but they are the only ones which I found.

Best regards,

Loïc

Ivan Rodriguez
Posts: 3
Joined: Tue Sep 04, 2007 10:54 pm

Post by Ivan Rodriguez » Mon Sep 10, 2007 7:30 pm

Hi

I think I will go with your first option.

Should I invoke the vb print dialog box first to obtain the printer name or should I just set that as a variable in my program.

What do you think.

Ivan

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Post by Loïc » Tue Sep 11, 2007 9:54 pm

Should I invoke the vb print dialog box first to obtain the printer name or should I just set that as a variable in my program.
Yes, because it is during the show of the print dialog box that the user will select the printer & options to use.

Best regards,

Loïc

Ivan Rodriguez
Posts: 3
Joined: Tue Sep 04, 2007 10:54 pm

Post by Ivan Rodriguez » Wed Oct 10, 2007 12:34 am

Hi Loic

Sorry it took so long to get back to you. just wanted to let you know that the code sample you provided me for printing the image worked straight out of the box without modification.

You may want to have it available for other users. Thanks a zillion.

Ivan

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest