ComPDF
TutorialsWindows.NETC#

How to Build a Windows PDF Viewer in C#?

By authorSierra Nakamura | Wed. 09 Jul. 2025

Windows is the preferred working environment for both enterprise and individual users. ComPDF offers comprehensive integration for Windows, covering .NET (C#, ASP.NET, ASP.NET Core, and VB.NET), C/C++, Python, and Java.

 

In this article, we will use C# as an example to provide a detailed guide on how to seamlessly integrate the ComPDF for Windows into your Windows application.



Requirement

 

Please ensure that your system meets the following requirements:

 

        - Windows 7,8,10,11 (32-bit, 64-bit).

        - Visual Studio 2017 or higher.

        - .NET Framework 4.5 or higher.

 

 

Create a New Project

 

1. Start Visual Studio 2022, click Create a new project.

 

Create a new Windows project | ComPDF

 

2. Choose WPF APP (.NET Framework) and click Next.

 

Choose WPF APP (.NET Framework) | ComPDF

 

3. Configure your project: Set your project name and choose the location to store your program. After completing the setup, click Create to create the project.


In this example, we have chosen .NET Framework 4.5 as the framework and named the project ComPDF Demo.

 

Configure your project | ComPDF

 

 

Install the Nuget Package

 

1. Right click on the project that you need to add ComPDF for Windows, then click Manager Nuget Packages.

 

Manager Nuget Packages | ComPDF

 

2. On the NuGet Package Manager page, select Browse. Set the Package source to nuget.org. Then, search for "ComPDF.NetFramework".


After selecting "ComPDF.NetFramework" from the search results, in the package description panel, click on the Install button to initiate the package installation.

 

initiate the package installation | ComPDF

 

 

Create a PDF Viewer

 

We have finished all prepare steps. Let's display a PDF file: Replace the content of the "MainWindow.xaml" file in your project with the following code:

 

<Window x:Class="ComPDF_Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ComPDF_Demo"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" UseLayoutRounding="True">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="52"/>
        </Grid.RowDefinitions>
        <Grid Name="PDFGrid" Grid.Row="0" />
        <Button Content="Open PDF" Grid.Row="1" HorizontalAlignment="Left" Margin="10" Click="OpenPDF_Click"/>
    </Grid>
</Window>
 

 

To use ComPDF SDK, you need to input a license key. You can contact the ComPDF team to obtain a license key. 

 

Replace the content of the "MainWindow.xaml.cs" file in your project with the following code. Then, replace the "Input your license key here" string in the code below to complete the creation of the PDF viewer.

 

using ComPDF.NativeMethod;
using ComPDF.PDFDocument;
using ComPDFViewer.PdfViewer;
using Microsoft.Win32;
using System.Windows;

namespace ComPDF_Demo
{
	public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            LicenseVerify();
        }
        
        bool LicenseVerify()
        {
            if (!CPDFSDKVerifier.LoadNativeLibrary())
        		return false;

            // Please input your license in this function.
    		LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("Input your license key here", false);
    		return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
        }

        private void OpenPDF_Click(object sender, RoutedEventArgs e)
        {
            // Get the path of a PDF file.
            var dlg = new OpenFileDialog();
            dlg.Filter = "PDF Files (*.pdf)|*.pdf";
            if (dlg.ShowDialog() == true)
            {
                // Use the PDF file path to open the document in CPDFViewer.
                CPDFViewer pdfViewer = new CPDFViewer();
                pdfViewer.InitDocument(dlg.FileName);
                if (pdfViewer.Document != null &&
                    pdfViewer.Document.ErrorType == CPDFDocumentError.CPDFDocumentErrorSuccess)
                {
                    pdfViewer.Load();
                    PDFGrid.Children.Add(pdfViewer);
                }
            }
        }
    }
}

 

 

Run the Windows PDF Viewer

 

Now run the project, you will see the PDF file that you want to display. The PDF Viewer has been created successfully.

 

ComPDF PDF Viewer for Windows

 

 

Adding Even More Capabilities

 

With broad support for popular programming languages such as C#, ASP.NET, ASP.NET Core, VB.NET, C/C++, Python, and Java, ComPDF offers a versatile and powerful PDF SDK for all your document management needs on Windows platforms.

 

         - Windows PDF Viewer SDK.

         - Annotate and collaborate: Markup, comment, and reply.

         - Create and fill out forms.

         - Edit PDF text, images, and pages.

         - Sign documents with electronic or digital signatures.

         - Redact and remove sensitive and private information.

         - Extensive PDF processing capabilities.

         - Independently developed PDF technologies with a proven track.

         - Keeping technical updates. Ensure that your application remains at the cutting edge of market requirements.

         - Default and customizable UI.

 

ComPDF for Windows: PDF SDK Demo

 

 

Conclusion


In this blog, we showed you how to create a WPF PDF viewer by ComPDF for Windows in C#. ComPDF for Windows is a powerful and user-friendly PDF SDK. If you have any questions about integrating ComPDF for Windows into your project, feel free to contact us and we'll be more than happy to help!