How to Convert TIFF to PDF with Python
Convert TIFF Images into Standardized PDF Documents
TIFF is widely used for scanned records, archival images, and high-resolution document capture, but it is not always the most convenient format for distribution or downstream document processing. Converting a .tif or .tiff file to PDF gives applications a consistent document format that is broadly supported by browsers, business systems, and PDF workflows.
The pdfRest Convert to PDF API Tool accepts TIFF images through the same /pdf endpoint used for other supported image, Office, email, PostScript, HTML, and structured-text formats. That consistent request pattern helps simplify systems that receive mixed file types: the application can standardize them as PDF without maintaining a separate conversion library for each source format. pdfRest uses Adobe PDF Library technology to produce reliable output that conforms to the PDF ISO 32000 specification.
For example, an insurance intake system may receive scanned claim documents as TIFF files from several offices. Converting each upload to PDF gives adjusters a consistent format to review and lets the application pass the result directly into OCR, text extraction, merging, or archival steps without requiring staff to convert files manually.
This Python example sends a TIFF file as multipart form data, assigns a predictable output name, and prints the JSON response.
Python TIFF-to-PDF Code Example
Install the requests and requests-toolbelt packages, then replace the file path and API-key placeholders. Use the .tif or .tiff extension in the submitted filename and identify the upload with the image/tiff MIME type.
from requests_toolbelt import MultipartEncoder
import requests
import json
# By default, we use the US-based API service. This is the primary endpoint for global use.
api_url = "https://api.pdfrest.com"
# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
#api_url = "https://eu-api.pdfrest.com"
pdf_endpoint_url = api_url+'/pdf'
# The /pdf endpoint can take a single file, id, or url as input.
# This sample passes a tif file to the endpoint, but there's a variety of input file types that are accepted by this endpoint.
# The 'image/tiff' string below is known as a MIME type, which is a label used to identify the type of a file so that it is handled properly by software.
# Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for more information about MIME types.
mp_encoder_pdf = MultipartEncoder(
fields={
'file': ('file_name.tif', open('/path/to/file', 'rb'), 'image/tiff'),
'output' : 'example_pdf_out',
}
)
# Let's set the headers that the pdf endpoint expects.
# Since MultipartEncoder is used, the 'Content-Type' header gets set to 'multipart/form-data' via the content_type attribute below.
headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_pdf.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
}
print("Sending POST request to pdf endpoint...")
response = requests.post(pdf_endpoint_url, data=mp_encoder_pdf, headers=headers)
print("Response status code: " + str(response.status_code))
if response.ok:
response_json = response.json()
print(json.dumps(response_json, indent = 2))
else:
print(response.text)
# If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.py' sample.
Source: pdfRest Convert to PDF multipart Python sample
If the TIFF already exists on the pdfRest processing service, use its resource ID in a JSON payload instead of uploading the file again. See the Convert to PDF JSON-payload sample.
Build the Multipart Conversion Request
MultipartEncoder combines the source file and conversion parameters into one multipart body. The file field contains the open binary stream, submitted filename, and MIME type. The optional output field sets the resulting PDF's base filename; the API adds the .pdf extension.
The encoder also generates the multipart boundary required by the Content-Type header. Reuse mp_encoder_pdf.content_type rather than writing a multipart header manually, because an incorrect or missing boundary prevents the server from parsing the upload. The Accept: application/json header requests a JSON response, and the Api-Key header authenticates the request.
The sample defaults to the US Cloud API. Applications that require EU-based processing can select the EU base URL shown in the code. Keep the base URL in configuration so deployment environments can choose the appropriate service without modifying request logic.
Handle the Conversion Response
A successful request returns JSON containing information about the generated PDF, including values that can be used to download the result or pass it into another pdfRest API Tool. Check response.ok before parsing the success schema, and validate that the expected output is present before continuing. For production code, add an application-appropriate timeout and catch network exceptions so a temporary connection problem is not mistaken for a conversion failure.
When another pdfRest operation should follow, pass the returned resource ID to the next API call instead of downloading and uploading the intermediate PDF. This supports efficient workflows such as converting a TIFF, applying OCR to make scanned text searchable, extracting text, merging the result with another document, or preparing it for delivery.
Validate TIFF Inputs and PDF Results
Test representative TIFF files, including the image dimensions, color modes, compression types, and page structures the application actually receives. After conversion, verify that the PDF opens correctly, contains the expected pages, and preserves the necessary image detail. Also confirm that the application handles unsupported, damaged, password-protected, or unexpectedly large inputs according to its own requirements.
Do not add compression, downsample, page-size, margin, or orientation fields to this TIFF request based on examples for other formats. Those Convert to PDF controls apply to specific document, PostScript, HTML, or structured-text inputs and do not apply to image-only conversion. Keeping the request limited to supported TIFF parameters makes the integration easier to understand and maintain.
Store the API key in an environment variable or secret manager rather than source control. You can test a TIFF conversion and inspect the generated request in API Lab, then review the current input and response schema in the Convert to PDF API reference.