ScreenshotNeo

BlogHow-to

How to Generate GST Invoice PDFs From a Website With Html2Pdf.app

Build a GST invoice PDF from website HTML with Html2Pdf.app. Learn the API flow, required invoice details, security, async jobs, and troubleshooting.

By the ScreenshotNeo team4 October 202610 min read

Direct answer: Build the invoice HTML on your website’s backend, then send it in an authenticated JSON POST request to Html2Pdf.app’s https://api.html2pdf.app/v1/generate endpoint. Check the HTTP status and save or stream the successful response bytes as a PDF. Keep the API key on the server. A rendered PDF is a document-formatting result; it does not by itself complete any e-invoice registration or reporting that may apply to the transaction.

This guide covers the documented Html2Pdf.app API workflow, sample code, invoice content to consider, asynchronous generation, and common rendering and integration problems. GST particulars and e-invoice applicability depend on current rules and the transaction; verify them with official sources and qualified tax guidance before putting a template into production.

1. Choose HTML input or a reachable URL

Html2Pdf.app documents two input approaches:

  • Raw HTML: Your backend assembles the invoice markup and submits it directly. This is useful when invoice data is private or the page requires an authenticated application session.
  • Page URL: Submit a URL the rendering service can reach. The page and its CSS, fonts, and images must also be accessible to the service.

For invoices assembled from customer and order data, raw HTML keeps the document generation flow within your backend. A URL can be convenient when your application already renders a stable, public invoice page. Do not make a private invoice publicly reachable solely to use URL-based conversion without first considering access control and data exposure.

2. Include the applicable GST invoice particulars

CBIC Rule 46 lists particulars for tax invoices, with some requirements conditional on the recipient, supply, and other circumstances. A template may need to include:

  • Supplier name, address, and GSTIN.
  • A consecutive serial number unique for the financial year, and the date of issue.
  • Recipient name, address, and GSTIN or UIN where applicable.
  • HSN code for goods or the accounting code for services, plus a description.
  • Quantity and unit for goods, where relevant.
  • Total value and taxable value of the supply.
  • Applicable tax rates and tax amounts.
  • Conditional particulars such as place of supply, delivery address, reverse-charge status, and supplier signature.

Use the current text of CBIC’s CGST Rules, including Rule 46, and Section 31 of the CGST Act when deciding what applies. The list above is a development checklist, not a universal invoice template or legal advice. Configure fields and conditions for the relevant taxpayer and transaction, and check current amendments before launch.

3. Generate a PDF synchronously from a backend

The synchronous API flow is: create the HTML, make an authenticated JSON POST request, check for an HTTP success response, then treat the response body as PDF bytes. The API key must stay in server-side configuration. Html2Pdf.app’s documentation says not to expose it in browser JavaScript, public repositories, or client-side templates.

cURL example

curl -X POST "https://api.html2pdf.app/v1/generate" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $HTML2PDF_API_KEY" \
  --data '{"html":"<!doctype html><html><body><h1>GST Invoice</h1><p>Invoice INV-2026-001</p></body></html>"}' \
  --output invoice.pdf

Set HTML2PDF_API_KEY in the shell environment before running the command. The example HTML is deliberately minimal; replace it with a complete, escaped invoice template and validated invoice data.

Python example

import os
import requests

api_key = os.environ["HTML2PDF_API_KEY"]
html = """<!doctype html>
<html>
  <head><meta charset=\"utf-8\"></head>
  <body>
    <h1>GST Invoice</h1>
    <p>Invoice INV-2026-001</p>
    <p>Supplier: Example Supplier</p>
  </body>
</html>"""

response = requests.post(
    "https://api.html2pdf.app/v1/generate",
    headers={
        "X-API-Key": api_key,
        "Content-Type": "application/json",
    },
    json={"html": html},
    timeout=90,
)
response.raise_for_status()

with open("invoice.pdf", "wb") as pdf_file:
    pdf_file.write(response.content)

Install the dependency with python -m pip install requests. For an application, choose a timeout appropriate to its request and job model, and handle HTTP errors without returning provider details or secrets to end users.

Node.js example

const apiKey = process.env.HTML2PDF_API_KEY;
if (!apiKey) throw new Error('Set HTML2PDF_API_KEY on the server');

const html = `<!doctype html>
<html>
  <head><meta charset="utf-8"></head>
  <body>
    <h1>GST Invoice</h1>
    <p>Invoice INV-2026-001</p>
    <p>Supplier: Example Supplier</p>
  </body>
</html>`;

const response = await fetch('https://api.html2pdf.app/v1/generate', {
  method: 'POST',
  headers: {
    'X-API-Key': apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ html }),
});

if (!response.ok) {
  throw new Error(`PDF generation failed with HTTP ${response.status}`);
}

const pdfBytes = Buffer.from(await response.arrayBuffer());
const { writeFile } = await import('node:fs/promises');
await writeFile('invoice.pdf', pdfBytes);

This example uses Node.js with built-in fetch and filesystem APIs. Run it in a server process with HTML2PDF_API_KEY configured. The browser must not call this provider endpoint with a secret key.

Serve the PDF from your website

In a web application, your own backend can accept invoice data, validate it, build the HTML, and call the conversion API. On success, return the bytes with a PDF content type and a safe download filename. If you store the PDF, apply your application’s existing access controls and retention rules. Avoid logging full invoice HTML or personal and financial data unnecessarily.

4. Use the documented asynchronous callback flow for queued work

Html2Pdf.app also documents a callBackUrl asynchronous flow for longer-running jobs. In this flow, the initial response can be HTTP 202 Accepted. That means the job was accepted for processing; it does not mean the response body contains the finished PDF. The service later sends the document payload to the callback endpoint.

Use this pattern when your website should queue invoice creation and notify the user when it is ready. Your backend should record a job state, associate the callback with that job, and handle callback delivery according to the provider’s documented payload format. Do not assume a callback is a synchronous PDF response. Protect the callback route and validate incoming requests using the mechanism documented by the provider; do not invent signature headers or payload fields.

5. Make the HTML render consistently

The appearance of the PDF depends on the actual HTML and resources that the rendering service can load. Html2Pdf.app’s documentation calls out media selection, fonts and other resources, and JavaScript load timing as factors. Its cURL guidance recommends confirming that the page URL and its CSS, fonts, and images are accessible when output is blank or unstyled.

  • Use a clear document structure and include a character encoding declaration such as <meta charset="utf-8">.
  • Prefer self-contained invoice markup and stable styles for raw HTML input. If you depend on external resources, verify the renderer can access them.
  • For URL input, make sure the URL is reachable by the conversion service without relying on a browser session or local network.
  • Account for JavaScript-driven content: it must be present when rendering occurs. Avoid depending on content that appears only after unpredictable client-side activity.
  • Check the selected print or screen media behavior and fonts in the generated document. Do not assume browser preview and PDF output are identical.
  • Review representative invoices for page breaks, clipped rows, long descriptions, totals, and signatures before enabling production downloads.

6. Separate PDF rendering from e-invoice reporting

A PDF is a human-readable rendering of invoice information. It does not by itself establish that invoice details were registered or reported through an Invoice Registration Portal (IRP), or that an IRN was issued where the rules require it. The GSTN-hosted 2025 e-invoice brochure describes IRP functionality and reporting of applicable invoice details in a notified format.

Determine whether e-invoicing applies to your taxpayer and transaction under current official rules. If it does, implement that reporting step as a distinct part of the invoice workflow, and only represent its status in the PDF when your system has reliable evidence of that status. The cited materials do not determine applicability for a specific business.

7. Troubleshooting

Symptom Likely cause What to check or do
Authentication error The API key is missing, invalid, or sent in the wrong place. Confirm the server has the key configured and send it in the documented X-API-Key header. Keep it out of browser code and public files.
The saved file is not a PDF An error response or non-PDF response was saved as if it were document bytes. Check the HTTP status before writing the response body. Log a sanitized error summary for diagnosis rather than blindly saving every response.
HTTP 202 but no PDF in the response The request used the asynchronous callback flow. Treat 202 as job acceptance and receive the result at the configured callback URL as described in the provider documentation.
Blank or incomplete document The renderer could not reach the page or required assets, or dynamic content was not ready. For URL input, check reachability of the page, CSS, fonts, and images. For HTML input, inspect the submitted markup and JavaScript-dependent content timing.
Missing styles or unexpected print layout Stylesheets, font files, or media selection differ in the rendering environment. Make resource URLs accessible, review the documented media behavior, and compare the generated PDF with the intended print styles.
Content or totals are cut off across pages The template has not been reviewed with realistic invoice lengths and page boundaries. Generate representative cases with long descriptions, many line items, and different recipient details. Adjust the HTML/CSS and recheck the PDF output.
PDF generation exceeds the website request window A synchronous conversion is taking longer than the application request can wait. Use the documented callback flow for queued work, and set application-level timeouts and job status handling to match that workflow.
API key appears in a browser request or repository The conversion call was implemented in client-side code or the secret was committed. Move the call to the backend, rotate an exposed key, and remove it from public source and client templates.

8. Performance, reliability, and cost considerations

The reviewed API documentation describes synchronous and callback generation but does not establish a universal latency threshold for choosing between them. Keep synchronous generation when its wait fits your user flow; use asynchronous jobs when the website should return promptly and finish the document in the background. Base timeout, retry, and user-notification behavior on your own application requirements and the provider’s current service documentation.

Do not retry blindly after an ambiguous network failure: the request might have completed even if your application did not receive the response. Track invoice and generation job identifiers in your own system, and define a safe recovery process so a retry does not create a confusing duplicate document or status. Validate the resulting PDF before treating it as ready for download.

Check Html2Pdf.app’s current pricing and plan limits directly before estimating cost; vendor prices and feature availability can change. The reviewed sources do not establish a verified conversion benchmark or independently verified uptime figure, so this guide makes no such claim. Account for application-side storage, retry handling, and support needs as well as the conversion service charge.

9. Or skip the browser setup

If the goal is a screenshot of an invoice page rather than a PDF invoice document, ScreenshotNeo is a website screenshot API and MCP server for developers. It captures a website as PNG, JPEG, WebP, or PDF from one GET request. It is not a substitute for GST invoice validation or IRP reporting.

See the ScreenshotNeo API documentation. For example, this cURL request captures a page as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets 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 screenshots a month with no card, and paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo and get 1,000 free screenshots a month with no card.

FAQ

Can I call Html2Pdf.app directly from the browser?

Keep the API key on your backend. Have the browser send invoice data to your application, then let the server make the authenticated conversion request.

Does a generated PDF prove that an invoice was registered with an IRP?

No. PDF conversion renders a document. Any required e-invoice registration or reporting is a separate workflow.

Should I submit HTML or a URL?

Use raw HTML when your backend constructs invoice content privately. Use a URL when the rendering service can reach the page and its required resources.

Does HTTP 202 contain the completed PDF?

In the documented callback flow, 202 means the job was accepted. The result is delivered later to the callback endpoint.

References