Skip to main content

API Reference

Request

Endpoints

The API accepts POST requests at the following two endpoints:

  • HTML to PDF: https://api.polydoc.tech/pdf/convert
  • HTML to Screenshot: https://api.polydoc.tech/screenshot/convert

Request Headers

Parameter
Examples
  • Authorization
    stringrequired
    Bearer token for authentication. Use your API key from the Dashboard.
  • Content-Type
    stringrequired
    Must be set to application/json for all requests with a JSON body.
  • X-Sandbox
    string
    Set to true to use the sandbox environment. Sandbox conversions do not count towards your monthly limit but produce output with a watermark. Omit or set to false for production use.

Rate Limit

The API is rate-limited to prevent abuse. The following rate limits apply, depending whether you are using the X-Sandbox header or not.

ModeRequests per MinuteRequests per Second
Production50050
Sandbox505

See the response section below for more information on how to keep track of your rate limit status in the response headers (X-RateLimit-*), and about the 429 status code that is returned when you exceed the rate limit.

API Parameters

The request body is a JSON object of API parameters. The smallest valid request only sets source; everything else is optional. The public schema matches the PdfOptions / ScreenshotOptions types in polydoc-types (layout may be omitted and is merged with server defaults).

Related guides: Templates, PDF/A, E-Invoice, CSS Paged Media, Cloud storage uploads, Webhook signatures, Integrations.

Main Params

Parameter
Examples
  • source
    stringrequired
    The source of the conversion. This can be a URL, HTML content, or a template.
  • filename
    string
    The filename of the output file. If not specified, the filename will be automatically generated.
  • tag
    string
    Optional short label for logging and tracing (max 30 characters). Not shown inside the PDF.
  • templateData
    object
    Key-value data passed into Liquid when source is a [template:…] reference. See the Templates guide.
  • webhook
    object
    When present, the gateway completes conversion first, then either returns the file on the original response (sync) or 202 JSON while delivering in the background (async). Outbound webhook request body = raw PDF or image bytes; header X-Signature = HMAC-SHA256 of the body. The webhook object is stripped before the converter runs.
    • url
      stringrequired
      The URL of the webhook.
    • async
      boolean
      When true (default), respond with 202 Accepted and JSON while the file is POSTed to your webhook in the background. When false, wait for webhook delivery (including retries), then respond with 200 OK and the same PDF or image bytes as the response body.
    • method
      GET|POST|PUT|PATCH|DELETE
      HTTP method for the webhook request. Default is POST.
    • headers
      object
      Extra headers on the webhook request (e.g. authorization).
    • timeout
      number
      Webhook HTTP timeout in milliseconds for the outbound call.
    • retries
      integer
      How many times to retry a failed webhook delivery.
    • retryDelay
      number
      Delay in milliseconds between webhook retry attempts.
  • timeout
    number
    Maximum time for the conversion in milliseconds (Chromium navigation, rendering, and PDF generation). Default 30000 (30 seconds). Maximum 600000 (10 minutes). Free plan: capped at 30000 (30 seconds).

Layout Params

The whole layout object is optional: omitted fields use converter defaults (for example Letter size and standard margins). For CSS Paged Media workflows, see CSS Paged Media and layout.preferCSSPageSize.

