[2005] Print Preview & Print
Hi,
I am developing a VB.Net application. I have a PDF file which I would like to print. My application has to show the PDF file in a print preview dialog and then should show print dialog to the user. so that the user can select the desired printer and shoot print out.
Can you point me to few code examples to achieve my requirement?
Thank you
Re: [2005] Print Preview & Print
Re: [2005] Print Preview & Print
Thanks for the link. It just uses the text from the rich text box and shows it in a print preview dialog. I would like to show an existing PDF file. Is it possible ? If yes, how ?
Thanks a lot.
Re: [2005] Print Preview & Print
Quote:
Originally Posted by csKanna
Thanks for the link. It just uses the text from the rich text box and shows it in a print preview dialog. I would like to show an existing PDF file. Is it possible ? If yes, how ?
Thanks a lot.
Try to use WebBrowser control and load PDF this way :
WebBrowser1.Navigate(<file path>)
Re: [2005] Print Preview & Print
Quote:
Originally Posted by ionut_y
Try to use WebBrowser control and load PDF this way :
WebBrowser1.Navigate(<file path>)
Can't we use Print Preview dialog to show the PDF preview :confused:
Re: [2005] Print Preview & Print
Quote:
Originally Posted by csKanna
Can't we use Print Preview dialog to show the PDF preview :confused:
No. The PrintPreviewDialog is to preview printed output that you create yourself by performing GDI+ drawing with a PrintDocument. Unless you're going to read the binary contents of the PDF file and then draw a printed representation yourself then the .NET printing components are not applicable. You'll be using either an external PDF viewer, like Adobe Reader, to do the printing or else you could incorporate a PDF-aware component into your project. There are freebies around, like iTextSharp, but I'm not sure whether they support printing or not.
Re: [2005] Print Preview & Print
Okay. thanks for clarification. My requirement is to show the PDf to the user and hit Print. If we do manually the process would be:
1. open the PDF with Acrobat, and
2. Hit Ctrl + P or File > Print (it will show the print dialog)
Let me know your suggestions.
Re: [2005] Print Preview & Print
To send the file to Adobe Reader (or whatever the default PDF handler is) you can create a ProcessStartInfo for the PDF file and set the verb property to "print", then pass it to Process.Start. This is akin to right-clicking the file in Windows Explorer and selecting Print. I don't think you can preview that way though, unless the PDF handler itself is designed to display a preview first.
Re: [2005] Print Preview & Print
Yeah. I already tried that. however, my requirement is simply opening the PDF and then launching the print dialog. The user is not going to check the PDF. he will see the pdf whether our app is printing the correct pdf. nothing else.
Re: [2005] Print Preview & Print
You could add an Adobe Reader ActiveX control to your form and display the PDF there. I don't know for sure but I'm guessing that it would have a print function.
You could also add a WebBrowser control and display the PDF there, just as you would view one in IE. You'd then get a full Adobe Reader instance within the WebBrowser, including Print button, just as you would in IE.
Re: [2005] Print Preview & Print
For a quick and easy to maintain way for doing this would be this suggestion:
Quote:
Originally Posted by jmcilhinney
You could also add a WebBrowser control and display the PDF there, just as you would view one in IE. You'd then get a full Adobe Reader instance within the WebBrowser, including Print button, just as you would in IE.
Re: [2005] Print Preview & Print
thanks. I tried showing the pdf in webbrowser control. however, i am not sure how i can print that?doesn't work. :(
may be i can try sending keystrokes to webbrowser.
Re: [2005] Print Preview & Print
As I have already explained, it is exactly like viewing a PDF in IE, which means that the user is responsible for pressing the Print button.
If you want programmatic access to the document then you'd need to add an Adobe Reader ActiveX control directly to your form.