|
-
Mar 17th, 2008, 02:58 AM
#1
Thread Starter
Hyperactive Member
[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
-
Mar 17th, 2008, 09:04 AM
#2
Re: [2005] Print Preview & Print
-
Mar 18th, 2008, 12:19 AM
#3
Thread Starter
Hyperactive Member
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.
-
Mar 18th, 2008, 12:25 AM
#4
Lively Member
Re: [2005] Print Preview & Print
 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>)
-
Mar 18th, 2008, 01:03 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Print Preview & Print
 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
-
Mar 18th, 2008, 01:22 AM
#6
Re: [2005] Print Preview & Print
 Originally Posted by csKanna
Can't we use Print Preview dialog to show the PDF preview 
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.
-
Mar 18th, 2008, 02:26 AM
#7
Thread Starter
Hyperactive Member
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.
-
Mar 18th, 2008, 02:35 AM
#8
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.
-
Mar 18th, 2008, 03:42 AM
#9
Thread Starter
Hyperactive Member
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.
-
Mar 18th, 2008, 07:12 AM
#10
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.
-
Mar 18th, 2008, 10:17 AM
#11
Re: [2005] Print Preview & Print
For a quick and easy to maintain way for doing this would be this suggestion:
 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.
-
Mar 18th, 2008, 09:40 PM
#12
Thread Starter
Hyperactive Member
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.
-
Mar 18th, 2008, 09:45 PM
#13
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|