Parameter
Examples
  • displayHeaderFooter
    boolean
    Whether to display the header and footer on the PDF page. The default value is true.
  • headerTemplate
    string
    The header of the PDF page.
    The header template of the page in HTML format. It supports the following HTML classes to automatically fill in the corresponding values:
    • date: The current date.
    • title: The title of the web page.
    • url: The URL of the web page.
    • pageNumber: The current page number.
    • totalPages: The total number of pages.
  • footerTemplate
    string
    The footer of the PDF page. See headerTemplate above for more information.
  • format
    string | object
    The format of the PDF page. This can be a paper format (accepted values are Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6) or an object of the width and height of the page. The default format is Letter.
    Paramters for the custom format:
    • width
      string|numberrequired
      The width of the page as number or with units (cm, mm, in, px).
    • height
      string|numberrequired
      The height of the page as number or with units (cm, mm, in, px).
  • landscape
    boolean
    Whether to print in landscape orientation.
  • margin
    object
    The margins of the PDF page. Each margin can be specified as number or with units (cm, mm, in, px).
    • top
      string|number
      The top margin of the page. The default value is 2cm.
    • right
      string|number
      The right margin of the page. The default value is 1cm.
    • bottom
      string|number
      The bottom margin of the page. The default value is 2cm.
    • left
      string|number
      The left margin of the page. The default value is 1cm.
  • preferCSSPageSize
    boolean
    Whether to prefer the CSS @page size declaration over the format option. The default value is false.
  • omitBackground
    boolean
    Hides default white background and allows generating PDFs with transparency. The default value is false.
  • printBackground
    boolean
    Whether to print background graphics. The default value is false.
  • pageRanges
    string
    The page ranges to print, e.g. 1-5, 8, 11-13.
  • scale
    number
    Scales the rendering of the web page. The value must be between 0.1 and 2.0. The default value is 1.0.
  • outline
    boolean
    When true, the generated PDF includes a document outline (often labeled Bookmarks in desktop PDF apps): a hierarchical table of contents in the viewer's navigation pane, with entries derived from HTML heading elements (h1h6). Use real heading tags in your document for a meaningful structure.
  • tagged
    boolean
    When true, Chromium emits a tagged PDF: a logical structure tree (tags) for accessibility—better support for screen readers, some viewers, and workflows that rely on PDF/UA-style structure. This is an accessibility feature and is separate from the visual print layout.

PDF Params

Parameter
Examples
  • metadata
    object
    The metadata to include in the PDF.
    • title
      string
      The title of the PDF.
    • author
      string
      The author of the PDF.
    • subject
      string
      The subject of the PDF.
    • keywords
      string[]
      The keywords of the PDF.
    • producer
      string
      The producer of the PDF.
    • creator
      string
      The creator of the PDF.
  • encryption
    object
    Password-based encryption applied after PDF generation (qpdf). Provide at least one of userPassword (open password) or ownerPassword. Each password must be at least 4 characters. Incompatible with pdf.pdfa and with eInvoice.
    • userPassword
      string
      Password required to open the document (viewer “open” password).
    • ownerPassword
      string
      Owner password for full access when permissions are restricted.
  • watermark
    object
    The watermark options for the PDF. The watermark will be added to each page of the PDF.
    • source
      stringrequired
      The source of the watermark. This can be a text string or an image. Images can be URLs or base64 encoded strings. Supported image formats are PNG and JPEG.
    • type
      text|imagerequired
      The type of the watermark.
    • options
      object
      The options for the watermark, depending on the type.
      Text
      • fontFamily
        Courier|Helvetica|TimesRoman
        The font family of the text. The default is Helvetica.
      • fontSize
        number
        The font size (in pt) of the text. The default is 100.
      • fontColor
        string
        The font color of the text. Supported formats are named colors, hex and rgb, e.g., grey, #dddddd, rgb(128,128,128). The default is grey.
      • fontStyle
        italic|normal
        The font style of the text. The default is normal.
      • fontWeight
        bold|normal
        The font weight of the text. The default is normal.
      • opacity
        number
        The opacity of the text. The value must be a number between 0 and 1. The default is 0.1.
      • rotation
        number
        The rotation of the text in degrees. The value must be between -360 and 360. The default is 0.
      • offsetX
        number
        The horizontal offset of the text. The default is 0.
      • offsetY
        number
        The vertical offset of the text. The default is 0.
      • repeat
        repeat|repeat-x|repeat-y|no-repeat
        The repeat mode of the text. The default is repeat.
      Image
      • scale
        number
        The scale of the image. The default is 1.
      • opacity
        number
        The opacity of the image. The value must be a number between 0 and 1. The default is 0.1.
      • rotation
        number
        The rotation of the image in degrees. The value must be between -360 and 360. The default is 0.
    • offsetX
      number
      The horizontal offset of the image. The default is 0.
    • offsetY
      number
      The vertical offset of the image. The default is 0.
    • repeat
      repeat|repeat-x|repeat-y|no-repeat
      The repeat mode of the image. The default is repeat.
  • pdfa
    object
    When set, the generated PDF is post-processed toward PDF/A (ISO 19005) via pdf2pdfa. Conceptual overview and examples: PDF/A guide.
    • level
      "1b"|"2b"|"3b"required
      The PDF/A conformance level to target. "3b" is recommended for HTML-to-PDF workflows because Chromium's renderer produces transparency, which PDF/A-1b forbids.
    • verify
      boolean
      When true, runs VeraPDF after conversion and requires a compliant PDF/A result. If validation fails, the API returns 422 with code: "PDFA_VERIFICATION_FAILED" and no PDF body. On success you receive the PDF with 200 like any other conversion. When false or omitted, conversion is best-effort without this enforcement. Defaults to false.

