Get started with C
This guide walks you through the steps to use a sample project, and then explains how to integrate the Pdftools SDK into your application with the C programming language.
Getting started with a sample project
Learn how to use the Pdftools SDK using a C sample project and convert a PDF file to an image.
Prerequisites
This sample project uses GCC toolset 4.8+ and CMake version 3.16 or higher.
Compile and run the sample
-
Download a sample project, and then unzip the file.
-
Navigate to the root directory of the unzipped sample project, and then run:
cmake .
-
Build the sample:
cmake --build .
-
Run the compiled sample application. Provide
inputPath
for the input PDF file andoutputPath
path for the output image file:./pdftoolspdf2imgsimple <inputPath> <outputPath>
For example, to render the sample PDF file
PdfPrimerWhitePaper.pdf
to a multi-page TIFF image format, run:./pdftoolspdf2imgsimple PdfPrimerWhitePaper.pdf PdfPrimerWhitePaper.tiff
You can apply a similar procedure as described in this tutorial for other code samples. 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 next sections.
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 ~
Containts important information in the README.md
file.lib
Runtime executable binaries and runtime import libraries:
win-x86\PdfToolsSdk.dll
andwin-x86\PdfToolsSdk.lib
for 32-bit Windows
win-x64\PdfToolsSdk.dll
andwin-x64\PdfToolsSdk.lib
for 64-bit Windowsinclude
Header files to include in your C or C++ project. The main header PdfTools.h
includes all the other headers./opt/pdftools.com/
Included subdirectories are:
Subdirectory Description ~
Contains important information in the README.md
file.lib
Runtime executable binaries for all supported platforms: linux-x64/libPdfToolsSdk.so
for 64-bit Linuxinclude
Header files to include in your C or C++ project. The main header PdfTools.h
includes all the other headers./opt/pdftools.com/
Included subdirectories are:
Subdirectory Description ~
Contains important information in the README.md
file.lib
Runtime executable binaries:
osx-x64/libPdfToolsSdk.dylib
for 64-bit (Intel) macOS
osx-arm64/libPdfToolsSdk.dylib
for ARM (Apple Silicon) macOSinclude
Header files to include in your C or C++ project. The main header PdfTools.h includes 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
orlib\win-x86
subdirectory 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/lib
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
Initialize the SDK
Initialize the Pdftools SDK with your license key. Replace the <PDFSDK,V1,include-your-key-here>
in the following function with the value of your license key:
// Initialize library
PdfTools_Initialize();
// Optional: Without a license key the Pdftools SDK returns watermarked results.
// Initialize the Pdftools SDK with a license key to remove the watermark.
// The Pdftools SDK returns an error if you use an invalid license key.
GOTO_CLEANUP_IF_FALSE_PRINT_ERROR(PdfTools_Sdk_Initialize(_T("$<PDFSDK,V1,include-your-key-here>$"), NULL), _T("Failed to set the license key. %s (ErrorCode: 0x%08x).\n"), szErrorBuff, PdfTools_GetLastError());
Without a valid license key the output files are watermarked. Get in touch with the Pdftools sales team through the Contact page to get a full license.
Uninitialize the SDK
After processing files with the Pdftools SDK, call the Uninitialize
function to unload the library correctly:
// Uninitialize library
PdfTools_Uninitialize();
Implement your use case
- Find more use cases and sample projects at the Code samples page.
- For more technical information about the Pdftools SDK for C, consult the C technical notes.