PDF to PDF in Python

This page describes how to join multiple PDF files or update PDF attributes in Python using the cloud-based Pdfcrowd API. The API is easy to use and it takes only a few of lines of code to integrate it to your application.

Installation

The Python API client library provides easy access to the Pdfcrowd API. No third-party libraries are required.

Install the client library from PyPI
pip install pdfcrowd

We also offer other installation options.

Authentication

The credentials to access the API are your Pdfcrowd username and the API key. You can try out the API without registering using the following demo credentials:

  • Username: demo
  • API key: ce544b6ea52a5621fb9d55f8b542d14d

To get your personal API credentials, you can start a free API trial or buy the API license.

API Method Reference

Refer to the PDF to PDF Python Reference for a description of all API methods.

Code Examples

Here are a few Python examples to get you started quickly with the API. See more examples.

import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.PdfToPdfClient('demo', 'ce544b6ea52a5621fb9d55f8b542d14d')

    # configure the conversion
    client.addPdfFile('/path/to/cover.pdf')
    client.addPdfFile('/path/to/proposal.pdf')
    client.addPdfFile('/path/to/price.pdf')
    client.addPdfFile('/path/to/contact.pdf')

    # run the conversion and write the result to a file
    client.convertToFile('offer.pdf')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # rethrow or handle the exception
    raise
import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.PdfToPdfClient('demo', 'ce544b6ea52a5621fb9d55f8b542d14d')

    # configure the conversion
    client.addPdfRawData(open('/path/to/cover.pdf', 'rb').read())
    client.addPdfRawData(open('/path/to/proposal.pdf', 'rb').read())
    client.addPdfRawData(open('/path/to/price.pdf', 'rb').read())
    client.addPdfRawData(open('/path/to/contact.pdf', 'rb').read())

    # run the conversion and write the result to a file
    client.convertToFile('offer.pdf')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # rethrow or handle the exception
    raise
import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.PdfToPdfClient('demo', 'ce544b6ea52a5621fb9d55f8b542d14d')

    # configure the conversion
    client.addPdfFile('/path/to/proposal.pdf')
    client.setPageWatermark('/path/to/watermark.pdf')

    # run the conversion and write the result to a file
    client.convertToFile('company_offer.pdf')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # rethrow or handle the exception
    raise

Troubleshooting