How to Convert a Webpage URL to PDF with APITemplate.io
Convert a live webpage to PDF with APITemplate.io using its browser tool or REST API. See request examples, settings, download steps, limits, and troubleshooting.
To convert an existing webpage URL to PDF with APITemplate.io, send a JSON POST request to https://rest.apitemplate.io/v2/create-pdf-from-url. Include the target address in url, authenticate with the X-API-KEY header, and optionally set page size, orientation, margins, and print-background behavior. On success, the documented response pattern includes status: success and a download_url.
For an occasional manual conversion, use APITemplate’s online HTML-to-PDF tool: enter a URL, choose page settings, generate the PDF, and download it before it expires. The API is the better fit for repeatable workflows and integrations.
Choose the right conversion method
| Method | Use it when | What you provide |
|---|---|---|
| Browser converter | You need a PDF occasionally and want to configure it by hand. | A webpage URL, uploaded HTML, or pasted HTML. |
| URL API | You need to automate conversion of an existing live page. | A URL and optional PDF settings in a JSON request. |
| Raw HTML | Your application controls or generates the markup. | HTML content. |
| Markdown | Your source content is already Markdown. | Markdown content. |
| Reusable template | You repeatedly create documents with the same layout and changing data. | A template and its variable data. |
This guide focuses on converting a live URL. If you control the content and need consistent branded documents, raw HTML or a reusable template may give you more control than rendering a public page.
Convert a URL with the browser tool
- Open APITemplate.io’s online HTML-to-PDF converter and select URL conversion.
- Enter the webpage address. Use a page you are authorized to access and convert.
- Choose the paper size, orientation, margins, and any available print-style options.
- Generate the PDF, then open it and check pagination, backgrounds, images, and clipping.
- Download the file promptly. The tool states that generated PDFs expire after two hours and allows up to 10 PDF documents per hour; check the tool for current limits.
The browser tool also accepts uploaded or pasted HTML. That can be useful when you have the markup already and do not need to render a live webpage.
Convert a URL with the REST API
The documented endpoint is POST /v2/create-pdf-from-url. Send the target page in the required url field. The API key belongs in the X-API-KEY request header; keep it on a server or in a secret store rather than exposing it in client-side code.
cURL
curl -X POST "https://rest.apitemplate.io/v2/create-pdf-from-url" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/article",
"settings": {
"paper_size": "A4",
"orientation": "1",
"margin_top": "40",
"margin_right": "10",
"margin_bottom": "40",
"margin_left": "10",
"print_background": "1"
}
}'
The values shown are the documented example settings. Choose margins and page size to suit the page rather than treating those values as universal defaults.
Python
This example submits the request, checks for an HTTP error, reads the documented response fields, then downloads the PDF from the returned URL.
import os
import requests
api_key = os.environ["APITEMPLATE_API_KEY"]
endpoint = "https://rest.apitemplate.io/v2/create-pdf-from-url"
payload = {
"url": "https://example.com/article",
"settings": {
"paper_size": "A4",
"orientation": "1",
"margin_top": "40",
"margin_right": "10",
"margin_bottom": "40",
"margin_left": "10",
"print_background": "1",
},
}
response = requests.post(
endpoint,
headers={"X-API-KEY": api_key, "Content-Type": "application/json"},
json=payload,
timeout=120,
)
response.raise_for_status()
result = response.json()
if result.get("status") != "success" or not result.get("download_url"):
raise RuntimeError(f"PDF generation did not return a download URL: {result}")
pdf_response = requests.get(result["download_url"], timeout=120)
pdf_response.raise_for_status()
with open("page.pdf", "wb") as pdf_file:
pdf_file.write(pdf_response.content)
print("Saved page.pdf")
Install the dependency with python -m pip install requests. Set APITEMPLATE_API_KEY in the process environment before running the script. The generation response is JSON in the documented example; the PDF is retrieved separately from its download_url.
Node.js
This example uses the built-in fetch available in current Node.js releases. It checks the API response before downloading the PDF bytes.
const apiKey = process.env.APITEMPLATE_API_KEY;
if (!apiKey) throw new Error("Set APITEMPLATE_API_KEY first");
const endpoint = "https://rest.apitemplate.io/v2/create-pdf-from-url";
const payload = {
url: "https://example.com/article",
settings: {
paper_size: "A4",
orientation: "1",
margin_top: "40",
margin_right: "10",
margin_bottom: "40",
margin_left: "10",
print_background: "1"
}
};
const response = await fetch(endpoint, {
method: "POST",
headers: {
"X-API-KEY": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`PDF API returned HTTP ${response.status}: ${await response.text()}`);
}
const result = await response.json();
if (result.status !== "success" || !result.download_url) {
throw new Error(`PDF generation did not return a download URL: ${JSON.stringify(result)}`);
}
const pdfResponse = await fetch(result.download_url);
if (!pdfResponse.ok) {
throw new Error(`PDF download returned HTTP ${pdfResponse.status}`);
}
const pdfBytes = Buffer.from(await pdfResponse.arrayBuffer());
await import("node:fs/promises").then(({ writeFile }) => writeFile("page.pdf", pdfBytes));
console.log("Saved page.pdf");
Keep the API key in an environment variable, and avoid logging it. The download URL is the value to retrieve after successful generation; do not assume the creation endpoint itself returns raw PDF bytes.
Settings and page output
| Setting | Purpose | Practical guidance |
|---|---|---|
paper_size |
Selects the page format, such as A4 in the documented example. | Match the expected reader or print format. Check whether wide tables or code blocks fit. |
orientation |
Chooses page orientation. The documented example uses "1". |
Use portrait for typical articles; consider landscape for wide layouts. Follow the API’s accepted values. |
margin_top, margin_right, margin_bottom, margin_left |
Set the four page margins. The example supplies values as strings. | Set each edge deliberately. Check headers, footers, and content near page boundaries. |
print_background |
Controls whether background styling is printed. The example uses "1". |
Enable it when background colors or images carry meaning; otherwise the PDF may be easier to print economically. |
These are settings established by the supplied API example, not a complete promise of every accepted value. Consult APITemplate’s current API documentation for its full schema and accepted enumerations. The renderer uses headless Chromium and the documentation says it supports modern CSS and JavaScript, but page rendering and pagination still depend on the site.
Check and handle the result
- Check the HTTP status before parsing the response body.
- For the documented successful response, verify
statusissuccessand thatdownload_urlis present. - Fetch the URL and save the response bytes as a PDF file. Treat the creation response and file download as two separate steps.
- Validate the downloaded file and, for important documents, inspect representative pages for missing assets, clipping, and unexpected page breaks.
Do not treat the sample response shape as a guarantee that every request succeeds or that every webpage renders identically. Handle unsuccessful HTTP responses, incomplete response data, and download failures in your application.
Dynamic pages, access, and fidelity
A URL conversion renders a page in a headless browser. JavaScript and modern CSS support helps with interactive layouts, but it does not guarantee that a page requiring a particular user action will reach the desired state before capture. Pages with content that appears only after scrolling, clicking, or signing in need special care.
- Use accessible pages: submit public URLs or pages you are authorized to convert. The reviewed guidance does not establish that session cookies or authenticated pages are supported, so do not assume a login-gated URL will render as your logged-in user.
- Check lazy content: confirm images and sections that load during scrolling appear in the PDF.
- Check print behavior: a site’s print stylesheet may hide navigation, alter colors, or reflow columns. Inspect the output and available converter options.
- Check long pages: tables, code, fixed-position elements, and large images can split or clip at page boundaries.
- Check external assets: fonts, images, and scripts may be unavailable or slow when the renderer fetches them.
For exact, repeatable document layout, generate or control the HTML or use a reusable template instead of relying on an unrelated page’s responsive and print styles.
Batch jobs, performance, and operating limits
APITemplate documents synchronous generation by default and an asynchronous option for large or batch jobs, with a transaction reference and webhook notification. For a high-volume integration, use the asynchronous workflow described in its REST guide rather than tying a user request to a long-running synchronous call.
- The REST guide documents a limit of 100 requests per 10 seconds per IP.
- It also documents up to 100 concurrent synchronous PDF-generation requests per account.
- The guide discusses regional endpoints, payload-size considerations, and limits on binary file responses.
These are APITemplate service constraints, not general PDF limits. Recheck its current REST documentation before planning production capacity because service limits and endpoints can change. Queue work, limit concurrency, and respond to throttling with bounded retries and backoff. For webhook workflows, make the handler safe to receive repeated notifications and verify completion using the transaction reference and documented response fields.
Generation time depends on the target page and its assets; the supplied material gives no independent performance benchmark. Pages with many scripts, large images, or slow resources can take longer and may fail to render fully. Set client timeouts appropriate to the workflow, record failures without recording secrets, and provide a way to retry or inspect failed jobs.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| Authentication error | The API key is missing, invalid, or sent under the wrong header. | Send the key as X-API-KEY; verify the server-side secret configuration and do not include extra whitespace. |
| Request rejected | Malformed JSON, missing url, or unsupported setting values. |
Send valid JSON with a complete URL and check the current API schema for accepted setting names and values. |
| Page is blank or incomplete | The target may block automated access, require interaction or login, or load assets slowly. | Open the URL without an authenticated session to confirm it is accessible. Check whether content depends on scrolling or user actions; use controlled HTML when you need deterministic content. |
| Images or styling are missing | External resources did not load, or background printing is disabled. | Check whether the resources are publicly reachable and set print_background as needed. Inspect the generated PDF rather than assuming browser rendering matches screen display. |
| Text or tables are clipped | The page layout does not fit the paper size, margins, or print layout. | Try landscape for wide content, adjust margins, and review the page’s print styles or use a layout you control. |
| Generation takes too long or times out | The page or its assets are slow, or a synchronous request is unsuitable for the workload. | Use a suitable client timeout, reduce unnecessary concurrent work, and consider the documented asynchronous job and webhook flow for large or batch workloads. |
| Throttling or capacity errors | Requests exceed published rate or concurrency limits. | Queue requests, reduce concurrency, add bounded backoff, and verify current limits in the REST guide. |
| Creation succeeds but no file is saved | The application did not fetch download_url, or the separate download failed. |
Check the JSON response, fetch the returned URL, check its HTTP status, and save the response bytes as a PDF. |
| Manual download link no longer works | The browser tool’s generated file expired. | Generate the PDF again and download it promptly; the tool states a two-hour expiry. |
Or skip the browser setup
If you need a screenshot of a webpage rather than a paginated PDF, ScreenshotNeo returns PNG, JPEG, WebP, or PDF from one GET request. Its [docs](https://screenshotneo.com/docs/) describe the API and options. For a PDF capture:
curl -G "https://api.screenshotneo.com/v1/shot" \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://stripe.com \
-o page.pdf
ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. See the [ScreenshotNeo API docs](https://screenshotneo.com/docs/) for request options and formats.
Sign up for 1,000 free screenshots a month, with no card required.
Cost and reliability considerations
The supplied APITemplate material does not establish a price for URL conversion, so check its current pricing before estimating recurring usage. Include both generation and file retrieval in your workflow design, and account for failed or delayed jobs in your own retry and support process. The manual converter has a stated hourly limit and file expiry, which makes it a poor fit for unattended recurring work.
For any provider, verify the returned document before distributing it. Do not infer fidelity from a successful status alone: a syntactically successful conversion can still omit page content or paginate it badly.
FAQ
Does the URL API return the PDF directly?
The documented success example returns a download URL in JSON. Your integration should fetch that URL to retrieve and save the PDF.
Can I convert a page that requires login?
The reviewed APITemplate guidance does not establish support for authenticated pages or session cookies. Do not assume a login-required URL will render with your account’s session.
Can I convert a page with JavaScript?
APITemplate says its URL renderer uses headless Chromium and supports JavaScript and modern CSS. That does not guarantee that interaction-dependent or delayed content will appear correctly.
When should I use HTML or a template instead?
Use raw HTML when you control the markup, Markdown when that is your source format, and a reusable template when documents share a layout populated with changing data.
Is this API a good fit for screenshot images too?
The APITemplate workflow here is for PDF output. For webpage screenshots in PNG, JPEG, or WebP, ScreenshotNeo provides a separate screenshot API and an MCP server for AI agents.


