Get started with C
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 the C programming language.
Try the Pdftools SDK without a license key.
Get 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-c repository.
Prerequisites
This code example uses GCC toolset 4.8+ and CMake version 3.16 or higher.
Compile and run the sample
-
Clone the sdk-examples-c repository:
git clone https://github.com/pdf-tools/sdk-examples-c.git -
Navigate to the
Pdf2ImgSimplecode example:cd sdk-examples-c/Pdf2ImgSimple -
Configure the project:
cmake . -
Build the sample:
cmake --build . -
The code example contains a PDF file
PdfPrimerWhitePaper.pdf. To render it in multi-page TIFF image format, run:./pdftoolspdf2imgsimple PdfPrimerWhitePaper.pdf PdfPrimerWhitePaper.tiff
The sample runs without a license key, and the output carries a watermark. To remove the watermark, open pdftoolspdf2imgsimple.c and uncomment the PdfTools_Sdk_Initialize function call in main(). Replace the "insert-license-key-here" placeholder with your license key. Include the less-than (<) and greater-than (>) signs.
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.
Compare the command syntax with a placeholder to the previous procedure:
./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.
Add the SDK to your project
-
Click the download link to get the latest version of the Pdftools SDK for C in a zip archive.
Optional: For older Linux distributions running glibc 2.12+, download the SDK from a separate download.
-
Unzip the file on your machine into a local directory recommended for your operating system. For example:
- Windows
- Linux
- macOS
C:\Program Files\PDF Tools AG\Included subdirectories are:
Subdirectory Description ~Contains important information in the README.mdfile.libRuntime executable binaries and runtime import libraries: win-x86\PdfToolsSdk.dllandwin-x86\PdfToolsSdk.libfor 32-bit Windows.win-x64\PdfToolsSdk.dllandwin-x64\PdfToolsSdk.libfor 64-bit Windows.win-arm64\PdfToolsSdk.dllandwin-arm64\PdfToolsSdk.libfor 64-bit Windows ARM.
includeHeader files to add to your C or C++ project. The main header PdfTools.hincludes all the other headers./opt/pdftools.com/Included subdirectories are:
Subdirectory Description ~Contains important information in the README.mdfile.libRuntime executable binaries for all supported platforms: linux-x64/libPdfToolsSdk.sofor 64-bit Linuxlinux-arm64/libPdfToolsSdk.sofor 64-bit Linux ARM
includeHeader files to add to your C or C++ project. The main header PdfTools.hincludes all the other headers./opt/pdftools.com/Included subdirectories are:
Subdirectory Description ~Contains important information in the README.mdfile.libRuntime executable binaries:
osx-x64/libPdfToolsSdk.dylibfor 64-bit (Intel) macOS
osx-arm64/libPdfToolsSdk.dylibfor ARM (Apple Silicon) macOSincludeHeader files to add to your C or C++ project. The main header PdfTools.hincludes all the other headers. -
Optional: The native libraries must be available in your compiler’s library path. This step is only required if your build process doesn’t resolve it automatically:
- Windows
- Linux
- macOS
Add the
lib\win-x64,lib\win-arm64orlib\win-x86subdirectory to the%PATH%environment variable.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/libCreate 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
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 more information, review the Pdftools SDK license management.
To remove watermarks, follow these steps:
-
Find your license key. For more information, review Find the license key.
-
Call
PdfTools_Sdk_Initializeonce at application startup, before any other Pdftools SDK function call:GOTO_CLEANUP_IF_FALSE_PRINT_ERROR(PdfTools_Sdk_Initialize(_T("YOUR_LICENSE_KEY"), NULL),_T("Failed to set the license key. %s (ErrorCode: 0x%08x).\n"), szErrorBuff,PdfTools_GetLastError());Replace
YOUR_LICENSE_KEYwith your license key. Use the license key in the same format you copied it. Include the less-than (<) and greater-than (>) signs.
To get a working reference with the PdfTools_Sdk_Initialize function, follow these steps:
- Clone the sdk-examples-c repository and navigate to a sample directory. For example,
sdk-examples-c/Pdf2ImgSimple. - Open the main C file and find the commented-out
PdfTools_Sdk_Initializecall. For example, the Pdf2ImgSimple C sample includes it inpdftoolspdf2imgsimple.c. - Uncomment the call and replace the
"insert-license-key-here"placeholder with your license key.
Uninitialize the SDK
After processing files with the Pdftools SDK, call PdfTools_Uninitialize to unload the library correctly:
// Uninitialize library
PdfTools_Uninitialize();
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 C, consult the C technical notes.
- If you need to configure a proxy, review Configure proxy documentation section.