Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

How To Create A PDF Viewer in PDFOne .NET v2.x

Create a PDF viewer application in 5 minutes flat.
By V. Subhash

This is an updated version of an older article. That article was written for PDFOne .NET v2.0 Preview, where the viewer was part of Gnostice.PDFOne assembly.

When version 2.0 was finally released, the PDF viewer component was provided in a separate assembly named Gnostice.PDFOne.Windows.PDFViewer. Hence, a newer version of the article was due. PDFViewer is a .NET PDF viewer component that you can use to display PDF documents to end-users in Win-forms applications.

All right and here we go. Let us build a Winforms PDF viewer application.

  1. Start Visual Studio. (I have used VS 2005 for this article.)
  2. Create a new Windows application in C# or Visual Basic.
  3. Add a toolstrip component from the Toolbox to the form. (In C#, this will named as toolStrip1. In VB.NET, it will be ToolStrip1.) Ensure that the strip is right below the title bar and its Dock property is set to Top.
  4. Add a PDFViewer component to the form. (It is a good idea to create a tab in the IDE's Toolbox for PDFOne .NET components. The help file has a "Getting Started" topic that shows how to do this.) In C#, the instance will be named pdfViewer1. In VB.NET, it will be named PdfViewer1.
  5. Ensure that the viewer is below the tool strip and viewer's Dock property is set to Fill.
  6. Add the following components using the toolstrip's design-time split button menu options.
    1. label - 1 no.
    2. text box - 1 no.
    3. buttons - 5 nos.
  7. Set the text property of the label to "File:".
  8. Set the name property of the text box to tb_Filename. Resize it so that it looks like the address bar of a browser.
  9. Rename the buttons to btn_Open, btn_FirstPage, btn_PreviousPage, btn_NextPage, and btn_LastPage. Also, set their DisplayStyle to Text and Text properties to "First Page", "Previous Page", Next Page", and "Last Page".
  10. Double-click on the btn_Open and add the following code for its click event.
    In C#
    tb_Filename.Text = tb_Filename.Text.Trim();
    if (tb_Filename.Text == "")
    // Close any previously loaded document
    if (pdfViewer1.PDFLoaded)
    // Load PDF document
    catch (Exception ex1)
         "Sorry. There has been an error. Error Information: "
         + ex1.Message);
    // Update form title bar
    this.Text = "PDFOne .NET Viewer - " + tb_Filename.Text;
    In VB
    tb_Filename.Text = Trim(tb_Filename.Text)
    If Trim(tb_Filename.Text) = "" Then
        Exit Sub
    End If
    ' Close any previously loaded document
    If PdfViewer1.PDFLoaded Then
    End If
    ' Load PDF document
    Catch Ex1 As Exception
        MessageBox.Show( _
                "Sorry. There has been an error. Error Information: " _
                & Ex1.Message)
        Exit Sub
    End Try
    ' Update form title bar
    Me.Text = "PDFOne .NET Viewer Component Demo - " & tb_Filename.Text
  11. For click-events of the other buttons, add the following code.
    In C#
    private void btn_PreviousPage_Click(object sender, EventArgs e)
    private void btn_FirstPage_Click(object sender, EventArgs e)
    private void btn_NextPage_Click(object sender, EventArgs e)
    private void btn_LastPage_Click(object sender, EventArgs e)
    In VB
    Private Sub btn_FirstPage_Click(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) _
                Handles btn_FirstPage.Click
    End Sub
    Private Sub btn_PreviousPage_Click(ByVal sender As System.Object, _
                                       ByVal e As System.EventArgs) _
                Handles btn_PreviousPage.Click
    End Sub
    Private Sub btn_NextPage_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                Handles btn_NextPage.Click
    End Sub
    Private Sub btn_LastPage_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                Handles btn_LastPage.Click
    End Sub
  12. Compile and run the application. Enter the path of a PDF document in the text box and click on Open button.


Our Free Online Document-Processing Tools
Gnostice Apps

Gnostice Apps provides several PDF document-processing services over the Web. It enables you to merge, split, convert, secure and redact PDF documents - all for FREE. All you need to access these services is a HTML5-capable browser such as the latest version of Firefox/Seamonkey or IE 11.

Our Developer Tools
eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers

PDFOne (for Java™)

A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications.

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

Privacy | Legal | Feedback | Newsletter | Resellers © 2002-2014 Gnostice Information Technologies Private Limited. All rights reserved.

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).