Click or drag to resize

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.

Assemblies required

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.

Create a simple PDF Viewer application

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.

Drag and drop the PdfViewer from the toolbox

Follow these steps to drag and drop the PdfViewer from the toolbox.

  1. Create a new WinForms application in Visual Studio.

  2. Open the Visual Studio toolbox.

  3. 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.

    Getting Started Win Forms 01
    Note Note
    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.

    C#
    //Loading the document in the PdfViewerControl
    pdfViewer1.LoadDocument("Sample.pdf");
  4. 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.

    Getting Started Win Forms 03
  5. 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.

    Getting Started Win Forms 04
  6. In the same way, add other toolbars and controls.

Adding control manually from code

To add control manually from code, follow these steps,

  1. Add Patagames.Pdf.Net.Controls.WinForms namespace.

    C#
    using Patagames.Pdf.Net.Controls.WinForms;
    using Patagames.Pdf.Net.Controls.WinForms.ToolBars;
  2. Create PdfViewer instance and load the PDF

    C#
    //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.

Appearance and Structure of the Toolbars and Controls

The following screenshots depicts different sections of the PdfViewer control and toolbars.

PdfViewer

Pdf Viewer Legend
  1. The height and width of the control.

  2. Padding within the control.

  3. The PageMargin property specifies space between page and page separator.

  4. Page border. The PageBorderColor property allows you to get or set the color of the page border.

  5. 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.

  6. Current page highlight. You can turn it off by seting the ShowCurrentPageHighlight property to false, or change the color using the CurrentPageHighlightColor property.

  7. BackColor - a color that represents the background color of the control.

  8. PageBackColor - a color that represents the background color of the page.

PdfToolStripMain

Pdf Tool Strip Main Legend
  1. Open file

  2. Print PDF

PdfToolStripClipboard

Pdf Tool Strip Clipboard Legend
  1. Select all text

  2. Copy selected text to clipboard

PdfToolStripPages

Pdf Tool Strip Pages Legend
  1. Go to first page

  2. Go to previous page

  3. Current page indicator

  4. Total number of pages in a document

  5. Go to next page

  6. Go to last page

PdfToolStripRotate

Pdf Tool Strip Rotate Legend
  1. Rotate the current page counterclockwise

  2. Rotate current page clockwise

Pdf Tool Strip Search Legend
  1. –ěpen a context menu with search parameters

  2. Text input field to search

  3. Go to the previous found record

  4. Go to the next found record

PdfToolStripSizes

Pdf Tool Strip Sizes Legend
  1. Set the zoom level to the page's actual size

  2. Set the zoom level so one full page fits in the window

  3. Set the zoom level so the page width fits the window width

  4. Set the zoom level so the page height fits the window height

PdfToolStripViewModes

Pdf Tool Strip View Modes Legend
  1. View one page at time

  2. View pages continuously with vertical scrolling enabled

  3. View pages continuously with horizontal scrolling enabled

  4. View pages side-by-side with continuous scrolling enabled

  5. View two pages side-by-side

PdfToolStripZoom

Pdf Tool Strip Zoom Legend
  1. Decrease magnification

  2. Current magnifiction level / Text field to set magnification level to a specific value

  3. Drop-down list with predefined magnification levels

  4. Increase magnification

PdfToolStripZoomEx

Pdf Tool Strip Zoom Ex Legend
  1. Current magnifiction level

  2. Drop-down list with predefined magnification levels

  3. Decrease magnification

  4. Track bar to set magnification level

  5. Increase magnification

BookmarksViewer

Bookmarks Viewer Legend

Pdf viewer in assembled form

One of the possible appearance of the PDF viewer

Pdf Viewer Complete

The sample project for displaying PDF files using the PDF Viewer is available in the Zip/Msi package here.

See Also