Some test text!

Loading...
Guides
Step by step

Get started with .NET Core

Welcome to PDFTron. .NET Core for the PDFTron SDK is cross-platform and supported on Windows, Linux, macOS. To get started, choose your preferred platform from the tabs below.

.NET Core & Windows PDF library integration

.NET Core

Azure Functions

This guide will help you [run PDFTron samples](#run-the-samples) and [integrate a free trial of the PDFTron SDK into .NET Core applications](#integrate-into-your-application) on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • Visual Studio

    Make sure that the .NET Core cross-platform development workload and MSBUILD are part of your installation.

    This guide will use Visual Studio 2017. If you would like to use the NuGet integration for Windows x64 please make sure you have Visual Studio 2017 or 2019.

    Note: PDFTron SDK is multi-targeting. Target Frameworks : .NET Core 2.1+, .NET Standard 2.1, .NET 5.

  • PDFTron's .NET Core PDF library for Windows:

Run PDFTron SDK in production
A commercial license key is required for use in a production environment. Please fill out our licensing form if you do not have a valid license key.
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.

PDFNET_BASE = path/to/extraction/folder/PDFNetC(64)/
  1. Get your PDFTron trial key.
Loading...

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 PDFTron SDK.

Run a specific sample

  1. Find the sample you want to run and navigate into the CS folder inside.

  2. Open a Command Prompt here and run:

    dotnet run

Alternatively, you can open the project in Visual Studio, Set as Startup Project and run it (F5).

Run all samples

  1. Download the runall_dotnet.bat zip and extract the file into the PDFNET_BASE/Samples folder.

  2. Double click the file in this location to run all the .NET Core samples.

Integrate into your application

This section will help you build the "PDFTron Hello World" application. It is easy to integrate the rest of PDFTron SDK if you are able to open, save and close a PDFDoc.

  1. Open a new instance of Visual Studio 2017 and create a new .NET Core console application project (File > New > Project... ). You can find this under the Visual C# menu.

    Start new project

    Click on OK and allow the IDE to create the project.

  2. Find the Solution Explorer on the right side of the screen. Select the project and press Alt + Enter. This will open the properties tab.

    Alternatively, you can right click on the project and find the properties option.

    Select .NET Core 2.1 (or above) as the target framework for your application.

    Select framework

    If you are using a Windows x64 machine for your .NET Core development, you can use NuGet package manager to get the PDFTron SDK. Otherwise, please integrate the SDK manually.

Integrate Manually

Integrate with NuGet using Visual Studio

  1. Right click on project Dependencies and click on Add Reference. This will open the Reference Manager dialog. Click on the Browse... option at the bottom of the dialog. Navigate to PDFNET_BASE/Lib and select PDFNetDotNetCore.dll and click Add.

    Add .NET Core PDFNet dll

    Click OK on the Reference Manager and continue.

  2. In the Solution Explorer, select the project and press Shift + Alt + A. With this you can Add an Existing Item.

    Alternatively, you can right click on the project and find the Add an existing item... option under the Add submenu.

    Once again, navigate to PDFNET_BASE/Lib. Choose the file type as All Files (*.*) and select PDFNetC.dll. Click on Add.

    Add PDFNetC.dll reference

  3. Select PDFNetC.dll in the solution explorer. A properties window should appear below. In it, change the Build Action setting to Content and the Copy to Output Directory setting to Copy always. To avoid errors, use the drop-down menus available for those fields.

    dll Settings

The Code

Replace the contents of Program.cs with:

using System;

// Most commonly used namespaces for PDFTron SDK.
using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Initialize PDFNet before using any PDFTron related
            // classes and methods (some exceptions can be found in API)
            PDFNet.Initialize();

            // Using PDFNet related classes and methods, must  
            // catch or throw PDFNetException
            try
            {
                using (PDFDoc doc = new PDFDoc())
                {
                    doc.InitSecurityHandler();

                    // An example of creating a new page and adding it to
                    // doc's sequence of pages
                    Page newPg = doc.PageCreate();
                    doc.PagePushBack(newPg);

                    // Save as a linearized file which is most popular  
                    // and effective format for quick PDF Viewing.
                    doc.Save("linearized_output.pdf", SDFDoc.SaveOptions.e_linearized);

                    System.Console.WriteLine("Done. Results saved in linearized_output.pdf");
                }
            }
            catch (PDFNetException e)
            {
                System.Console.WriteLine(e.Message);
            }

            // Makes the program wait to terminate after user input
            Console.ReadKey();
        }
    }
}

Run the program using the Local Windows Debugger. The program will give the following output in the console:

Output

You should see an output file produced at the location of your project. If you used .NET Core 2.1, then by default it will be in the following folder:

C:\Users\User_Name\source\repos\myApp\myApp\bin\Debug\netcoreapp2.1

Next step

Guides API docsSamples

Get the answers you need: Support