E-Invoice Params

Add eInvoice to any PDF conversion request to embed a structured invoice into the output PDF. The result is a hybrid PDF — human-readable as a normal PDF and machine-parseable by accounting software — conforming to the ZUGFeRD (Germany) and Factur-X (France / EU) standards. Both formats use the same underlying CII XML and are legally accepted across the EU. For a walkthrough and payload tips, see the E-Invoice guide.

Parameter
Examples
  • standard
    facturx | zugferdrequired
    E-invoice standard to embed. facturx and zugferd produce equivalent hybrid documents and are interoperable; the choice determines the attachment name and label inside the XML.
    • facturx — recommended for France and cross-border EU invoicing.
    • zugferd — common for German domestic invoicing.
  • profile
    stringrequired
    Compliance profile that determines how much data must be present in the XML. Use en16931 for standard EU B2B invoices.
    ValueWhen to use
    minimumPayment data only; no line items. Very lightweight.
    basicwlPayment data without line items.
    basicLine items included, no allowances or charges.
    en16931Full EN 16931 standard — the recommended choice for most B2B invoices.
    extendedSuperset of EN 16931 with extra fields for complex invoicing scenarios.
  • verify
    boolean
    When true, runs VeraPDF on the assembled PDF and requires PDF/A-3b compliance. Non-compliance yields 422 with code: "PDFA_VERIFICATION_FAILED" (JSON pdfa details); no PDF is returned. On success you get 200 with the PDF body. When omitted or false, no strict verification gate is applied. Defaults to false.
  • invoice
    objectrequired
    The invoice data to encode as CII XML.
    • number
      stringrequired
      Invoice number. Must be unique per issuer.
    • issueDate
      stringrequired
      Issue date in YYYY-MM-DD format, e.g. 2026-03-15.
    • dueDate
      string
      Payment due date in YYYY-MM-DD format.
    • currencyCode
      stringrequired
      ISO 4217 currency code, e.g. EUR, USD, GBP.
    • seller
      objectrequired
      Invoice issuer (your company).
      • name
        stringrequired
        Legal company or person name.
      • address
        objectrequired
        Postal address.
        • line1
          stringrequired
          Street and house number.
        • line2
          string
          Additional address line (floor, suite, c/o, etc.).
        • city
          stringrequired
          City.
        • postalCode
          stringrequired
          Postal or ZIP code.
        • countryCode
          stringrequired
          ISO 3166-1 alpha-2 country code, e.g. DE, FR, NL.
      • taxId
        string
        VAT registration number. Strongly recommended for EU B2B invoices (e.g. DE123456789, FR98765432100).
      • email
        string
        Contact email address.
      • phone
        string
        Contact phone number.
    • buyer
      objectrequired
      Invoice recipient (your customer).
      • name
        stringrequired
        Legal company or person name.
      • address
        objectrequired
        Postal address.
        • line1
          stringrequired
          Street and house number.
        • line2
          string
          Additional address line (floor, suite, c/o, etc.).
        • city
          stringrequired
          City.
        • postalCode
          stringrequired
          Postal or ZIP code.
        • countryCode
          stringrequired
          ISO 3166-1 alpha-2 country code, e.g. DE, FR, NL.
      • taxId
        string
        VAT registration number. Strongly recommended for EU B2B invoices (e.g. DE123456789, FR98765432100).
      • email
        string
        Contact email address.
      • phone
        string
        Contact phone number.
    • buyerReference
      string
      Buyer's purchase order number or reference, e.g. PO-2026-7788.
    • note
      string
      Free-text note added to the invoice, e.g. a thank-you message or special instructions.
    • paymentTerms
      string
      Human-readable payment terms, e.g. "Net 30 days" or "2% discount within 10 days".
    • paymentMeans
      object
      Bank account details for payment. Recommended when invoices are processed automatically.
      • typeCode
        stringrequired
        UNTDID 4461 payment means code. Common values: "30" (credit transfer / bank transfer), "58" (SEPA credit transfer).
      • iban
        string
        IBAN of the payee bank account.
      • bic
        string
        BIC / SWIFT code of the bank.
      • accountName
        string
        Account holder name.
      • paymentReference
        string
        Payment reference or remittance information.
    • lines
      object[]required
      Line items. At least one is required.
      • description
        stringrequired
        Product or service description.
      • quantity
        numberrequired
        Number of units.
      • unitCode
        string
        UN/ECE unit of measure code. Common values: C62 (pieces/units), HUR (hours), DAY (days), KGM (kilograms). Defaults to C62.
      • unitPrice
        numberrequired
        Net price per unit (excluding VAT).
      • lineTotal
        numberrequired
        quantity × unitPrice (net, before tax).
      • vatRate
        number
        VAT rate in percent, e.g. 19.0. Defaults to 0.
      • vatCategoryCode
        string
        EN 16931 VAT category code. S = standard rate, Z = zero-rated, E = exempt. Defaults to S.
    • taxSummary
      object[]
      Aggregated VAT totals per rate. Calculated automatically from lines when omitted. Provide explicitly when your invoice has multiple VAT rates or when you need precise rounding control.
      • categoryCode
        stringrequired
        VAT category code (S, Z, E, …).
      • rate
        numberrequired
        VAT rate in percent.
      • taxableAmount
        numberrequired
        Net amount this rate applies to.
      • taxAmount
        numberrequired
        Calculated VAT amount.
    • totalNetAmount
      numberrequired
      Sum of all line totals (net, before tax).
    • totalTaxAmount
      numberrequired
      Total VAT amount.
    • totalGrossAmount
      numberrequired
      totalNetAmount + totalTaxAmount. This is the amount the buyer pays.

Render Params

Controls page load and scripting before print. Paged.js and similar libraries often need waitForSelector, mediaType, and layout preferCSSPageSize — see Paged.js and Vivliostyle.

Parameter
Examples
  • css
    string
    The CSS content to inject into the page.
  • disableJavascript
    boolean
    Whether to disable JavaScript on the page. The default value is false.
  • javascript
    string
    The JavaScript content to inject into the page.
  • waitForSelector
    string
    The CSS selector to wait for before rendering the page. This can be useful to ensure the page is ready to be rendered, especially in case of lazy loading. See also waitForFunction.
  • waitForFunction
    string
    The JavaScript function to wait for before rendering the page. This can be useful to ensure the page is ready to be rendered, especially in case of lazy loading. See also waitForSelector.
  • mediaType
    print|screen
    The media type of the page. The default value is screen.
  • blockAds
    boolean
    When true, ads and trackers are blocked during page load using EasyList / uBlock Origin–compatible filter lists. Only effective when source is a URL; has no effect on HTML string sources. Blocking ads can produce cleaner output and reduce conversion time by preventing chatty ad-network requests from delaying network idle. The default value is false.

Request Params

Parameter
Examples
  • userAgent
    string
    The user agent to use for the request.
  • cookies
    object[]
    The cookies to use for the request. Each cookie must contain either the url or domain parameter.
    • name
      stringrequired
      The name of the cookie.
    • value
      stringrequired
      The value of the cookie.
    • url
      string
      The URL of the cookie.
    • domain
      string
      The domain of the cookie.
    • path
      string
      URL path scope for the cookie.
    • expires
      number
      Expiry time as a Unix timestamp in seconds.
    • secure
      boolean
      Whether the cookie is secure.
    • httpOnly
      boolean
      Whether the cookie is http-only.
    • sameSite
      Strict|Lax|None
      SameSite attribute for the cookie.
  • httpHeaders
    object
    The HTTP headers to use for the request. Each header must be a key-value pair.
  • authentication
    object
    The authentication credentials for the HTTP authentication, using the HTTP Basic scheme.

Cloud Storage Params

When set, the gateway uploads the generated file to your bucket using the presigned URL (HTTP PUT). Step-by-step setup for major providers lives under Cloud storage.

Parameter
Examples
  • cloudStorage
    object
    Target upload: PolyDoc PUTs the PDF or screenshot bytes to this URL after conversion.
    • presignedUrl
      stringrequired
      A presigned HTTP PUT URL for your object store (S3, GCS, Azure, etc.).

Response

HTTP Status Codes

The API returns the following HTTP status codes.

CodeMeaningDescription
200
OKSuccessful conversion. Usually the response body is the PDF or image file. Same when a webhook is used with async: false (webhook is delivered first, then the file is returned). In some modes the body is JSON instead: e.g. cloudStorage upload confirmation, or screenshot encoding: "base64" (payload under data.base64).
202
AcceptedConversion finished and a webhook was provided with async omitted or true (default): JSON response while the file is sent to your webhook in the background.
400
Bad RequestInvalid request body or schema validation failure, template resolution error, or business-rule rejection (e.g. incompatible pdf.pdfa and pdf.encryption). For URL-based sources, navigation errors on the provided URL also surface here.
401
UnauthorizedMissing Authorization: Bearer header or invalid API token.
403
ForbiddenThe authenticated user account is disabled and may not use the API.
404
Not FoundThe requested path does not exist.
408
Request TimeoutThe converter stopped waiting for rendering (e.g. page load, navigation, or in-page script) within the timeout you set on the request (up to 10 minutes on paid plans). Returned by the converter and forwarded by the gateway with a JSON error body.
413
Payload Too LargeRequest body exceeds the gateway size limit, or the converter rejected the payload (e.g. HTML size limit without subscription).
422
Unprocessable EntityThe request was syntactically valid but the promised artifact could not be produced or verified for this input.
429
Too Many RequestsPer-minute or per-second rate limit exceeded (tracked separately for production and sandbox traffic).
500
Internal Server ErrorUnexpected gateway error, conversion engine crash, or other failures not mapped to a more specific code.
502
Bad GatewayConversion succeeded but either uploading to your cloudStorage presigned URL failed, or (with webhook and async: false) webhook delivery failed after retries.
503
Service UnavailableThe converter is busy serving another job (after gateway retries) or a required downstream dependency is unavailable.
504
Gateway TimeoutThe gateway stopped waiting for the converter (or another internal hop timed out). The gateway's converter proxy budget is set above the maximum request timeout (10 minutes on paid plans) so that an overrun during rendering usually surfaces as 408 Request Timeout from the converter with a JSON body instead. If you still see 504 on long jobs, check timeouts on any reverse proxy or load balancer in front of the API.

Headers

Besides defaults from the HTTP stack, typical responses include the following. HTTP header names are case-insensitive per RFC 7230 §3.2; the casing shown here is for readability only — Polydoc may send the same name in any case (e.g. X-RateLimit-Limit or x-ratelimit-limit) and compliant clients normalize on the receiving side.

HeaderDescription
X-Conversion-Id
Canonical id for this conversion. The same value appears as the conversion id in your conversion history. Present on all PDF and screenshot conversion responses (including errors) so you can correlate logs and support tickets.
X-Credit-Used
Integer quota units charged for this attempt — same formula as persisted usage: each block of your per-job data quota (default 5 MB of output) counts as one unit, with a minimum of one unit when the conversion engine ran but returned no file (e.g. converter 4xx/5xx). Validation errors before the conversion engine starts use 0.
Content-Type
application/pdf or an image type for a successful binary body; application/json for JSON-only responses (errors, webhook acceptance, cloud-storage confirmation, base64 screenshot mode).
Content-Disposition
Present on successful PDF or image downloads (attachment with filename). Omitted for JSON bodies.
Content-Length
Length of the response body when the gateway sends raw PDF or image bytes.
X-RateLimit-Limit
Maximum requests allowed in the rate-limit window that supplied this header (see rate limiting). Added by the gateway's rate-limit plugin.
X-RateLimit-Remaining
How many requests remain in that window before a 429 response.
X-RateLimit-Reset
Seconds until the rate-limit window resets.
Retry-After
Present on 429 Too Many Requests from the gateway's rate-limit plugin (window-reset seconds) and on upstream 429 responses forwarded from the conversion service (capacity overflow). Value is the seconds to wait before retrying.

Payload

The successful 200 response contains the PDF or screenshot file. The error payload is a JSON object with details about the error. The HTTP status code is returned on the response line only; it is not repeated inside the JSON body. To correlate a request with support or your conversion history, read the X-Conversion-Id response header.

{
"success": false,
"error": "Bad Request",
"message": "The parameter 'layout.scale' must be a number between 0.1 and 2.0."
}