![]() | Getting Started with Windows Forms PDF Viewer |
This topic contains the following sections:
This section explains how to create an application that displays a PDF file using the WinForms PDF Viewer.
The following assemblies are required in your Windows Forms application to use the PDF Viewer.
Required Assemblies | Description |
---|---|
Patagames.Pdf | The main assembly containing a class library for creating, editing, loading PDF documents, as well as PDF Rendering Engine. |
Patagames.Pdf.WinForms | This component contains the PdfViewer UserControl and other UI controls that are used in the PDF Viewer. |
You can create a PDF Viewer application by simply drag the control from the Visual Studio toolbox and drop in the designer window of your application or by creating the control manually from code.
Follow these steps to drag and drop the PdfViewer from the toolbox.
Create a new WinForms application in Visual Studio.
Open the Visual Studio toolbox.
Navigate to Patagames Pdf.Net SDK tab and drag the PdfViewer toolbox item to the Designer window, it automatically adds the required references to the current application.
![]() |
---|
PdfViewer itself does not contain any UI elements. This allows you to quite freely decorate your interface and organically fit it into the design of your application. All necessary functionality is available through public methods. |
This will add the instance pdfViewer1 to the Designer cs file. The PDF can be loaded in the Form cs file using the LoadDocument method.
//Loading the document in the PdfViewerControl pdfViewer1.LoadDocument("Sample.pdf");
Navigate to Patagames Pdf.Net SDK tab and drag the PdfToolStripMain toolbox item to the Designer window.
This will add the instance pdfToolStripMain1 to the Designer cs file.
Click the pdfToolStripMain1 toolbar on the form, then find the PdfViewer property in the property grid, and select the pdfViewer1 from the drop-down list. This activates the toolbar to work with this instance of PdfViewer, now you can load documents by clicking the Open icon.
In the same way, add other toolbars and controls.
To add control manually from code, follow these steps,
Add Patagames.Pdf.Net.Controls.WinForms namespace.
using Patagames.Pdf.Net.Controls.WinForms; using Patagames.Pdf.Net.Controls.WinForms.ToolBars;
Create PdfViewer instance and load the PDF
//Initializing the PdfViewerControl PdfViewer pdfViewer1 = new PdfViewer(); //Loading the document in the PdfViewerControl pdfViewer1.LoadDocument("Sample.pdf"); //Add PdfViewerControl to the Form Controls.Add(pdfViewer1);
Refer to Working with PdfViewer for more information.
The following screenshots depicts different sections of the PdfViewer control and toolbars.
The height and width of the control.
Padding within the control.
The PageMargin property specifies space between page and page separator.
Page border. The PageBorderColor property allows you to get or set the color of the page border.
Page separator. You can turn off the display of the separators by seting the ShowPageSeparator property to false, or change the color using the PageSeparatorColor property.
Current page highlight. You can turn it off by seting the ShowCurrentPageHighlight property to false, or change the color using the CurrentPageHighlightColor property.
BackColor - a color that represents the background color of the control.
PageBackColor - a color that represents the background color of the page.
Open file
Print PDF
Select all text
Copy selected text to clipboard
Go to first page
Go to previous page
Current page indicator
Total number of pages in a document
Go to next page
Go to last page
Rotate the current page counterclockwise
Rotate current page clockwise
Оpen a context menu with search parameters
Text input field to search
Go to the previous found record
Go to the next found record
Set the zoom level to the page's actual size
Set the zoom level so one full page fits in the window
Set the zoom level so the page width fits the window width
Set the zoom level so the page height fits the window height
View one page at time
View pages continuously with vertical scrolling enabled
View pages continuously with horizontal scrolling enabled
View pages side-by-side with continuous scrolling enabled
View two pages side-by-side
Decrease magnification
Current magnifiction level / Text field to set magnification level to a specific value
Drop-down list with predefined magnification levels
Increase magnification
Current magnifiction level
Drop-down list with predefined magnification levels
Decrease magnification
Track bar to set magnification level
Increase magnification
One of the possible appearance of the PDF viewer
The sample project for displaying PDF files using the PDF Viewer is available in the Zip/Msi package here.