HTML to PDF / 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 PDF 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 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/
Example 2: HTML File Upload
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/
Example 3: Basic Customization
Customize the PDF output with page size, orientation, margins, and headers/footers. 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.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/
Example 4: Print-Optimized Conversions
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.
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.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/
JavaScript Preprocessing
  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/
Render at Specific Viewport Width
  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 "viewpor_small.pdf" \ -F "content_viewport_width=small" \ -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.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/
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.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 (appliesdisplay:none !important) - 
    
pdfcrowd-hide- Hides the element but preserves its space (appliesvisibility: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: alwaysorpage-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/
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.
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 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.
         | 
      
| 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.
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:
- Review the API Status Codes for specific error code explanations
 - Check the FAQ for answers to common questions
 - Visit the Parameter Reference for detailed configuration options
 - Contact support with the information below
 
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 PDF API Parameter Reference for a detailed description of all parameters.