Build a .NET Framework PDF library app with Apryse Server SDK

This guide shows how to build a simple .NET Framework PDF application on Windows that uses the Apryse Server SDK and PDFNet library to generate a PDF programmatically. You’ll set up a minimal project, install the SDK, and add the required code to create a blank PDF document. This example provides a practical foundation for building more advanced document‑generation workflows.

Prerequisites

  • Install Visual Studio to build, test, and deploy applications. This guide uses Visual Studio 2022. The minimum supported version is Visual Studio 2019.
  • Install the .NET desktop development workload and the .NET Framework development tools for your version of .NET Framework. You can install these components through the Visual Studio Installer. For more, see Microsoft's documentation.
  • Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Contact sales to purchase a commercial license key.

Keep your commercial license key confidential

License keys are uniquely generated and strictly confidential. Don't publish or store them in any public location, including public GitHub repositories.

1. Set up your project

In Visual Studio, begin by setting up your project and preparing your workspace for the application.

  1. Open Visual Studio and go to File > New > Project.
  2. Select C# Console App (.NET Framework) or VB Console App (.NET Framework), then click Next.
  3. Add a Project name.
  4. Specify where to save your project using the Location field, then click Next.

Info

Remember the file location for your project. You'll need it later when verifying this workflow.

5. In the Framework dropdown, select the .NET Framework version. For example, .NET Framework 4.8.1.

6. Click Create to launch the new app where you can run and debug your project.

2. Add the Apryse SDK

Next, add the Apryse SDK to your .NET Framework application and configure your project to work with PDF documents. You can install the SDK using the NuGet Package Manager (recommended) or manually download and reference the SDK files.

  1. In Visual Studio, go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  2. From the Browse tab, enter Apryse in the Search field. This shows you the various packages that Apryse has published.
  3. From the search results, select PDFNet. For more package information, see NuGet.
  4. In the Manage Packages for Solution dialog, select the project, then click Install.
Visual Studio Manage NuGet Packages window showing the PDFTron.NetFramework.x64 package with version options and an Install button.

Manage NuGet Packages dialog in Visual Studio with PDFTron.NetFramework.x64 installation options.

5. In the Preview Changes modal, click Apply to install the package in your project.

6. Check the Output window (Package Manager) to confirm the installation completed successfully:

Text

1Adding package 'PDFNet.12.0.0' to folder 'C:\Users\...'
2Added package 'PDFNet.12.0.0' to folder 'C:\Users\...'
3Added package 'PDFNet.12.0.0' to 'packages.config'
4Executing script file 'C:\Users\...'
5Successfully installed 'PDFNet 12.0.0' to apryse-console-app
6Executing nuget actions took 4.25 sec
7Time Elapsed: 00:00:04.7114123
8========== Finished ==========

7. In Solution Explorer, open the source file for your project (Program.cs for C# or Module1.vb for VB). Replace the file contents with the following code, update your license key, and save the file:

Program.cs

1using System;
2// Most commonly used namespaces for Apryse SDK.
3using pdftron;
4using pdftron.Common;
5using pdftron.PDF;
6using pdftron.SDF;
7namespace myApp
8{
9 class Program
10 {
11 // Load appropriate PDFNet libraries at runtime
12 // Automatically load 32-bit or 64-bit binary for app's architecture
13 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
14 static void Main(string[] args)
15 {
16 // Initialize PDFNet before using any Apryse related
17 // classes and methods (some exceptions can be found in API)
18 PDFNet.Initialize("YOUR_LICENSE_KEY");
19 // Using PDFNet related classes and methods, must
20 // catch or throw PDFNetException
21 try
22 {
23 using (PDFDoc doc = new PDFDoc())
24 {
25 doc.InitSecurityHandler();
26 // An example of creating a new page and adding it to
27 // doc's sequence of pages
28 Page newPg = doc.PageCreate();
29 doc.PagePushBack(newPg);
30 // Save as a linearized file which is most popular
31 // and effective format for quick PDF Viewing.
32 doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);
33 System.Console.WriteLine("Done. Results saved in output.pdf");
34 }
35 }
36 catch (PDFNetException e)
37 {
38 System.Console.WriteLine(e.Message);
39 }
40 PDFNet.Terminate();
41 }
42 }
43}

Info

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.

Performance warning

New C# or VB .NET Framework projects often use Any CPU with Prefer 32-bit enabled by default in Visual Studio. On a 64-bit version of Windows, this causes the application to run as a 32-bit process and load the 32-bit Apryse libraries. To run as a 64-bit process, go to Project Properties > Build in Visual Studio and deselect Prefer 32-bit or change the Platform target to x64. This ensures the application can run as a 64-bit process on 64-bit Windows and load the appropriate PDFNet native libraries.

With this code, you can:

  • Import the required Apryse SDK namespaces.
  • Load the appropriate PDFNet native libraries for the application's architecture.
  • Initialize the Apryse SDK with a license key.
  • Create a new PDF document, add a blank page, and save it as a linearized PDF.
  • Handle SDK exceptions and automatically release resources.
  • Terminate the Apryse SDK when processing is complete.

About PDFNetLoader

The NuGet package uses PDFNetLoader to support both 32-bit and 64-bit processes from a single build. It deploys both the x86 and x64 versions of PDFNet.dll and automatically loads the appropriate version at runtime based on the application's architecture.

For most applications, no additional configuration is required. This approach works well with the Any CPU platform target commonly used by .NET Framework projects.

If your application targets a specific architecture, such as x64 or x86, you may be able to deploy only the corresponding version of PDFNet.dll and remove PDFNetLoader. However, this requires additional changes to the project's references and deployment configuration and is not covered in this guide.

In summary, PDFNetLoader is primarily intended for Any CPU applications that need to support both 32-bit and 64-bit processes from the same build.

For more, see our blog post about PDFNetLoader.

3. Verify your output

Finally, build and run your application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally.

  1. In Visual Studio, run the app by selecting the Start button on the toolbar, or by pressing F5. A successful output looks similar to:

Command Prompt

1PDFNet is running in demo mode.
2PackageV2: base
3Done. Results saved in output.pdf

2. Navigate to this directory, where the build output is created by default:

Text

1C:\Users\<your_name>\source\repos\<project_name>\<project_name>\bin\Debug\

3. Verify the blank output.pdf file was generated programmatically using the Apryse Server SDK. The folder structure looks similar to:

Text

1C:\Users\<your_name>\source\repos\
2└── apryse-console-app\
3 ├── apryse-console-app.sln
4 └── apryse-console-app\
5 └── bin\
6 └── Debug\
7 ├── apryse-console-app.exe
8 ├── apryse-console-app.exe.config
9 ├── apryse-console-app.pdb
10 ├── output.pdf
11 ├── PDFNet.dll
12 └── PDFNet.xml

Next steps

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales