Documentation menu

Getting started

API reference

Guides

Trust and support

Quickstart

Three steps: set your key, create a PDF, take a screenshot. Every example on this page is run against the live API before it is published.

1. Set your API key

The examples read the key from the SAHIFA_API_KEY environment variable, so it never ends up in your source code.

# macOS, Linux
export SAHIFA_API_KEY="sk_live_..."

# Windows PowerShell
$env:SAHIFA_API_KEY = "sk_live_..."

Don't have a key yet? See getting an API key.

2. Create a PDF from HTML

This request sends a short Arabic invoice and adds a page footer. It saves invoice.pdf.

# HTML to PDF with an Arabic footer. Requires: SAHIFA_API_KEY in the environment.
curl https://api.sahifa.dev/v3/convert/pdf \
  --user "api:$SAHIFA_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "source": "<html dir=\"rtl\" lang=\"ar\"><body><h1>فاتورة ضريبية</h1><p>الإجمالي: 1,150.00 ر.س</p></body></html>",
    "format": "A4",
    "margin": "20mm",
    "footer": { "source": "<div style=\"width:100%;text-align:center\">صفحة {{page}} من {{total}}</div>" }
  }' \
  --fail-with-body --output invoice.pdf

The footer uses the {{page}} and {{total}} variables. A header or footer needs a margin large enough to hold it. See the PDF reference for every option.

3. Take a screenshot

This request captures a whole web page as PNG and hides cookie consent pop-ups. It saves page.png.

# Full-page screenshot of a URL, without cookie banners. Requires: SAHIFA_API_KEY.
curl --get https://api.sahifa.dev/take \
  --data-urlencode "access_key=$SAHIFA_API_KEY" \
  --data-urlencode "url=https://example.com" \
  --data "format=png" \
  --data "full_page=true" \
  --data "block_cookie_banners=true" \
  --fail-with-body --output page.png

See the screenshot reference for viewports, element capture, dark mode and blocking options.

4. Handle busy moments

When the render queue is full the API answers 429. Retrying after a short wait is safe, because a failed request has no side effects.

# curl retries 408, 429, 500, 502, 503 and 504 responses on its own, honouring Retry-After.
curl https://api.sahifa.dev/v3/convert/pdf \
  --user "api:$SAHIFA_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{ "source": "https://example.com" }' \
  --retry 4 --retry-delay 2 --retry-max-time 60 \
  --fail-with-body --output example.pdf

What next