Windows C# .NET PDF library integration

Welcome to Apryse. .NET for the Apryse SDK is supported on Windows.

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into .NET Framework applications on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • Visual StudioMake sure that the .NET Desktop Development and .NET Framework 4.5.1+ development tools workload is part of your installation.This guide will use Visual Studio 2017.
  • Apryse's C# .NET PDF Library for Windows:

Download the SDK

Download

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Extract the folder from the .zip file.

This article uses PDFNET_BASE as the path into the folder that you extracted.

sh

1PDFNET_BASE = path/to/extraction/folder/PDFNetDotNet4/
  1. 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 the samples

Navigate to the location of extracted contents. Find and enter the Samples folder (PDFNET_BASE/Samples). Here you can find sample code for a large number of features supported by the Apryse SDK.

  1. Open Samples_20XX.sln in Visual Studio. Choose an appropriate version for your Visual Studio installation.
  2. Find the sample you want to run and set it as the Startup Project for the solution.
  3. Run the project.

Integrate into your application

This is called the "Apryse Hello World" application. It is easy to integrate the rest of Apryse SDK if you are able to open, save and close a PDFDoc.

  1. Create a new .NET Framework console application project in Visual Studio for your preferred language. You can find them under the Visual C# or Visual Basic category.
  2. Navigate into your project's folder. By default, the path should be similar to: C:/Users/User_Name/source/repos/myAppCopy the Lib folder from PDFNET_BASE to your project folder (the folder which contains your .csproj or .vbproj file).
  3. Find the Solution Explorer to the right. Right-click on References and select the Add reference option. This opens a Reference Manager dialog.Click on Browse... at the bottom of the dialog. Navigate to the copied Lib folder and add PDFNetLoader.dll to the references.Also add the appropriate version of PDFNet.dll from the x86 folder as another reference (path/to/your/project/folder/Lib/PDFNet/x86/PDFNet.dll). This version will allow the application to run on both 32-bit and 64-bit OS.
  4. Select PDFNet.dll and set its Copy Local property to False.
Apryse Docs Image
  1. Open App.config in the solution explorer and make sure the loadFromRemoteSources property is set to true:

sh

1<configuration>
2 <runtime>
3 <loadFromRemoteSources enabled="true" />
4 </runtime>
5</configuration>
  1. Right click on your project and select Properties. In the left pane, select the Build Events tab. Under Post-Build Events, add the following code snippet:

sh

1xcopy $(ProjectDir)Lib\PDFNet $(TargetDir)PDFNet /S /I /Y

The Code

Replace the contents of Program.cs or Module1.vb with:

VB

1'Default namespace
2Imports System
3
4'Majority of Apryse SDK can be used with these namespaces
5Imports pdftron
6Imports pdftron.Common
7Imports pdftron.SDF
8Imports pdftron.PDF
9
10Module Module1
11
12 'Required for AnyCPU implementation.
13 Dim pdfNetLoader As PDFNetLoader
14 Sub New()
15 pdfNetLoader = pdftron.PDFNetLoader.Instance()
16 End Sub
17
18 Sub Main()
19 ' Initialize PDFNet before using any Apryse related
20 ' classes and methods (some exceptions can be found in API)
21 PDFNet.Initialize("YOUR_APRYSE_LICENSE_KEY")
22
23 ' Using PDFNet related classes and methods,
24 ' must catch or throw PDFNetException
25 Try
26
27 Using doc As PDFDoc = New PDFDoc
28
29 ' An example of creating a new page and adding it to
30 ' doc's sequence of pages
31 Dim newPg As Page = doc.PageCreate()
32 doc.PagePushBack(newPg)
33
34 ' Save as a linearized file which is most popular
35 ' and effective format for quick PDF Viewing.
36 doc.Save("linearized_output.pdf", SDFDoc.SaveOptions.e_linearized)
37 Console.WriteLine("Done. Results saved in linearized_output.pdf")
38 End Using
39
40 Catch e As PDFNetException
41 Console.WriteLine(e)
42 End Try
43 End Sub
44
45End Module

Build and run the project using the Start button in Visual Studio.

You should find the "linearized_output.pdf" in your project folder with a blank page.

Next step

Troubleshooting

PDFNetLoader

The steps above allow you to create an application that can support both 32bit or 64bit processes at runtime. However, this is often not needed in practice.

If you know you are targeting only 64bit, or 32bit, then reference the corresponding 32bit or 64bit PDFNet.dll assembly in your solution (make sure copylocal:true is set), and remove both PDFNetLoader.dll and the one line of code for PDFNetLoader.

If on the other hand you are writing a client application, where you need to support both 64bit and 32bit, then simply using your installer to install the correct 32bit or 64bit PDFNet.dll, and omit PDFNetLoader.dll, is typically the best way to proceed.

In summary, PDFNetLoader.dll is not required, and is just used for AnyCPU 32bit/64bit handling. To know more about PDFNetLoader see [this post])https://www.pdftron.com/blog/dotnet/dotnet-pdf-control-nuget).

Find out how to set a startup project

Setting a startup project

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales