/// REFERENCE

How do I convert a URL to PDF with the ASHDOCS API?

Reference for POST /api/v1/tools/url-to-pdf: SSRF-guarded with private IPs refused, plus wait strategies, page format and print stylesheet options.

Published: Last updated:

Answer: POST /api/v1/tools/url-to-pdf takes JSON with a public url and an options object, loads the page in headless Chromium and returns the PDF in a job envelope; two credits. Private and metadata addresses are refused before anything is fetched. The options below set the viewport, when the capture fires and the page geometry; a value out of range is a 400 naming the field, raised before any job or credit moves.

Request

Options travel in a nested options object. The setting that most often decides whether the PDF looks right is wait_until: a page captured before its JavaScript finishes renders blank or half-loaded, which networkidle (the default) and wait_extra_ms are there to prevent.

bash
curl -X POST https://www.ashdocs.com/api/v1/tools/url-to-pdf \
  -H "X-API-Key: ash_test_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/report",
        "options": { "format": "Letter", "wait_until": "networkidle", "wait_extra_ms": 500 } }'

When there is no Chromium

On a host without a Chromium binary the page is rendered by WeasyPrint instead, and the job's render info says so — it is never a silent switch.

Options

Generated from the URL renderer's option parser.

Sent inKeyWhat it does
optionsviewport.width / viewport.heightBrowser window in CSS pixels. Default 1280 × 800; width 320–3840, height 320–4320.
optionswait_until (alias wait_for)When to capture: networkidle, load, domcontentloaded. Default networkidle.
optionswait_extra_msExtra wait after the load condition, 0–10000 ms. Default 0.
optionsscroll_lazyDefault true: scrolls the page first so lazy-loaded images load.
optionsprint_background (alias printBackground)Default true: print background colours and images.
optionsmediascreen (default) or print — which CSS media the page is rendered as.
optionsformat (alias page_size)Paper size: A4, Letter, Legal, A3, A5. Default A4.
optionslandscapeDefault false.
optionsprefer_css_page_sizetrue lets the page's own @page size win over format. Default false.
optionsscaleRender scale, 0.1–2.0. Default 1.0.
optionsmargin_mmPage margin, 0–50 mm. Default 10.

Frequently asked questions

Why is my PDF blank or half-loaded?

The capture fired before the page finished rendering. Keep wait_until at networkidle and add wait_extra_ms for pages that render after the network goes quiet.

Can I capture the page's print stylesheet?

Yes — set media to print. The default is screen.

Can it fetch an internal URL?

No. Private, loopback and metadata addresses are refused before the fetch.