Results 1 to 13 of 13

Thread: [2005] Print Preview & Print

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    [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
    Kanna

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Print Preview & Print

    Does this help?

  3. #3

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    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.
    Kanna

  4. #4
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    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>)

  5. #5

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    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
    Kanna

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Print Preview & Print

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    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.
    Kanna

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    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.
    Kanna

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  12. #12

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Re: [2005] Print Preview & Print

    thanks. I tried showing the pdf in webbrowser control. however, i am not sure how i can print that?
    Code:
    webbrowser.print
    doesn't work.

    may be i can try sending keystrokes to webbrowser.
    Kanna

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width