Some test text!

Loading...
Guides

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.

macOS .NET Core PDF library integration

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

Prerequisites

  • .NET Core SDK
    • 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 macOS:

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. Download the PDFTron SDK.
  2. Extract the downloaded zip file and navigate to it.
  3. Get your PDFTron trial key.
Loading...

Run 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 confirm there is a file named runall_dotnetcore.sh. Give yourself execute permissions for this script by executing
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

Integrate into your application

This section will show you how to use our SDK to create a simple PDFTron "Hello World!" application using command line. It will create a document with one blank page and save it as a linearized PDF in its running directory. If you use Visual Studio for Mac, you can follow the instructions here instead. Otherwise, you can use the following steps from the terminal.

  1. Create a new project called myApp from the terminal:
dotnet new console -o myApp

This guide will assume your project is named myApp.

Integrate Manually

Integrate with NuGet for macOS

2. From the PDFTron SDK, copy the `/Lib/libPDFNetC.dylib`, /Lib/libPDFNetC.dylib.*x.x.x*(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 `` element:
```xml

<ItemGroup>
  <Content Include="libPDFNetC.dylib">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemGroup>

<ItemGroup>
  <Reference Include="PDFNetDotNetCore">
    <HintPath>PDFNetDotNetCore.dll</HintPath>
  </Reference>
</ItemGroup>
```

Your final `myApp.csproj` should look something like this:

```xml

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="libPDFNetC.dylib">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Reference Include="PDFNetDotNetCore">
      <HintPath>PDFNetDotNetCore.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>
```

Next, you can edit Program.cs. 4. Open Program.cs in your favorite text editor and add the necessary headers:

```cs

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

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        pdftron.PDFNet.Initialize();
    }
  2. 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
    
              }
          }
        }
    }
  3. 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.

Next step

Guides API docsSamples

Get the answers you need: Support