Getting started with the Pdftools SDK
This guide walks you through the steps necessary to integrate the Pdftools SDK into your project. By the end, you’ll be able to create a PDF document.
Get in touch with the Pdftools sales team through the Contact page to get a license key.
Steps to use the Pdftools SDK:
- Request a license key.
- Create a new project.
- Add the Pdftools SDK to your project.
Depending on the language, there are two ways you can get the SDK:
- NuGet: For .NET. Download from nuGet.
- Local package: For Java and C. Download from myPdftools portal.
- Set color profiles and install fonts, as appropriate.
- Initialize the library by passing the license key.
- Decide on your goal. Depending on your goal, the tasks to be performed vary:
- Convert: Choose to convert your input file into another output file format:
- Validate a PDF document: Check your PDF document complies with a standard or a custom validation profile.
- Optimize a PDF document: Perform optimization on your PDF document to remove redundant objects, minimize file size, and more.
Request a license key
You can download your license key from your My PDF Tools Portal account or get an evaluation license key.
Install the Pdftools SDK
The Pdftools SDK can be installed in different ways according to the operating system and programming language used:
- .NET
- Java
- C
NuGet package
NuGet is a package manager that facilitates the integration of libraries for the software development in .NET. The NuGet package for the Pdftools SDK contains all the libraries needed, managed and native, for all supported operating systems.
Install the package
Download the NuGet package directly from https://www.nuget.org/. In Microsoft Visual Studio, this is the default location for downloading packages.
The package contains .NET libraries with version .NET Standard 2.0, and native libraries for Windows, macOS, and Linux. The required native libraries are loaded automatically. All project platforms are supported, including AnyCPU.
To use the SDK, download a license key from the Pdftools website and use it as described in Initialize the SDK.
This NuGet package is only supported on a subset of the operating systems supported by .NET Core.
ZIP archive
Unzip the archive to a local directory for your operating system.- Windows
- Linux
- macOS
C:\Program Files\PDF Tools AG\
This creates the following subdirectories:
Subdirectory | Description |
---|---|
lib | Contains the runtime executable binaries: win-x86\PdfToolsSdk.dll for 32-bit Windows win-x64\PdfToolsSdk.dll for 64-bit Windows |
doc | Contains documentation |
jar | Contains Java archive file com.pdftools.jar . |
You may want to add the lib\win-x64
or lib\win-x86
subdirectory to the %PATH%
environment variable.
/opt/pdftools.com/
This creates the following subdirectories:
Subdirectory | Description | |
---|---|---|
lib | Contains the runtime executable binaries: linux-x64/libPdfToolsSdk.so for 64-bit Linux | |
doc | Contains documentation | |
jar | Contains Java archive file com.pdf_tools.fourheights.pdftoolsSdk.jar . |
You may want to create a link to the shared library from one of the standard library directories, e.g:
ln -s /opt/pdf-tools.com/lib/linux-x64/libPdfToolsSdk.so /usr/lib
The Pdftools SDK for Java requires Java version 8 or higher.
For compilation and execution when using the Java interface, the jar\com.pdftools.jar
Java archive needs to be on the CLASSPATH. This can be done by either adding it to the environment variable CLASSPATH
, or by specifying it using the -classpath
or -cp
switch:
javac -cp ".;C:\Program Files\PDF Tools AG\jar\com.pdftools.jar" ^
sampleApplication.java
Additionally, the library needs be in one of the system's library directories2
or added to the Java system property java.library.path
. This can be achieved by either adding this system property dynamically at program startup before using the API, or by specifying it using the -Djava.library.path
switch when starting the Java VM. Choose the correct subdirectory depending on the platform of the Java VM3.
The path separator usually is a colon and hence the above changes to something like:
... -cp ".:/path/to/com.pdftools.jar" ...
/opt/pdftools.com/
This creates the following subdirectories:
Subdirectory | Description |
---|---|
lib | Contains the runtime executable binaries: osx-x64/libPdfToolsSdk.dylib for 64-bit (Intel) macOS osx-arm64/libPdfToolsSdk.dylib for ARM (Apple Silicon) macOS |
doc | Contains documentation |
jar | Contains Java archive file com.pdftools.jar . |
The Pdftools SDK for Java requires Java version 8 or higher.
For compilation and execution when using the Java interface, the jar\com.pdftools.jar
Java archive needs to be on the CLASSPATH. This can be done by either adding it to the environment variable CLASSPATH
, or by specifying it using the -classpath
or -cp
switch:
javac -cp ".;C:\Program Files\PDF Tools AG\jar\com.pdftools.jar" ^
sampleApplication.java
Additionally, the library needs be in one of the system's library directories2
or added to the Java system property java.library.path
. This can be achieved by either adding this system property dynamically at program startup before using the API, or by specifying it using the -Djava.library.path
switch when starting the Java VM. Choose the correct subdirectory depending on the platform of the Java VM3.
The path separator usually is a colon and hence the above changes to something like:
... -cp ".:/path/to/com.pdftools.jar" ...
ZIP archive
Unzip the archive to a local directory for your operating system.- Windows
- Linux
- macOS
If you are using Windows, the local directory may be, for example:
C:\Program Files\PDF Tools AG\
This creates the following subdirectories:
Subdirectory | Description |
---|---|
lib | Contains the runtime executable binaries and runtime import libraries: win-x86\PdfToolsSdk.dll and win-x86\PdfToolsSdk.lib for 32-bit Windows win-x64\PdfToolsSdk.dll and win-x64\PdfToolsSdk.lib for 64-bit Windows |
include | Contains the header files to include in your C/C++ project. The main header PdfTools.h includes all the other headers. |
You may want to add the lib\win-x64
or lib\win-x86
subdirectory to the %PATH%
environment variable.
/opt/pdftools.com/
This creates the following subdirectories:
Subdirectory | Description |
---|---|
lib | Contains the runtime executable binaries for all supported platforms: linux-x64/libPdfToolsSdk.so for 64-bit Linux |
include | Contains the header files to include in your C/C++ project. The main header PdfTools.h includes all the other headers. |
You may want to create a link to the shared library from one of the standard library directories, e.g:
ln -s /opt/pdf-tools.com/lib/linux-x64/libPdfToolsSdk.so /usr/lib
/opt/pdftools.com/
This creates the following subdirectories:
Subdirectory | Description |
---|---|
lib | Contains the runtime executable binaries: osx-x64/libPdfToolsSdk.dylib for 64-bit (Intel) macOS osx-arm64/libPdfToolsSdk.dylib for ARM (Apple Silicon) macOS |
include | Contains the header files to include in your C/C++ project. The main header PdfTools.h includes all the other headers. |
You may want to create a link to the shared library from one of the standard library directories. For example (for an Intel processor Mac):
ln -s /opt/pdf-tools.com/lib/osx-x64/libPdfToolsSdk.dylib /usr/lib
Directory for temporary files
This directory for temporary files is used for data specific to one instance of a program. The data is not shared between different invocations and deleted after termination of the program. The directory is determined as follows. The product checks for the existence of environment variables in the following order and uses the first path found:
- Windows
- Linux
- macOS
- The path specified by the
%TMP%
environment variable. - The path specified by the
%TEMP%
environment variable. - The path specified by the
%USERPROFILE%
environment variable. - The Windows directory.
- The path specified by the
$PDFTMPDIR
environment variable. - The path specified by the
$TMP
environment variable. - The
/tmp
directory.
- The path specified by the
$PDFTMPDIR
environment variable. - The path specified by the
$TMP
environment variable. - The
/tmp
directory.
Cache directory
The cache directory is used for data that is persisted and shared between different invocations of a program. The actual caches are created in subdirectories. The content of this directory can safely be deleted to clean all caches. This directory should be writable by the application, otherwise caches cannot be created or updated and performance degrades significantly.
- Windows
- Linux
- macOS
If the user has a profile:
%LOCAL_APPDATA%\PDF Tools AG\Caches
If the user has no profile:
<TempDirectory>\PDF Tools AG\Caches
If the user has a home directory:
~/.pdf-tools/Caches
If the user has no home directory:
<TempDirectory>/pdf-tools/Caches
where <TempDirectory>
refers to the directory for temporary files.
If the user has a home directory:
~/.pdf-tools/Caches
If the user has no home directory:
<TempDirectory>/pdf-tools/Caches
where <TempDirectory>
refers to the directory for temporary files.
Font directories
For font directories by operating system, see Install fonts.
Set color profiles
If no color profiles are available, default profiles for both RGB and CMYK are generated on the fly by the Pdftools SDK. If no particular color profiles are set, default profiles are used. By default, the SDK uses the color profile "sRGB Color Space Profile.icm" for device RGB colors, and "USWebCoatedSWOP.icc" for device CMYK. It searches for these profiles in the specified directories:
- Windows
- Linux
- macOS
%SystemRoot%\System32\spool\drivers\color
- directory
Icc
, which must be a direct sub-directory of where thePdfToolsSdkAPI.dll
resides.
$PDF_ICC_PATH
if the environment variable is defined- the current working directory
$PDF_ICC_PATH
if the environment variable is defined- the current working directory
Most systems have pre-installed color profiles. For example, on Windows at %SystemRoot%\sys- tem32\spool\drivers\color\
.
You can download color profiles from the links provided in the bin\Icc\
directory or from these websites:
- http://www.pdf-tools.com/public/downloads/resources/colorprofiles.zip
- http://www.color.org/srgbprofiles.html
- https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html
Install fonts
Some Pdftools SDK features require fonts to be installed locally.
If you use these SDK features, then you must have fonts installed:
- PDF to PDF/A conversion
- PDF to image conversion
For example, the PDF/A standard requires all fonts to be embedded in the PDF file. This guarantees that the textual content of a conforming file will match, on a glyph by glyph basis, the appearance of the file originally created. If non-embedded fonts are used in the original PDF when converting to PDF/A, the fonts must be embedded during conversion. To embed fonts, a matching font has to be found in the font directories.
PDF documents may contain both embedded and non-embedded fonts. When rendering non-embedded fonts when converting to image from PDF, the best result can be achieved if the font is available on the system. Therefore, it is important to make sure the font directories contain all fonts required.
Font directories
The location of the font directories depends on the operating system.
Font directories are traversed recursively in the order specified. If two fonts with the same name are found, the latter takes precedence, i.e. user fonts always take precedence over system fonts.
- Windows
- Linux
- macOS
Installing fonts in Windows
When a font is installed, it is installed by default only for a particular user. It is important to either install fonts for all users or make sure the Pdf Tools SDK is run under that user and the user profile is loaded.The font directories for Windows are:
%SystemRoot%\Fonts
- User fonts listed in the registry key
\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts
. This includes user specific fonts fromC:\Users\<user>\AppData\Local\Microsoft\Windows\Fonts
and app specific fonts fromC:\Program Files\WindowsApps
Fonts
directory, which must be a direct subdirectory of wherePdfToolsSdkAPI.dll
resides.
The directories are transversed recursively in this order.
Installing fonts in Linux and Debian systems
In Linux, it is recommended that you install the Liberation fonts, Google Noto CJK fonts, and the OpenSymbol font.
On Debian-based systems, the packages are fontsliberation2
, fontsnotocjk
, and fonts opensymbol
.
Many PDF documents use Microsoft core fonts such as Arial, Times New Roman, and other fonts commonly used on Windows. Therefore, it is recommended that you install these fonts to your default font directories.
Many Linux distributions offer an installable package for Microsoft TrueType core fonts. For instance, on Debian-based systems, the package is ttfmscorefontsinstalller
. Alternatively, you can download the fonts from http://corefonts.sourceforge.net/
For more information on Microsoft core fonts and licensing, see Font redistribution FAQ for Windows.
/usr/share/fonts
/usr/local/share/fonts
~/.fonts
$PDFFONTDIRor/usr/lib/X11/fonts/Type1
The directories are transversed recursively in this order.
Installing fonts in macOS
In macOS, it is recommended that you install the Liberation fonts, Google Noto CJK fonts, and the OpenSymbol font.
Many PDF documents use Microsoft core fonts such as Arial, Times New Roman, and other fonts commonly used on Windows. Therefore, it is recommended that you install these fonts to your default font directories.
Many Linux distributions offer an installable package for Microsoft TrueType core fonts. For instance, on Debian-based systems, the package is ttfmscorefontsinstalller
. Alternatively, you can download the fonts from http://corefonts.sourceforge.net/
For more information on Microsoft core fonts and licensing, see Font redistribution FAQ for Windows.
/System/Library/Fonts
/Library/Fonts
The directories are transversed recursively in this order.
Font cache
A cache of all fonts in all font directories is created. If fonts are added or removed from the font directories, the cache is updated automatically.
To achieve optimal performance, make sure that the cache directory is writable for the Pdftools SDK. Otherwise, the font cache cannot be updated and the font directories have to be scanned on each program startup.
The font cache is created in the subdirectory <CacheDirectory>/Installed Fonts
of the cache directory.
Initialize the SDK
You initialize the library with the initialize
method of the sdk
class, passing the license key as a string.
Sign up for a trial license to get a license key.
- .NET
- Java
- C
namespace PdfToolsValidateSimple
{
class Program
{
/***$Usage$***/
static void Main(string[] args)
{
/***$CheckArguments$***/
try
{
// Set and check license key. If the license key is not valid, an exception is thrown.
Sdk.Initialize("$LicenseKey$");
public static void main(String[] args)
{
/***$CheckArguments$***/
try
{
/***$LoadLibrary$***/
// Set and check license key. If the license key is not valid, an exception is thrown.
Sdk.initialize("$LicenseKey$");
// Initialize library
PdfTools_Initialize();
// Set the license key. If it is not valid, an error is returned.
GOTO_CLEANUP_IF_FALSE_PRINT_ERROR(PdfTools_Sdk_Initialize(_T("$LicenseKey$"), NULL), _T("Failed to set the license key. %s (ErrorCode: 0x%08x).\n"), szErrorBuff, PdfTools_GetLastError());
If the license key is missing, an exception is thrown. If a license key is provided but is incorrect as either the format is incorrect or it is not a valid key, a corrupt file or license exception is thrown, respectively.