ScreenshotNeo

BlogHow-to

How to Convert an Indian Government Website Page to PDF with Html2Pdf.app

Save a public Indian government webpage as a PDF with Html2Pdf.app, review the result, and use its API when you need conversion in code.

By the ScreenshotNeo team4 October 20268 min read

To save a public Indian government webpage as a PDF with Html2Pdf.app, open its browser converter, enter the page’s public URL, generate the PDF, download it, and check the result. The homepage advertises URL conversion without an API key. If you need to automate conversion, use the separate authenticated API from a trusted server. A PDF made from a webpage is a saved copy; it is not thereby certified as an official government document.

Convert a page with the browser tool

  1. Open the exact government page you want to save. Confirm that it loads without a sign-in and that the address is the intended official URL.
  2. Open the Html2Pdf.app converter and enter the public webpage URL.
  3. Start the conversion and save the resulting PDF.
  4. Open the PDF and inspect all pages. Check for missing text, clipped tables, shifted columns, absent images, page breaks in the wrong places, and headers or footers that cover content.

This browser workflow does not require an API key, according to the service homepage. A page that needs authentication or is otherwise inaccessible to the converter may not work; the service does not promise session or login support.

Check that the saved copy is useful and authentic

Government of India guidance says a website’s URL is a strong indicator of its authenticity and status. Keep the original URL with the PDF, and, when authenticity matters, revisit and verify the page through that official address. Converting a page does not make the resulting file an official or certified government document. See the Guidelines for Indian Government Websites and Apps and their website guidance.

For a record you may need to verify later, note the source URL and the date you saved it. A PDF reflects what the converter could access and render at conversion time; the live page can change afterward.

Use the API for automated conversion

Html2Pdf.app’s API accepts a publicly reachable URL or raw HTML in an authenticated POST request to https://api.html2pdf.app/v1/generate. A synchronous request returns PDF binary data. Keep the API key on a backend or another trusted server-side environment. Do not place it in browser JavaScript, a public repository, or a client app distributed to users.

The examples below demonstrate the request shape. Set your API key using a private environment variable and replace the example URL with the page you are authorized to convert. Consult the Html2Pdf.app documentation for the current required fields and options.

cURL

curl --fail-with-body --request POST \
  --url 'https://api.html2pdf.app/v1/generate' \
  --header 'Content-Type: application/json' \
  --data '{"apiKey":"YOUR_API_KEY","url":"https://example.gov.in/page"}' \
  --output government-page.pdf

Use this from a trusted shell or server. The sample shows the URL-conversion path; verify the exact authentication field format required by your account and the current API documentation. The API key must remain private.

Python

import os
import requests

api_key = os.environ["HTML2PDF_API_KEY"]
endpoint = "https://api.html2pdf.app/v1/generate"
payload = {
    "apiKey": api_key,
    "url": "https://example.gov.in/page",
}

response = requests.post(endpoint, json=payload, timeout=90)
response.raise_for_status()

content_type = response.headers.get("Content-Type", "")
if "pdf" not in content_type.lower():
    raise RuntimeError(f"Expected a PDF response, got {content_type!r}")

with open("government-page.pdf", "wb") as pdf_file:
    pdf_file.write(response.content)

Install the dependency with python -m pip install requests. Set HTML2PDF_API_KEY in the server environment before running the script. Check the HTTP status before saving the body as a PDF: error responses are not PDF files.

Node.js

const endpoint = 'https://api.html2pdf.app/v1/generate';
const apiKey = process.env.HTML2PDF_API_KEY;
if (!apiKey) throw new Error('Set HTML2PDF_API_KEY in the server environment');

const response = await fetch(endpoint, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    apiKey,
    url: 'https://example.gov.in/page'
  })
});

if (!response.ok) {
  const detail = await response.text();
  throw new Error(`PDF conversion failed (${response.status}): ${detail}`);
}

const contentType = response.headers.get('content-type') || '';
if (!contentType.toLowerCase().includes('pdf')) {
  throw new Error(`Expected a PDF response, got ${contentType}`);
}

const pdf = Buffer.from(await response.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('government-page.pdf', pdf));

Run this in a server-side Node.js environment with a version that provides built-in fetch. Keep the key out of frontend bundles and source control.

API options that affect the PDF

The documentation describes these layout and rendering controls. Defaults are suitable only when they match the page and the intended use; check the current API reference for accepted field names and value formats.

Option What it controls When to adjust it
Page format Paper size; A4 is the documented default. Use a different supported format when the source layout or destination requires it.
Orientation Portrait or landscape page orientation. Try landscape for wide tables, then inspect legibility and page breaks.
Custom dimensions Explicit page width and height. Use when standard paper sizes do not fit the intended output.
Margins Space between rendered content and page edges. Increase margins if content is clipped; reduce them carefully if the content is too fragmented.
CSS media Whether print or screen CSS rules are used. Try the other mode if the page’s print stylesheet hides or rearranges content unexpectedly.
Scale Rendered content size on the page. Adjust for content that is too large or too small, then check text remains readable.
Header and footer templates Optional repeated page header and footer content. Use for document context or page furniture, and ensure it does not overlap the body.
Filename Name for the generated document. Set a descriptive name for automated filing.
waitFor Wait time from 0 to 10 seconds for JavaScript or asynchronous resources. Increase it when a page populates content shortly after initial load. This documented API option is not confirmation that the browser converter exposes the same control.

The rendering engine uses headless Chromium and supports modern HTML, CSS, and JavaScript, according to the vendor. That does not guarantee pixel-perfect reproduction. CSS media selection, available fonts and external resources, and JavaScript timing can all change the output.

Common problems and fixes

Symptom or status Likely cause What to do
The page cannot be converted; API returns 400. The source URL is inaccessible to the converter, or a parameter is invalid. Open the URL without a login, check for typos and redirects, and validate the request fields. Correct the problem before retrying.
API returns 401. The API key is missing or invalid. Check the key and the documented authentication format. Keep the key in a trusted server environment.
API returns 403. The account has reached a plan limit. Review account usage and plan limits before making another request.
API returns 500. A server-side error occurred. Retry cautiously after a short delay; if it continues, consult the provider’s support or status information. Avoid an unbounded retry loop.
PDF is blank or missing dynamic sections. JavaScript or asynchronous content had not finished loading, or the content was unavailable to the renderer. Confirm the page displays the section in a normal browser. For API calls, try a documented waitFor value up to 10 seconds, then inspect again.
Fonts, images, or styles are missing. External resources may not have loaded or may be inaccessible during conversion. Check that resources are publicly reachable and retry. Compare print and screen media settings where the API allows it.
Text or tables are clipped or awkwardly split. Page size, orientation, scale, margins, or print styles do not suit the source. Try landscape for wide content, adjust scale and margins, or use the other CSS media mode; review each page afterward.
A login page or access-denied page appears in the PDF. The converter received only the publicly accessible response and has no promised access to your browser session. Use a public page if available. Do not assume URL conversion supports authenticated sessions.
The output file is corrupt or contains an error message. An error response may have been saved as though it were PDF binary data. Check HTTP status and content type before writing the body to a PDF file.

The API documentation advises against retrying 400, 401, or 403 responses without fixing the underlying issue. Repeatedly sending the same invalid request will not resolve it.

Privacy, reliability, and cost considerations

For API handling, Html2Pdf.app says generated PDFs are processed temporarily and are not permanently stored on its servers. It also says raw HTML or text submitted in the html parameter is not stored in conversion logs, while selected request metadata and a source URL supplied in html may be retained in those logs. These are vendor statements, not an independent audit. Review its documentation, Privacy Policy, and Data Processing Agreement for details before submitting sensitive material.

Conversion reliability depends partly on the source: availability, access controls, page scripts, fonts, and external resources can affect the output. Save and inspect the result rather than assuming a successful request means the PDF is complete. The research available for this guide does not establish API pricing, so check the provider’s current offering before designing a high-volume workflow.

For automation, check every response status, avoid treating arbitrary response bodies as PDFs, and make retries conditional on the error. Store generated files and source URLs according to your own retention needs.

Or skip the browser setup

If your goal is to capture a page as an image rather than create a PDF, ScreenshotNeo is a website screenshot API and MCP server. Its one-request API returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.

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

Cookie banners, popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed, and the response identifies the page verdict and billing status. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.

FAQ

Can I convert a government page without an API key?

Yes. Html2Pdf.app advertises its browser converter for public webpage URLs without an API key. API calls are a separate, authenticated workflow.

Will the PDF be an official government document?

No. It is a saved rendering of a webpage. Keep and verify the original government URL when authenticity matters.

Can I convert a page behind a login?

The documented URL workflow requires a public, reachable page and does not promise support for login sessions. A page that requires authentication may fail or render an access screen.

What should I do if the PDF looks different from the webpage?

Inspect CSS media, fonts and resources, JavaScript timing, page size, orientation, scale, and margins. The rendered file should be reviewed before sharing or relying on it.