Some test text!

menu
search
Step by stepkeyboard_arrow_down

Get started with .NET Core

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

Get started with .NET Core

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

linkPrerequisites

  • 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: Target Framework for PDFTron SDK is >= netappcore 2.1

  • PDFTron SDK for Windows
    64-bit Download
    32-bit Download

linkInitial setup

Extract the folder from the .zip file.

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

PDFNET_BASE = path/to/extraction/folder/PDFNetC(64)/

linkRun 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

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.

linkIntegrate 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 for Windows (x64)

  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

linkThe 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

linkNext step

GuidesAPI docsSamples

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close