Displaying PDF on WebBrowser Control not working

19,853

AFAIK, the web browser control in WinForms relies on the default PDF reader (usually Acrobat Reader) for displaying PDF files. If you need to display PDF files without requiring any other piece of software to be installed, then you will probably need to use a PDF rendering library in your application. Some examples of PDF rendering libraries:

  • MuPDF A GPL/Commercial viewer with a .net wrapper, you need a commercial license for use on commercial closed-source applications.
  • Amyuni PDF Creator .Net Commercial library for editing or displaying PDF files. Disclaimer: I currently work as a developer of the library.

Another option would be to create a local HTML5 page that renders the PDF file using the project pdf.js, then embeed that page on your web browser control. But this will only work on Windows systems with IE 9.0 or above.

Share:
19,853
Gonzalo.-
Author by

Gonzalo.-

Web developer from Argentina

Updated on June 04, 2022

Comments

  • Gonzalo.-
    Gonzalo.- almost 2 years

    I Have a test.pdf and I want to display it inside in my form.

    My code is very simple:

    public Form1()
            {
                InitializeComponent();
                this.wbPdf.Navigate(@"file:///<fullpath>\test.pdf#toolbar=0");
            }
    

    and it's not working. It's showing me a white page with an "X".

    But if I do instead this:

    this.wbPdf.Navigate(@"file:///<fullpath>\test.pdf#toolbar=0", true);
    

    the IE opened and it showed my pdf. Of course, I tried to use false in the second parameter and it's not working.

    Also, if I tried to do something like

    this.wbPdf.Navigate(@"http://www.google.com");
    

    it showed me google, so I think there isn't any problem of configuration of Web Browser Control

    Any ideas? I'm not will be able to have Acrobat Reader installed, so using ActiveX components is not an option (also, this project is in x64 and I've read that this component is not working very well in x64).

    I want to display the pdf only for viewing inside the form, not in another window.