Displaying a PDF file in WebBrowser Control does not work

I have 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 does not work. This shows me a white page with an "X".

But if I do this:

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

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

Also, if I tried to do something like

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

he showed me google, so I think there is no configuration problem for Web Browser Control

Any ideas? I cannot install Acrobat Reader, so using ActiveX components is not an option (this project is also in x64 , and I read that this component does not work very well in x64 ).

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

+4
source share
1 answer

AFAIK, a WinForms web browser control, uses a standard PDF reader (usually Acrobat Reader) to display PDF files. If you need to display PDF files without having to install any other software, you will probably need to use the PDF rendering library in your application. Some examples of PDF rendering libraries:

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

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

+4
source

Source: https://habr.com/ru/post/1480977/


All Articles