Get started with Python
This guide walks you through the steps to use the Pdftools SDK in a sample project with Python.
Try the Pdftools SDK without a license key for free.
The Python interface is implemented as a wrapper around the Pdftools SDK's C API.
Prerequisites
The Pdftools SDK for Python requires Python 3.6 or higher.
Getting started with a sample project
Learn how to use the Pdftools SDK using a Python sample project and convert a PDF file to an image.
Download and run the sample
-
Download a sample project, and then unzip the file.
-
Install the Pdftools SDK package by running the following command:
pip install https://pdftools-public-downloads-production.s3.eu-west-1.amazonaws.com/productkits/PDFSDK/latest/pdftools_sdk-latest.tar.gz
-
In the command line, navigate to the root directory of the unzipped sample project, where you can find the
pdf2_img_simple.py
file. -
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
Run python3
instead on systems where only Python 3 is installed and python
is not aliased.
The code sample 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.
Review the following snippet with a placeholder and compare it to the last step of the previous procedure:
python ./pdf2_img_simple.py INPUT_PDF IMAGE_OUTPUT_PATH
Integrate the SDK into your application
Integrate and initialize the Pdftools SDK into your application by following the instructions in the following sections.
Add the SDK to your project
-
Install the Python package:
pip install https://pdftools-public-downloads-production.s3.eu-west-1.amazonaws.com/productkits/PDFSDK/latest/pdftools_sdk-latest.tar.gz
-
From the Pdftools SDK code samples page, download any Python code sample.
-
Unzip a code sample and review the
README.md
file with usage details. Every code sample includes aREADME.md
with different usage instructions. -
Import the following 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
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. In case you want to use another functionality, copy the correct imports into your project with the following steps:
- Open the Pdftools SDK code samples.
- Download a sample. For example: Decrypt an encrypted PDF
- Unzip the downloaded sample.
- 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.
You can try the Pdftools SDK without a license key for free. This section is optional if you want to evaluate this SDK. Initialization only lets you remove watermarks added to output files.
Contact the Pdftools sales team through the Contact page to get a full license. For additional information, review Pdftools SDK license management.
To remove watermarks, follow these steps:
-
Locate your license key. For more information, review Find the license key.
-
Before you call any function of the Pdftools SDK, first call the
Sdk.initialize
method.Sdk.initialize("insert-license-key-here")
Replace the
insert-license-key-here
with the value of your license key. Include the less-than (<
) and greater-than (>
) signs.
To get a code sample with the PdfTools_Sdk_Initialize
function that you can use as a reference for your code, follow these steps:
- On the Code samples page, download and unzip a Python code sample. For example: Download Convert PDF to image sample.
- Unzip the file, and then find the
Sdk.initialize
method in a Python file included with the sample. For example: Convert PDF to image sample includesSDK.initialize
method in thepdf2_img_simple.py
file. - Uncomment the method and replace
insert-license-key-here
with your license key.
Implement your use case
- Find more use cases and sample projects on the Code samples page.