Get started with .NET
This guide walks you through the steps to use a code example, and then explains how to integrate the Toolbox add-on into your application with .NET.
Prerequisites
The Toolbox add-on 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 Toolbox add-on using a C# code example. The ImageExtraction example extracts all images and image masks from a PDF document. Use similar steps to run any other code example from the toolbox-examples-csharp repository.
Compile and run the sample
- Visual Studio
- Command line
This sample describes the process using Visual Studio 2022.
-
Clone the toolbox-examples-csharp repository:
git clone https://github.com/pdf-tools/toolbox-examples-csharp.git -
Open the project in Visual Studio:
toolbox-examples-csharp/ImageExtraction/ToolboxImageExtraction.csproj -
In the
Program.csfile, replace the string"YOUR_LICENSE_KEY"with your license key:
Sdk.Initialize("YOUR_LICENSE_KEY", null);
-
Click Build -> Build Solution to compile the project.
-
Run the compiled sample application. Provide
inputPathfor the input PDF file andoutputDirpath for the output directory where the image files will be stored:ToolboxImageExtraction <inputPath> <outputDir>For example, to extract all images and image masks from the sample PDF file
ImageCollection.pdfto the output directory/tmp/images, run:ToolboxImageExtraction ImageCollection.pdf /tmp/images
-
Clone the toolbox-examples-csharp repository:
git clone https://github.com/pdf-tools/toolbox-examples-csharp.git -
In the
Program.csfile, replace the string"YOUR_LICENSE_KEY"with your license key:
// Set and check license key. If the license key is not valid, an exception is thrown.
Sdk.Initialize("YOUR_LICENSE_KEY", null);
-
In the example folder, run the following command providing
inputPathfor the input PDF file andoutputDirpath for the output directory where the image files will be stored:dotnet run --framework net6.0 --project ToolboxImageExtraction.csproj <inputPath> <outputDir>For example, to extract all images and image masks from the sample PDF file
ImageCollection.pdfto the output directory/tmp/images, run:dotnet run --framework net6.0 --project ToolboxImageExtraction.csproj ImageCollection.pdf /tmp/images
You can apply a similar procedure as described in this tutorial for other code examples. For more information, see Code samples page.
Integrate the Toolbox add-on into your application
Integrate and initialize the Toolbox add-on into your application by following the instructions in the next sections.
Add the Toolbox add-on to your project
- Visual Studio
- Command line
The integration section describes the process using 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.Toolbox. - Select the NuGet package named
PdfTools.Toolbox 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.
In the project directory, run the following command:
dotnet add package PdfTools.Toolbox
Optional: If you want to use a specific version of the Toolbox add-on, run the following command:
dotnet add package PdfTools.Toolbox --version <VERSION>
Initialize the SDK
After installing the Nuget package the final step before using the SDK is to initialize the SDK with your license key. Replace YOUR_LICENSE_KEY in the following method with the value of your license key:
PdfTools.Toolbox.Sdk.Initialize("YOUR_LICENSE_KEY", null);
Without a valid license key the Toolbox add-on returns an error. Contact the Pdftools sales team through the Contact page to get a full license.
Implement your use case
- Find more use cases and code examples on the Toolbox add-on Code samples page.
- For more technical information about the Toolbox add-on for .NET, consult the .NET technical notes.