Tutorial

How to Generate a PDF from a Web Page

Convert any web page to a high-quality PDF using the SnapAPI /v1/pdf endpoint. Choose paper format, margins, orientation, and background colors.

Steps

  1. Call /v1/pdf with a URLSend a GET request to /v1/pdf with your URL and API key. SnapAPI renders the page in a real browser and returns a PDF binary.
  2. Choose paper formatSet format=A4, Letter, Legal, A3, or A5. Add landscape=true for horizontal orientation.
  3. Control margins and backgroundSet margin_top, margin_right, margin_bottom, margin_left in pixels. Use print_background=true to include background colors and images.
  4. Save the resultThe response is a PDF binary with Content-Type: application/pdf. Write it directly to a .pdf file.

Code Examples

curl "https://snapapi.tech/v1/pdf?url=https://example.com&api_key=YOUR_KEY&format=A4" -o page.pdf
import requests

response = requests.get("https://snapapi.tech/v1/pdf", params={
    "url": "https://example.com",
    "api_key": "YOUR_KEY",
    "format": "A4",
    "print_background": "true"
})
with open("page.pdf", "wb") as f:
    f.write(response.content)
print("PDF saved!")
const res = await fetch(
  "https://snapapi.tech/v1/pdf?" + new URLSearchParams({
    url: "https://example.com",
    api_key: "YOUR_KEY",
    format: "A4",
    print_background: "true"
  })
);
require("fs").writeFileSync("page.pdf", Buffer.from(await res.arrayBuffer()));
Get Free API KeyFull API Docs