Skip to main content
Version: Version 1.16

Get started with Python

This guide walks you through the steps to use the Pdftools SDK in a code example with Python. The Python interface wraps the Pdftools SDK C API.

tip

Try the Pdftools SDK without a license key.

Prerequisites

The Pdftools SDK for Python requires Python 3.6 or higher.

Get started with a sample project

Learn how to use the Pdftools SDK using a Python 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-python repository.

Clone and run the sample

  1. Clone the sdk-examples-python repository:

    git clone https://github.com/pdf-tools/sdk-examples-python.git
  2. Navigate to the Pdf2ImgSimple code example:

    cd sdk-examples-python/Pdf2ImgSimple
  3. Install the Pdftools SDK package:

    pip install pdftools_sdk
  4. To render the sample PDF file PdfPrimerWhitePaper.pdf to a multi-page TIFF image format, run:

    python ./pdf2_img_simple.py PdfPrimerWhitePaper.pdf PdfPrimerWhitePaper.tiff
note

Run python3 instead on systems where only Python 3 is installed and python is not aliased.

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:

python ./pdf2_img_simple.py INPUT_PDF IMAGE_OUTPUT_PATH

The sample runs without a license key, and the output carries a watermark. To remove the watermark, open pdf2_img_simple.py and uncomment the Sdk.initialize method call in the if __name__ == "__main__": block. Replace the "insert-license-key-here" placeholder with your license key. Include the less-than (<) and greater-than (>) signs.

Integrate the SDK into your application

Integrate and initialize the Pdftools SDK into your application.

Add the SDK to your project

  1. Install the Python package:

    pip install pdftools_sdk
  2. Clone the sdk-examples-python repository and navigate to any sample directory.

  3. Review the README.md file with usage details. Every code example includes a README.md with different usage instructions.

  4. Import the required packages in the header of your Python code:

    from ctypes import *
    from pdftools_sdk.pdf import Document
    from pdftools_sdk.pdf2_image import Converter
    from pdftools_sdk.pdf2_image.profiles import Archive
Imports depend on the sample you use

The imports depend on the Python sample you use. Imports displayed in the last step of the previous procedure are valid for the Convert PDF to image sample. Every sample includes a single Python file from which you can copy the imports. To use a different feature, copy the correct imports into your project:

  1. In the sdk-examples-python repository, navigate to a sample directory. For example: sdk-examples-python/Decrypt.
  2. Open the decrypt.py file, and then copy its imports to the header of your Python code.

Optional: Initialize the SDK

Learn how to remove watermarked output of the Pdftools SDK using a valid license key.

tip

Initialization removes watermarks from output files and readies the SDK for production. Without a license key, output files carry a watermark.

Getting a license key

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:

  1. Find your license key. For more information, review Find the license key.

  2. Call Sdk.initialize once at application startup, before any other Pdftools SDK method call:

    Sdk.initialize("YOUR_LICENSE_KEY")

    Replace YOUR_LICENSE_KEY with 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 Sdk.initialize method, follow these steps:

  1. Clone the sdk-examples-python repository and navigate to a sample directory. For example, sdk-examples-python/Pdf2ImgSimple.
  2. Open the main Python file and find the commented-out Sdk.initialize call. For example, the Pdf2ImgSimple Python sample includes it in pdf2_img_simple.py.
  3. Uncomment the call and replace the "insert-license-key-here" placeholder with your license key.

Implement your use case

  • Find more use cases and code examples on the Code samples page.
  • If you need to configure a proxy, review Configure proxy documentation section.