Skip to main content
Version: Version 1.6

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.

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-c repository.

Prerequisites

This code example uses GCC toolset 4.8+ and CMake version 3.16 or higher.

Compile and run the sample

  1. Clone the sdk-examples-c repository:

    git clone https://github.com/pdf-tools/sdk-examples-c.git
  2. Navigate to sdk-examples-c/Pdf2ImgSimple, and then run:

    cmake .
  3. Build the sample:

    cmake --build .
  4. Run the compiled sample application. Provide inputPath for the input PDF file and outputPath 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

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.

note

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 next sections.

Add the SDK to your project

  1. 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.

  2. Unzip the file on your machine into a local directory recommended for your operating system. For example:

    C:\Program Files\PDF Tools AG\

    Included subdirectories are:

    SubdirectoryDescription
    ~Contains important information in the README.md file.
    libRuntime 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
    includeHeader files to add to your C or C++ project. The main header PdfTools.h includes all the other headers.
  3. 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:

    Add the lib\win-x64 or lib\win-x86 subdirectory to the %PATH% environment variable.

Optional: Initialize the SDK

The Pdftools SDK runs without an explicit PdfTools_Sdk_Initialize call by auto-activating an internal test license that watermarks the output. Call PdfTools_Sdk_Initialize with your license key to remove the watermark.

Getting a license key

Contact the Pdftools sales team through the Contact page to get a full license.

Call PdfTools_Sdk_Initialize once 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());

Use the license key in the same format you copied it. Include the less-than (<) and greater-than (>) signs.

For a working reference, see the PdfTools_Sdk_Initialize function in the Pdf2ImgSimple C sample. In SDK samples the call is commented out by default with an "insert-license-key-here" placeholder; uncomment it and replace the 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.