Convert PDF documents to HTML with the PDFCrowd Python client. The client handles communication with the API, while conversions run on PDFCrowd's servers.
Install the Python client with pip, or see other installation options.
python -m pip install pdfcrowd
You can run the examples below with the displayed API credentials. Update the input URLs and filenames as needed.
Convert a PDF URL to HTML and save it locally as invoice.html:
import pdfcrowd client = pdfcrowd.PdfToHtmlClient('demo', 'demo') client.convertUrlToFile('https://your-server.com/invoice.pdf', 'invoice.html')
The URL must return a PDF and be reachable from PDFCrowd's servers.
The client raises pdfcrowd.Error on conversion or validation errors.
See Handle Errors.
Convert logo.pdf to HTML and save it locally as logo.html:
import pdfcrowd client = pdfcrowd.PdfToHtmlClient('demo', 'demo') client.convertFileToFile('logo.pdf', 'logo.html')
Pass your PDFCrowd username and API key to
PdfToHtmlClient.
Find your credentials on the API Keys page.
Send a PDF URL, upload a local file, or pass PDF bytes or a readable binary stream.
| Input | Method |
|---|---|
| URL | convertUrlToFile() |
| Local file | convertFileToFile() |
| Bytes in memory | convertRawDataToFile() |
| Readable binary stream | convertStreamToFile() |
Set conversion options on the client before calling a conversion method.
For example, client.setScaleFactor(150) enlarges the HTML page layout by a factor of 1.5.
Common settings are listed below. See the method reference for all available options or browse Python examples.
| Purpose | Methods |
|---|---|
| Pages to convert | setPrintPageRange() |
| Password-protected input | setPdfPassword() |
| Embedded or separate resources | setImageMode(), setCssMode(), setFontMode() |
| Image format and resolution | setImageFormat(), setDpi() |
| Scale and styles | setScaleFactor(), setCustomCss(), setHtmlNamespace() |
| Consistent ZIP output | setForceZip() |
The PDF password unlocks the input document; it is separate from your PDFCrowd API key.
By default, images, CSS and fonts are embedded in a single HTML file. The result preserves the PDF page layout; it does not reconstruct the original source HTML or create a responsive design.
The methods below use URL input; local files, bytes, and input streams have corresponding methods.
| Output | Method |
|---|---|
| Local file | convertUrlToFile() |
| Bytes in memory | convertUrl() |
| Writable binary stream | convertUrlToStream() |
See the reference for file and stream handling.
Convert a PDF to HTML and return the result as bytes:
import pdfcrowd client = pdfcrowd.PdfToHtmlClient('demo', 'demo') data = client.convertUrl('https://your-server.com/invoice.pdf') print(f"Received {len(data)} bytes")
Setting an image, CSS or font mode to "separate" produces a ZIP archive with the HTML and its resources.
Save that result with a .zip extension, then extract it while retaining the relative directory structure.
isZippedOutput() reports whether the selected settings produce a ZIP archive.
When serving the result from a web application, use text/html; charset=utf-8 for HTML or application/zip for an archive.
The client raises a pdfcrowd.Error
exception on conversion or validation errors.
This example converts a PDF to HTML and logs any PDFCrowd error, including its
HTTP status and reason code:
import logging import pdfcrowd client = pdfcrowd.PdfToHtmlClient('demo', 'demo') try: client.convertUrlToFile( 'https://your-server.com/invoice.pdf', 'invoice.html' ) except pdfcrowd.Error as error: logging.error("PDFCrowd: %s", error) logging.error("Status: %s; reason: %s", error.getStatusCode(), error.getReasonCode()) raise
Local Python errors, such as a failure to read an input file or write the output, may need separate handling.
See the error-object reference for status, reason, and message accessors.
str(error) returns the complete error, including available status and reason codes.
| Status | What it means | What to do |
|---|---|---|
400 | Invalid input, settings, or conversion failure | Read the reason code and correct the input or settings. |
401 | Missing credentials or an inactive license | Check your username, API key, and license status. |
403 | Suspended service or no credits remaining | Check your account and available credits. |
413 | Upload exceeds the 300 MB limit | Reduce the upload size. |
429 | Request rate limit reached | Wait and reduce the rate of new requests. |
430 | Concurrent request limit reached | Allow active requests to finish before starting more. |
503 | Temporary network issue | Check your retry policy before submitting another request. |
See all status and reason codes for specific explanations and Limits and Retries for retry behavior.
For job IDs, credit usage, and other conversion details, see the reference.
Request rate and concurrency limits depend on your license. Control how quickly
your application submits conversions and how many it runs at once. A
429 response concerns request rate; a 430 response
concerns requests already in progress. The maximum upload size is 300 MB.
The Python client automatically retries a request once when it receives HTTP
502 or 503. Use
setRetryCount()
to change that count, or set it to 0 to disable automatic retries.
Account for these retries when adding an application-level retry policy.
This example converts a PDF to HTML with debug logging enabled and records the debug log URL when available. Use the input and settings from the conversion you are investigating.
import logging import pdfcrowd logging.basicConfig(level=logging.INFO) client = pdfcrowd.PdfToHtmlClient('demo', 'demo') try: client.setDebugLog(True) client.convertUrlToFile( 'https://your-server.com/invoice.pdf', 'invoice.html' ) except pdfcrowd.Error as error: logging.error("PDFCrowd: %s", error) logging.error("Status: %s; reason: %s", error.getStatusCode(), error.getReasonCode()) raise finally: if client.getDebugLogUrl(): logging.info("Debug log: %s", client.getDebugLogUrl())
The debug log contains conversion settings and processing details. You can also find logs in your conversion history. A local or connection failure may occur before a conversion log is available.
| Problem | Check |
|---|---|
| The PDF cannot be loaded | Check that the URL returns a PDF, rather than HTML or a login page, and is reachable from PDFCrowd's servers. For local files, check the path and read permissions. |
| The PDF requires a password | Set the input document's password with setPdfPassword(). |
| Images, fonts or styles are missing | If resource modes are set to "separate", extract the ZIP archive and retain its relative directory structure. |
| The layout does not adapt to the screen | The HTML preserves the PDF page layout. Responsive layouts require further work on the generated HTML and CSS. |
For help, contact support and include any available diagnostics, the client version, and enough detail to reproduce the problem.