Get started with .NET
This guide walks you through the steps to use a code example, and then explains how to integrate the Pdftools SDK into your application with .NET.
Try the Pdftools SDK without a license key.
Prerequisites
The Pdftools SDK for .NET requires .NET and .NET Core 2.0 or higher, or .NET Framework 4.6.1 or higher.
Getting started with a sample project
Learn how to use the Pdftools SDK using a C# code example. The Pdf2ImgSimple example converts a PDF file to an image. Use similar steps to run any other code example from the sdk-examples-csharp repository.
Compile and run the sample
Switch between the following tabs to display steps for the command line interface or for the Visual Studio. To compile and run the sample, follow these steps:
- Command line
- Visual Studio
-
Clone the sdk-examples-csharp repository:
git clone https://github.com/pdf-tools/sdk-examples-csharp.git -
Navigate to the
Pdf2ImgSimplecode example:cd sdk-examples-csharp/Pdf2ImgSimple -
To render the sample PDF file
PdfPrimerWhitePaper.pdfto a multi-page TIFF image format, run the following command:dotnet run --framework net6.0 --project PdfToolsPdf2ImgSimple.csproj PdfPrimerWhitepaper.pdf tiff_output.tiff
The code example takes:
- The input and output files are represented as a file name or a file path with the file name.
- Both file paths (input and output) can be relative or absolute.
Review the following snippet with a placeholder and compare it to the last step of the previous procedure:
dotnet run --framework net6.0 --project PdfToolsPdf2ImgSimple.csproj INPUT_FILE OUTPUT_FILE
This documentation uses Visual Studio 2022.
-
Clone the sdk-examples-csharp repository:
git clone https://github.com/pdf-tools/sdk-examples-csharp.git -
Open the project in Visual Studio:
sdk-examples-csharp/Pdf2ImgSimple/PdfToolsPdf2ImgSimple.csproj -
Click Build -> Build Solution to compile the project.
-
Within the code example, open your terminal.
-
The code example contains a PDF file
PdfPrimerWhitePaper.pdf. To render it in multi-page TIFF image format, run:./bin/Debug/net6.0/PdfToolsPdf2ImgSimple PdfPrimerWhitepaper.pdf tiff_output.tiff
The code example takes:
- The input and output files are represented as a file name or a file path with the file name.
- Both file paths (input and output) can be relative or absolute.
Review the following snippet with a placeholder and compare it to the last step of the previous procedure:
./bin/Debug/net6.0/PdfToolsPdf2ImgSimple INPUT_FILE OUTPUT_FILE
You can apply a similar procedure described in this tutorial for other code examples. For more information, see Code samples page.
Integrate the SDK into your application
Integrate and initialize the Pdftools SDK into your application by following the instructions in the following sections.
Add the SDK to your project
- Command line
- Visual Studio
In the project directory, run the following command:
dotnet add package PdfTools
Optional: If you want to use a specific version of the Pdftools SDK, run the following command:
dotnet add package PdfTools --version VERSION_NUMBER
Replace the VERSION_NUMBER with a specific version of the Pdftools SDK you want to add to your project.
This documentation uses Visual Studio 2022 on Windows.
- Open your solution in Visual Studio.
- Click Tools > Nuget Package Manager > Manage NuGet Packages for Solution….
- Click the Search tab and search for
Pdftools SDK. - Select the NuGet package named
PdfTools by PDF Tools AG, select your Project, and then click Install. - Click OK to allow the changes, and then review and Accept the license agreement.
Optional: Initialize the SDK
Learn how to remove watermarked output of the Pdftools SDK using a valid license key.
Initialization removes watermarks from output files and readies the SDK for production. Without a license key, output files carry a watermark.
Contact the Pdftools sales team through the Contact page to get a full license. For additional information, review Pdftools SDK license management.
To remove watermarks, follow these steps:
-
Find your license key. For more information, review Find the license key.
-
Call
Sdk.Initializeonce at application startup, before any other Pdftools SDK method call:Sdk.Initialize("YOUR_LICENSE_KEY");Use the license key in the same format you copied it. Include the less-than (
<) and greater-than (>) signs.
Without a license key, output files carry a watermark. For more information, review Pdftools SDK license management. Without a valid license key, the output files carry a watermark. Contact the Pdftools sales team through the Contact page to get a full license.
To get a working reference with the Sdk.Initialize method, follow these steps:
- On the Code samples page, clone a sample repository. For example, clone sdk-examples-csharp and navigate to
sdk-examples-csharp/Pdf2ImgSimple. - Find the
Sdk.Initializemethod in the C# file of the sample. For example: Convert PDF to image (C, C#, Java, Python) includes theSdk.Initializemethod in theProgram.csfile. - Uncomment the method and replace the
YOUR_LICENSE_KEYwith your license key.
Implement your use case
- Find more use cases and code examples on the Code samples page.
- For more technical information about the Pdftools SDK for .NET, consult the .NET technical notes.