PHP Java .NET Python Node.js Ruby Go Command Line API WebSave WordPress Zapier Make (formerly Integromat) Postman Bubble Integrately Appy Pie Pipedream Activepieces Pabbly

HTML to PDF HTTP API Documentation

Convert URLs and HTML to PDF with direct HTTP POST requests.

Overview

This document describes direct HTTP access to the HTML to PDF API. It supports converting a URL, an uploaded HTML file, or an HTML string to PDF. If you prefer a language-specific client library, see the Official SDKs.

An AI coding agent can integrate this API for you. See the AI Coding Agent Guide.

Quick Start

Start by running one of the complete cURL commands below. These commands use direct HTTP POST requests and cover URL, file, and HTML string input.

The API uses HTTP Basic authentication. The commands below use demo credentials and work as-is. You can obtain your own PDFCrowd username and API key from a free trial or API license.

Convert a URL

Converts a public URL to PDF with minimal parameters. The PDF is returned in the response body and saved to a local file.

curl -f -u "demo:demo" \
    -o "example.pdf" \
    -F "content_viewport_width=balanced" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Upload an HTML File

Convert local HTML files to PDF. This is useful when working with HTML generated by tools, templates, or any content stored locally.

Single HTML File

Upload a single HTML file for conversion.

curl -f -u "demo:demo" \
    -o "output.pdf" \
    -F "content_viewport_width=balanced" \
    -F "file=@/path/to/your/document.html" \
    https://api.pdfcrowd.com/convert/24.04/

Archive with Local Assets

For HTML documents with local external assets (images, CSS, JavaScript), create an archive (.zip, .tar.gz, or .tar.bz2) containing your HTML file and all referenced local resources. The API will automatically extract the archive and convert the HTML file found in the top-level folder. If your archive contains multiple HTML files, use the zip_main_filename parameter to specify which one to convert.

Note: External assets hosted on the internet are loaded normally and do not need to be included in the archive.

curl -f -u "demo:demo" \
    -o "output.pdf" \
    -F "content_viewport_width=balanced" \
    -F "file=@/path/to/your/archive.zip" \
    https://api.pdfcrowd.com/convert/24.04/

Send an HTML String

Pipe generated HTML into the text parameter. This avoids shell quoting issues when the HTML is produced by a script or another command. If the HTML is already saved as a file, use the HTML file upload command above.

generate_html | curl -f -u "demo:demo" \
    -o "html.pdf" \
    -F "content_viewport_width=balanced" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/

Customize the Output

Customize the PDF output with page size, orientation, margins, and headers/footers. This request demonstrates the most commonly used customization options.

See the complete parameter reference for all available customization parameters.

curl -f -u "demo:demo" \
    -o "customized.pdf" \
    -F "content_viewport_width=balanced" \
    -F "page_size=Letter" \
    -F "orientation=landscape" \
    -F "margin_top=0.5in" \
    -F "margin_bottom=0.5in" \
    -F "margin_left=0.5in" \
    -F "margin_right=0.5in" \
    -F "footer_height=1cm" \
    --form-string "footer_html=<div style='text-align:center; font-size:10px;'>Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span></div>" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/
Interactive Configuration Tool: Want to experiment with PDF generation settings visually? Try our API Playground to test different conversion options like margins, headers, and page layouts, then generate ready-to-use cURL commands. The playground opens in a new tab so you can reference this documentation while experimenting.

Create a Print-Friendly PDF

Converting web pages to clean PDFs can be challenging, whether adapting existing pages not designed for print or creating pages specifically for PDF output. The following techniques help optimize the result. You can use them individually or combine them as needed.

Hide or Restyle Page Elements

Inject custom CSS at conversion time using custom_css to hide elements or adjust layouts.

curl -f -u "demo:demo" \
    -o "custom_css.pdf" \
    -F "content_viewport_width=balanced" \
    --form-string "custom_css=
        /* Hide navigation, ads, and sidebar */
        nav, .advertisement, .sidebar, footer {
            display: none !important;
        }
        /* Adjust layout for print */
        .content {
            width: 100% !important;
            max-width: none !important;
        }
    " \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Run JavaScript Before Conversion

Run JavaScript before conversion using custom_javascript to remove or modify content dynamically.

curl -f -u "demo:demo" \
    -o "custom_js.pdf" \
    -F "content_viewport_width=balanced" \
    --form-string "custom_javascript=
        // Remove dynamic content before conversion
        document.querySelectorAll('.video-player, .chat-widget').forEach(el => {
            el.remove();
        });
        // Expand collapsed sections
        document.querySelectorAll('.collapsed').forEach(el => {
            el.classList.remove('collapsed');
        });
    " \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Control Responsive Layout

Control how content is rendered by setting a specific viewport width using content_viewport_width. This is useful for controlling responsive layouts.

Common viewport widths: Mobile (375-414px), Tablet (768-834px), Desktop (1280-1920px). You can also use presets: small (480px), medium (1024px), large (1200px), or balanced (auto-detect optimal width).

curl -f -u "demo:demo" \
    -o "viewport_small.pdf" \
    -F "content_viewport_width=small" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Wait for Dynamic Content

Ensure dynamic content is fully loaded before conversion. Use javascript_delay to wait a fixed time (in milliseconds) for JavaScript/AJAX to complete.

# Wait for a specified time before conversion
curl -f -u "demo:demo" \
    -o "with_delay.pdf" \
    -F "content_viewport_width=balanced" \
    -F "javascript_delay=2000" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Or wait_for_element to wait until a specific element appears in the DOM (more reliable for dynamic content).

# Wait for a specific element to appear
curl -f -u "demo:demo" \
    -o "wait_element.pdf" \
    -F "content_viewport_width=balanced" \
    -F "wait_for_element=#content-loaded" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Apply Print CSS

Apply existing @media print CSS rules from your webpage using the use_print_media parameter. This only works if your page provides print media styles.

curl -f -u "demo:demo" \
    -o "print_media.pdf" \
    -F "content_viewport_width=balanced" \
    -F "use_print_media=true" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

HTML and CSS Techniques

You can also optimize PDFs by modifying your HTML and CSS directly. These techniques work alongside the API parameters shown above.

Element Removal Classes: Add these classes to HTML elements you want to control in the PDF output:

  • pdfcrowd-remove - Removes the element from the layout (applies display:none !important)
  • pdfcrowd-hide - Hides the element but preserves its space (applies visibility:hidden !important)
<nav class="pdfcrowd-remove">This won't appear in the PDF</nav>
<div class="pdfcrowd-hide">This is invisible but takes up space</div>

Page Breaks: Control page breaks using CSS properties:

  • Force a page break: page-break-before: always or page-break-after: always
  • Avoid page breaks inside elements: page-break-inside: avoid
<!-- Force page break before this section -->
<div style="page-break-before: always"></div>

<!-- Avoid breaking tables across pages -->
<style>
  table, tr, td { page-break-inside: avoid; }
</style>

Conversion-Specific Styling: Prefix your CSS selectors with .pdfcrowd-body to ensure styles apply only during conversion:

<style>
  /* These styles only apply during PDF conversion */
  .pdfcrowd-body h1 { font-size: 48px; }
  .pdfcrowd-body footer { display: none; }
  .pdfcrowd-body .main-content { width: 100%; }
</style>

HTTP Request

All conversion API requests are sent as POST requests to the conversion endpoint. This section covers the technical details, including endpoint URLs, authentication methods, parameter format, and request structure.

Endpoint

https://api.pdfcrowd.com/convert/24.04/

Show older API versions

Authentication

The API uses HTTP Basic authentication with a PDFCrowd username and API key. To get started quickly, you can use these demo credentials for testing:

  • Username: demo
  • API key: demo

Use your own PDFCrowd username and API key for production. You can obtain API credentials from a free trial or API license.

Show authentication details

POST Parameters

Conversion settings and options are sent as parameters in the POST request body to configure the conversion. For a complete list of available parameters and their descriptions, see the Parameter Reference.

URL Parameters

The following optional parameter can be appended to the endpoint URL:

  • errfmt – Specifies the error response format (see HTTP Response)
    • txt – Returns errors in plain text format (default)
    • json – Returns errors in JSON format

Example: https://api.pdfcrowd.com/convert/24.04/?errfmt=json

Request Format

The Content-Type header must match the request body format. Most HTTP libraries and tools set this automatically based on how you structure your request.

  • multipart/form-data – Required when uploading local files
  • application/x-www-form-urlencoded – May be used when no files are uploaded

Note: If you are using a standard HTTP client library or tool, the Content-Type is typically set automatically. You only need to set this manually when working with low-level HTTP libraries.

HTTP Response

The API returns different responses based on the conversion outcome. This section explains HTTP status codes, response body formats for both successful conversions and errors, and response headers containing conversion metadata.

Success Response

HTTP Status: 200 OK

The converted file is returned in the response body. The Content-Type header is set to the appropriate MIME type for the output format.

Error Response

HTTP Status: 4xx (client error)

Error details are returned in the response body. The format is controlled by the errfmt URL parameter (see HTTP Request).

Text Format (errfmt=txt, default)

Content-Type: text/plain

<status_code>.<reason_code> - <message>

JSON Format (errfmt=json)

Content-Type: application/json

{
  "status_code": <http_status_code>,
  "reason_code": <specific_error_code>,
  "message": "<error_message>"
}

For a complete list of status codes and reason codes, see API Status Codes.

Response Headers

The HTTP response includes the following headers with additional information about the conversion:

Name Description
x-pdfcrowd-debug-log URL pointing to the debug log for this request.
x-pdfcrowd-remaining-credits Number of conversion credits remaining in your account.
x-pdfcrowd-consumed-credits Number of credits consumed for this conversion.
x-pdfcrowd-job-id Unique identifier assigned to this conversion job.
x-pdfcrowd-pages Total number of pages in the output document.
x-pdfcrowd-total-pages Total number of pages in the source document before page range filtering (see print_page_range option).
x-pdfcrowd-output-size Size of the output data in bytes.
x-pdfcrowd-reason-code The error reason code, or 0 if no error.

Troubleshooting

This section helps diagnose common HTTP API issues and points to the relevant settings, examples, and support information.

Common Issues

Issue Solution
Dynamic content not rendered Use javascript_delay or wait_for_element. More.
Unexpected page breaks Use CSS page-break-inside: avoid to prevent breaks, or page-break-before/after: always to force them. More.
Page rendered at unexpected width Set content_viewport_width to a specific value (e.g., 800px, 1280px) or preset (small, medium, large). More.
Missing images or styling in uploaded files Create a .zip archive containing your HTML file and all local assets. More.

Debugging Tools and Techniques

Debug Log

Use the debug_log parameter to capture detailed information about the conversion process on PDFCrowd servers, including resource loading, timeouts, browser console output, and load times. Set it to true to enable it.

The debug log URL is returned in the x-pdfcrowd-debug-log HTTP response header and is also available in your conversion log.

Inspect Failed cURL Requests

Use this command when the API returns HTTP status 400 or higher and you need to inspect the error response. It preserves the response body, saves response headers, and requests structured JSON error details.

curl --fail-with-body -u "demo:demo" \
    -D headers.txt \
    -o error-response.json \
    -F "url=http://www.example.com" \
    "https://api.pdfcrowd.com/convert/24.04/?errfmt=json"

--fail-with-body keeps the error body visible while still returning a non-zero exit status, -D headers.txt saves response headers, and errfmt=json returns structured error details.

API Status Codes

If you receive an error, refer to the API Status Codes page for detailed explanations of specific error codes. You can also use errfmt=json in the endpoint URL to get structured error responses (see HTTP Response).

Getting Help

If you're still experiencing issues after trying these solutions:

When contacting support, please include:

  • Your complete curl command (or HTTP request details)
  • The source URL or HTML file you're trying to convert
  • Any error messages or HTTP status codes received
  • Debug log output (if available)
  • Expected behavior vs. actual result