- https://github.com/pvginkel/PdfiumViewer is recommended if you’re okay with just viewing PDFs.
- However, it’s really, really slow.
- The example source is at https://github.com/heejune/WinForm-PDFjs
If you needed to add PDF support feature into your C# based project, then using the PDFium & PDFViewer will be the easiest approach. Just include the PDFium via nugget package. You can also find the PdfiumViewer is on the github(https://github.com/pvginkel/PdfiumViewer).
However, the wrapper control only provides basic features so that you might need to consider different solutions in case you required another features such as highlighting text, searching keyword(PdfiumViewer supports the search, but it only returns position information rather actually selecting searched keywords). That’s why I tried to embed the PDFjs into a C# project.
The overall process will be like this:
- Include the web browser control into the target project
- Download PDFjs and make the C# code locate it.
- Navigate the web browser control to the viewer.html which is located at ‘pdfjs-1.4.20-dist/web/viewer.html’
- [From C#] Convert the pdf file into base64 string. I did on purpose because the C# application currently I’m writing only handles the PDF as memory buffer. If you could refer to the target PDF as local file, then go with it.
- [From viewere.js] Add a helper function which decodes the base64 into an ArrayBuffer and call PDFViewerApplication.open with it.
Code#1. PDF file into base64 and pass it to webbrowser control
Code#2. Open PDFjs with viewer.js and base64 string
The complete example is https://github.com/heejune/WinForm-PDFjs
Got hints following: