How to Capture GST Invoice Webpages as PDFs with Browserless
Generate a paginated PDF from a GST invoice URL or HTML with Browserless, wait for dynamic content, and handle continuous-page output correctly.
Use Browserless’s POST /pdf REST endpoint to render a GST invoice webpage as a paginated PDF. Send a JSON body containing either a url or raw html, authenticate with your Browserless token in the token query parameter, and save the response bytes as a PDF. For JavaScript-rendered invoices, make sure the invoice content is ready before printing. If you need one continuous page for the full document height, use Browserless /function and calculate the page height; /pdf produces normal paginated output.
This captures a rendered copy of the invoice page. It does not create, register, or validate a GST e-invoice.
1. Generate a PDF from a URL
Get an API token from your Browserless account dashboard. The current REST API expects it as the token query parameter. Replace the example URL with the invoice page that your browser session can access. The example uses a public URL; authenticated invoice sites may need a session-aware approach described below.
curl -X POST 'https://production-sfo.browserless.io/pdf?token=YOUR_BROWSERLESS_TOKEN' \
-H 'Content-Type: application/json' \
--data '{
"url": "https://example.com/invoices/123",
"options": {
"format": "A4",
"printBackground": true,
"displayHeaderFooter": false
}
}' \
--output invoice.pdf
The endpoint returns PDF bytes, so use a binary-safe output option such as --output. Do not parse the response as JSON. Browserless documents the endpoint as accepting a URL or raw HTML and returning a PDF file in its PDF API documentation.
2. Choose PDF settings
Set print options according to the invoice layout and required output. The options are passed in the request’s options object.
| Option | Use |
|---|---|
format |
Choose a standard paper size such as A4 or another supported format. |
printBackground |
Include background colors and images that are part of the printed page. |
displayHeaderFooter |
Enable or disable browser-generated print headers and footers. |
margin |
Set printable margins when the invoice needs more or less space. |
landscape |
Use landscape orientation for unusually wide invoice layouts. |
preferCSSPageSize |
Let the page’s CSS page size rules determine the output when the document defines them. |
Consult the current Browserless PDF API reference for supported option names and value formats; browser and API behavior can change. Check the resulting PDF at its actual printed size, especially if the invoice contains a tax table, QR code, or other small details.
3. Send the request with Python
This runnable example streams the response to a local file and fails visibly on HTTP errors. Install the dependency with python -m pip install requests.
import requests
endpoint = "https://production-sfo.browserless.io/pdf"
params = {"token": "YOUR_BROWSERLESS_TOKEN"}
payload = {
"url": "https://example.com/invoices/123",
"options": {
"format": "A4",
"printBackground": True,
"displayHeaderFooter": False,
},
}
with requests.post(endpoint, params=params, json=payload, timeout=120, stream=True) as response:
response.raise_for_status()
content_type = response.headers.get("Content-Type", "")
if "application/pdf" not in content_type:
raise RuntimeError(f"Expected application/pdf, received {content_type!r}")
with open("invoice.pdf", "wb") as pdf_file:
for chunk in response.iter_content(chunk_size=64 * 1024):
if chunk:
pdf_file.write(chunk)
print("Saved invoice.pdf")
4. Send the request with Node.js
On Node.js versions with built-in fetch, use the response’s arrayBuffer() to preserve the binary PDF data.
import { writeFile } from "node:fs/promises";
const endpoint = new URL("https://production-sfo.browserless.io/pdf");
endpoint.searchParams.set("token", "YOUR_BROWSERLESS_TOKEN");
const response = await fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
url: "https://example.com/invoices/123",
options: {
format: "A4",
printBackground: true,
displayHeaderFooter: false,
},
}),
signal: AbortSignal.timeout(120_000),
});
if (!response.ok) {
throw new Error(`Browserless returned HTTP ${response.status}: ${await response.text()}`);
}
const contentType = response.headers.get("content-type") ?? "";
if (!contentType.includes("application/pdf")) {
throw new Error(`Expected application/pdf, received ${contentType}`);
}
await writeFile("invoice.pdf", Buffer.from(await response.arrayBuffer()));
console.log("Saved invoice.pdf");
5. Render raw HTML instead of navigating to a URL
Use the html field when your application has already produced the invoice markup and you do not need Browserless to navigate to a page. Include the styles required for printing. Send either url or html, not both.
curl -X POST 'https://production-sfo.browserless.io/pdf?token=YOUR_BROWSERLESS_TOKEN' \
-H 'Content-Type: application/json' \
--data-binary '{
"html": "<!doctype html><html><head><style>body{font-family:Arial,sans-serif}@page{size:A4;margin:16mm}</style></head><body><h1>Tax Invoice</h1><p>Invoice content goes here</p></body></html>",
"options": { "format": "A4", "printBackground": true }
}' \
--output invoice.pdf
For invoice HTML generated from untrusted input, escape or sanitize that input before placing it into markup. HTML capture is still browser rendering; it does not verify GST fields or submit anything to a tax portal.
6. Wait for JavaScript-rendered invoice content
A page can return its initial HTML before invoice details have finished loading. If the PDF starts too early, it may omit line items, totals, or a QR code. Define a readiness condition tied to the invoice page, such as a selector that appears only after the invoice data is rendered, or a suitable delay where no reliable selector exists. Browserless’s guidance recommends waiting for elements before PDF generation to avoid incomplete captures; see its PDF generation guidance.
The exact wait mechanism depends on the endpoint and the invoice site’s authentication flow. Use the current Browserless documentation for the supported request configuration. A fixed delay is simple but less reliable: too short can produce a partial document, while too long wastes browser time. Prefer a meaningful element-ready condition when available, and verify it corresponds to fully rendered invoice data rather than just the page shell.
7. Handle authenticated invoice pages
Invoice portals often require a login, session cookie, or application-specific access flow. A URL capture cannot see content that the browser is not authorized to view. Use an approved authentication method supported by the Browserless flow you choose, or render trusted invoice HTML from your own application. Avoid putting account credentials in source code or logs, and do not expose a token in client-side code. Confirm that the resulting PDF belongs to the intended invoice and does not include unrelated authenticated page content.
8. When you need one continuous page
The regular /pdf endpoint creates standard paginated output. If the requirement is one PDF page extending across the entire invoice height, use Browserless’s more flexible /function API: navigate or load the content, determine the rendered document height, then generate a PDF with a custom height. Follow the current Browserless PDF API documentation for the supported function pattern and PDF options.
A continuous page can be hard to read, print, or process in downstream document tools. Use it only when the consuming system explicitly needs a single page; otherwise, normal A4 pagination is usually easier to review.
9. Verify the PDF and keep GST tasks separate
After capture, check that the PDF opens and includes the expected invoice number, date, supplier and recipient details where applicable, line items, tax amounts, total, and any required visual elements. CBIC’s invoice rules list particulars for a tax invoice, including supplier name, address and GSTIN, a consecutive serial number for the financial year, issue date, applicable recipient details, HSN or service accounting code, description, quantity and unit for goods, and total supply value. Browserless does not check those particulars, and a visually complete PDF does not prove legal compliance. See the official CBIC tax invoice rules.
GST e-invoice creation or registration is a separate operation. The GST e-Invoice Portal’s API integration guidance describes a direct integration workflow for taxpayers, including distinct taxpayer and API-integrator users. Rendering an already displayed invoice webpage to PDF does not register an e-invoice.
10. Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| Unauthorized response | Missing, incorrect, or revoked API token. | Check the dashboard token and confirm it is passed as the token query parameter. |
| PDF is blank or missing invoice details | Capture began before asynchronous content rendered, or the page redirected to a login/error screen. | Wait for a reliable invoice-ready selector, then inspect whether the browser can access the authenticated page. |
| Request rejected for input | Malformed JSON, unsupported option values, or both url and html supplied. |
Validate JSON, use exactly one content source, and check option names against the current API docs. |
| Downloaded file is not a PDF | An error response was saved with a .pdf extension, or the response was handled as text. |
Check HTTP status and content type before writing bytes; preserve the response as binary. |
| Text or background colors are missing | Print backgrounds are disabled or page print styles hide content. | Enable printBackground and inspect the page’s print CSS. |
| Invoice is clipped or unexpectedly split | Paper size, margins, orientation, or CSS page rules do not match the layout. | Adjust paper format, margins, landscape, or page-size handling, then inspect the output pages. |
| Only part of a long invoice appears | Content was not fully rendered, or the chosen PDF layout assumptions are wrong. | Wait for content readiness; for a single continuous page, use /function with custom height. |
| Timeout on a slow page | Navigation or application rendering exceeds the request’s available time. | Check page accessibility and readiness conditions, avoid excessive fixed waits, and use the documented timeout/navigation controls for the selected Browserless API. |
11. Performance, reliability, and cost considerations
Each capture requires browser navigation or HTML rendering, page readiness, and PDF generation. Limit unnecessary waits, use a specific content-ready condition, and avoid repeatedly capturing the same unchanged invoice when your workflow can reuse a safely stored result. For retries, distinguish transient navigation or network failures from permanent authentication and input errors. Make retry behavior bounded so an unavailable invoice page does not trigger an endless queue. Protect tokens and any invoice data in request logs and stored artifacts.
Browserless usage, limits, and pricing depend on the current account and plan. Check the provider’s current account information for costs and capacity; the research sources establish the endpoint behavior but do not specify pricing figures. Your application should record whether a capture succeeded and validate the generated file before treating it as complete.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server by Yorker Media. For invoice pages that should be captured as an image rather than a PDF, one GET request returns PNG, JPEG, or WebP. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 shots a month with no card, and paid plans start at $5 for 3,000. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/invoices/123 -o invoice.webp
This produces an image, not a PDF, so use Browserless when a PDF file is the required deliverable. Sign up for ScreenshotNeo’s free 1,000 screenshots a month, with no card required.
FAQ
Does capturing a GST invoice webpage create an e-invoice?
No. It saves a rendered page as a PDF. E-invoice creation and registration are separate processes.
Can Browserless print an invoice that is behind a login?
Only if the browser session used for capture can access the page through an authentication flow supported by the chosen Browserless API.
Can I make the regular PDF endpoint output a single continuous page?
The documented /pdf endpoint is for paginated PDF output. Use /function when you need to calculate and set a custom full-page height.


