Some test text!

menu
search

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 Linux. Your free trial includes unlimited trial usage and support from solution engineers.

linkPrerequisites

linkInitial setup

  1. Download the PDFTron SDK.
  2. Extract via tar xvzf PDFNetC64.tar.gz or tar xvzf PDFNetC.tar.gz.

linkRun the samples

Run a specific sample

  1. Navigate to the CS folder in the sample you want to run(e.g. /Samples/AddImageTest/CS and execute
dotnet run

Run all samples

  1. Navigate to /Samples and make a new file named runall_dotnetcore.sh. Open up the file and paste the shell script from here into it.
  2. Next give yourself execute permissions by
chmod a+x runall_dotnetcore.sh

then run the script using:

./runall_dotnetcore.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

linkIntegrate into your application

This section will show you how to use our SDK to create a simple PDFTron "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Create a new project called myApp via dotnet new console -o myApp. This guide will assume your project is named myApp.
  2. From the PDFTron SDK, copy the /Lib/libPDFNetC.so, /Lib/libPDFNetC.so.(for example 6.10.2) and /Lib/PDFNetDotNetCore.dll to your myApp folder.
  3. Open myApp.csproj in your favorite text editor and add in your <Project> element:

    <ItemGroup>
      <Content Include="libPDFNetC.so">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
    </ItemGroup>
    
    <ItemGroup>
      <Reference Include="PDFNetDotNetCore">
        <HintPath>PDFNetDotNetCore.dll</HintPath>
      </Reference>
    </ItemGroup>

    Your final myApp.csproj should look something like this:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.2</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <Content Include="libPDFNetC.so">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    
      <ItemGroup>
        <Reference Include="PDFNetDotNetCore">
          <HintPath>PDFNetDotNetCore.dll</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
  4. Open Program.cs in your favorite text editor and add the necessary headers:

    using pdftron.Common;
    using pdftron.PDF;
    using pdftron.SDF;
  5. Initialize PDFNet in your main function:

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        pdftron.PDFNet.Initialize();
    }
  6. Instantiate a new document with one blank page:

    using(PDFDoc doc = new PDFDoc()){
      Page page = doc.PageCreate();  // Start a new page
      doc.PagePushBack(page);  // Add page to document
    }

    Then save the document as a linearized PDF named output.pdf:

    doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);  // Save document as a linearized PDF

    Your final program should look like this:

    using System;
    using pdftron.Common;
    using pdftron.PDF;
    using pdftron.SDF;
    
    namespace myApp
    {
        class Program
        {
          static void Main(string[] args)
          {
              Console.WriteLine("Hello World!");
              pdftron.PDFNet.Initialize(); // PDFNet must be initialized before accessing any PDFTron API
    
              using(PDFDoc doc = new PDFDoc()){
    
                Page page = doc.PageCreate();   // Start a new page
                doc.PagePushBack(page);       // Add page to document
                doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized); // Save document as a linearized PDF
    
              }
          }
        }
    }
  7. Now run the application by executing dotnet run. If all goes well, your console should output:

    PDFNet is running in demo mode.
    Permission: write
    Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

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