TesseractOCR.vb (contains methods for Optical Character Recognition from images)

PDFViewer.vb (contains the Viewer user control)

I was tempted to move every function over to PDFLibNet (XPDF) which is faster, but after a lot of testing, I decided to use Ghostscript and PDFLibNET. Ghostscript is used for printing, "PDF to image" conversion, and as a secondary renderer in case of XPDF incompatibility. PDFLibNET is used for quick PDF to screen rendering, searching, and bookmarks.

Using the Code

This project consists of 7 DLLs that must all be in the same directory:

FreeImage.dll

FreeImageNET.dll

gsdll32.dll

itextsharp.dll

PDFLibNET.dll

tessnet2_32.dll

PDFView.dll

Due to file size restrictions, I could not include the Ghostscript 8.64 DLL (gsdll32.dll) in the source code. Please download the Win32 Ghostscript 8.64 package from sourceforge.net and place the file "gsdll32.dll" into the \PDFView\lib directory where the other DLLs already exist.

To place a PDF control on form:

Dim PDFFileName AsString = "MyPDF.pdf"Dim PDFViewer AsNew PDFView.PDFViewer
' Specify whether you want to see bookmarks in the control
' Bookmarks are enabled by default
' PDFViewer.AllowBookmarks = False 'Disable bookmarks
' Get the page count of the PDF document if you want to
' conditionally set properties of the PDFViewer control
' Dim PageCount As Integer = PDFViewer.PageCount(PDFFileName)
' To use Ghostscript, UseXPDF = False
' Ghostscript is slower, but is more compatible and has higher quality rendering
' To use XPDF, UseXPDF = True
' XPDF is quite a bit faster than Ghostscript since there is no file i/o involved
' PdfViewer1.UseXPDF = False 'Disables use of XPDF and associated features
' PDFViewer displays the file as soon as the FileName property is set
' File can be a PDF or a TIFF
PDFViewer.FileName = OpenFileDialog1.FileName
PDFViewer.Dock = DockStyle.Fill 'Autosize the viewer control
Me.Controls.Add(PDFViewer)

The essential part of this solution is extracting the current frame to be viewed from a multi-frame (or single frame) image. At first I used System.Drawing to implement it. I found this to be slower than other C++ solutions that use DIBs (Device Independent Bitmaps) to perform graphic conversions.

I then tried implementing FreeImage with a .NET wrapper which gave it a little speed boost. FreeImage also has a ton of image conversion functions which may come in handy if you wanted to extend this into an editor.

I ended up implementing PDFLibNET which gave it a substantial speed boost since the amount of File I/O operations were reduced. Another streamlined routine for extracting one page from a PDF was added to the Ghostscript utility class as well.

Points of Interest

This project was made possible due to various open source libraries that others were kind enough to distribute freely. I would like to thank all of the Ghostscript, FreeImage.NET, iTextSharp, TessNet, and AFPDFLib (PDFLibNet) developers for their efforts.

History

19th June, 2009: 1.0 Initial release

22nd June, 2009: Updated source code to correctly scale printed pages to the Printable Page Area of the printer that is selected

Comments and Discussions

I tried to add the viewer control in my project but it give a error "System.InvalidOperation exception" looks like it does not work with framework higher then 2, Has anybody an idea what to do. The example project is also not working. I tried to run it with Visual Studio Express 2013.

It would be more convenient if besides the existing tools, the author adds some functions for navigating such as Mouse wheel to move up/move down and/or zoom in/zoom out, 4-arrow buttons to move current vision and Page up/Page down to Previous/Next Page

I am not sure how to create some code which creates an instance of a viewer to be able to preview (and preferably edit) a PDF file, even if the security settings have been configured, as this would be useful penetration testing for the PDF file itself.

Since the following code does not seem to help me find any methods I was hoping that you would provide some sample code to illustrate how to read (and amend) URLs stored within existing PDF files. I would probably need to update the timestamp and create an audit trail since this is for professional use as well.

Dim p AsNew PDFReader
p.

NOTE: Unfortunately, there are no methods being displayed by Visual Studio 2013 (trial) here.

Can this control open a password-protected file programmatically? In other words, is there any function in the "PDF viewer Control" that can take the file name and its password in the code behind then view it in the PDF control?

That is awesome solution to display pdf without adode.i used in my project. i displayed the PDF files, but when i move the file from one folder to another programatically , it says that the file is used by another process.

I had the following message when I tried to open the source code in vb 12, Do you know what can I do to fix it? Thank you in advance...

Warning 1 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "PDFLibNet", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. ManejoCarteras

I tried to run the SamplePDFViewer after I opened the solution and I got the following exception:

"An error occurred creating the form. See Exception.InnerException for details. The error is: Could not load file or assembly 'PDFLibNet, Version=1.0.6.6, Culture=neutral, PublicKeyToken=26d87f7d66fb2aee' or one of its dependencies. An attempt was made to load a program with an incorrect format."

Has anyone been able to use this with .NET 4? I am trying to use it with a C# project and keep getting errors "Mixed mode assembly is built against version 'v2.0.50727'". I tried adjusting the app.config file to below, but now I get a different error.

I have the PDF Viewer implemented on a .NET framework 3.5 platform and everything works fine.When I convert the solution to .NET 4.0 and I run the code I get the following error when accessing the FileName-property: