HTML to Image / HTTP API Documentation

Overview

The HTTP API provides direct access to PDFCrowd's conversion service without requiring library installation. Send an HTTP POST request to convert to image from any programming language or platform that supports HTTP requests.

Getting started: Jump to Quick Start for working examples. For technical details about request format, authentication, and response handling, see HTTP Request and HTTP Response. For complete parameter documentation, visit the Parameter Reference.

Quick Start

The following examples demonstrate progressive use of the HTTP API, from basic conversion to advanced customization. Each example is complete and ready to use - just replace the file paths with your own. You can also explore our additional examples for more code samples.

Examples below use demo credentials for testing. For production use, start a free trial or purchase a license.

Note: Examples use Unix shell syntax with curl.

Example 1: Basic URL Conversion

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

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

Example 2: HTML File Upload

Convert local HTML files to images. 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.png" \
    -F "output_format=png" \
    -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.png" \
    -F "output_format=png" \
    -F "file=@/path/to/your/archive.zip" \
    https://api.pdfcrowd.com/convert/24.04/

Example 3: Basic Customization

Customize the image output with screenshot width, output format, and scale factor. This example demonstrates the most commonly used customization options.

See the complete parameter reference for all available customization parameters.

curl -f -u "demo:demo" \
    -o "customized.jpg" \
    -F "screenshot_width=1280" \
    -F "output_format=jpg" \
    -F "scale_factor=50" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/
Interactive Configuration Tool: Want to experiment with image capture settings visually? Try our API Playground to test different output formats, dimensions, and quality settings, then generate ready-to-use curl commands. The playground opens in a new tab so you can reference this documentation while experimenting.

Example 4: Screenshot-Optimized Conversions

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

Custom CSS Styling

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

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

JavaScript Preprocessing

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

curl -f -u "demo:demo" \
    -o "custom_js.png" \
    -F "output_format=png" \
    --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/

Wait Conditions

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.png" \
    -F "output_format=png" \
    -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.png" \
    -F "output_format=png" \
    -F "wait_for_element=#content-loaded" \
    -F "url=http://www.example.com" \
    https://api.pdfcrowd.com/convert/24.04/

Using Print Stylesheets

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.png" \
    -F "output_format=png" \
    -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 screenshots 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 screenshot 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 screenshot</nav>
<div class="pdfcrowd-hide">This is invisible but takes up space</div>

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

<style>
  /* These styles only apply during image 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

For production use, start a free trial or purchase a 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-output-size Size of the output data in bytes.
x-pdfcrowd-reason-code The error reason code, or 0 if no error.

Troubleshooting

This guide helps you diagnose and resolve common HTTP API issues. If you encounter problems, try the solutions below before contacting support.

Common Issues

Issue Solution
Dynamic content not rendered Use javascript_delay or wait_for_element. 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.

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

API Parameter Reference

Refer to the HTML to Image API Parameter Reference for a detailed description of all parameters.