Image to PDF in Python

This page describes how to use our cloud-based API to convert images to PDF in Python. The API is user-friendly and can be integrated into your application with just a few lines of code.

Sample Output

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.

API Method Reference

Refer to the Image 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.ImageToPdfClient('your_username', 'your_apikey')

    # run the conversion and write the result to a file
    client.convertFileToFile('/path/to/logo.png', 'logo.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.ImageToPdfClient('your_username', 'your_apikey')

    # run the conversion and write the result to a file
    client.convertUrlToFile('https://pdfcrowd.com/static/images/logo.png', 'logo.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.ImageToPdfClient('your_username', 'your_apikey')

    # run the conversion and write the result to a file
    client.convertRawDataToFile(open('/path/to/logo.png', 'rb').read(), 'logo.pdf')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # rethrow or handle the exception
    raise

Troubleshooting