Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a government page that depends on JavaScript or modern browser layout, use PHP to control headless Chrome or Chromium and print the rendered page to PDF. For static HTML with simple styles, Dompdf may be enough, but its documented CSS support is narrower. In either case, test the specific portal, set A4 output deliberately, and check the PDF—especially Indic text, wide tables, and page breaks—before relying on it.

Choose a renderer for the page you need to capture

Indian government sites vary across central, state, district, and local services. A workflow that works on one portal does not establish that it will work on another. First determine whether the page is static HTML or whether it needs JavaScript, interactive rendering, or current browser layout behavior.

Target page Starting approach Trade-off
Server-rendered HTML with simple styles; no JavaScript execution needed Dompdf PHP-native and supports much of CSS 2.1, but does not support flexbox or grid.
JavaScript, interactive rendering, or modern browser layout required PHP-controlled Chrome/Chromium with chrome-php/chrome Uses a real browser rendering engine; requires a compatible Chrome/Chromium installation and browser process.
Login, CAPTCHA, consent prompt, or other access restriction Check the target portal’s rules and permitted access first Policies and access flows are portal-specific; there is no universal automation permission.

Compare options on JavaScript execution, CSS fidelity, runtime and deployment requirements, paper and margin controls, asset loading, font coverage, and security. The cited project documentation lists PHP 7.4–8.5 and Chrome/Chromium 65 or newer for chrome-php/chrome; check the release you install because compatibility requirements can change. Dompdf’s project documentation should likewise be checked for the version you deploy.

Capture a rendered page with PHP and headless Chrome

The chrome-php/chrome documentation describes opening pages in Chrome/Chromium, waiting for navigation, creating a PDF, and saving it. Install the library with Composer and ensure Chrome or Chromium is available to the PHP process. The following example navigates to a page, waits for navigation, requests an A4 PDF, and writes it to disk:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
require __DIR__ . '/vendor/autoload.php';

use HeadlessChromiumBrowserFactory;

$url = 'https://example.gov.in/';
$outputPath = __DIR__ . '/portal-page.pdf';

$browserFactory = new BrowserFactory();
$browser = $browserFactory->createBrowser();

try {
    $page = $browser->createPage();
    $navigation = $page->navigate($url);
    $navigation->waitForNavigation();

    // If the portal renders important content after navigation, wait for its
    // selector using the wait API supported by your installed library release.
    // Replace this comment with the portal-specific selector and check it exists.

    $page->pdf([
        'paperWidth' => 8.27,  // A4 width in inches
        'paperHeight' => 11.7, // A4 height in inches
        'marginTop' => 0.4,
        'marginBottom' => 0.4,
        'marginLeft' => 0.4,
        'marginRight' => 0.4,
        'printBackground' => true,
        'landscape' => false,
    ])->saveToFile($outputPath);
} finally {
    $browser->close();
}

Use an actual portal URL and adapt the wait to the page’s meaningful content. Navigation completion alone may not mean a delayed table, chart, or language-specific content has appeared. The library’s navigation documentation does not establish the loading behavior of any particular portal. The exact PDF option names and supported wait methods can vary by installed release, so confirm them in the project’s documentation before deployment.

Set paper and layout intentionally

  • Use A4 dimensions and explicit margins rather than relying on defaults. GIGW’s print checkpoint says page content should print correctly on A4 paper: GIGW Guidelines.
  • For wide tables, test landscape as well as portrait. Orientation controls are available, but no single setting is established for all portals.
  • Decide whether background colors and images should print, and review headers, footers, links, images, and page breaks in the resulting PDF.
  • Inspect every page for clipped columns or missing content instead of assuming the browser’s on-screen view will paginate correctly.

Wait for the content, not an arbitrary delay

If a portal populates results after navigation, wait for the selector or condition that indicates the specific content is present. A fixed sleep may be too short on a slow response and unnecessarily long on a fast one. Verify delayed tables, charts, or translated text in the saved PDF.

Use Dompdf for static, simpler HTML

Dompdf accepts HTML, lets PHP set the paper size, and can render and stream output. Its project documentation describes support for much of CSS 2.1, but not flexbox or grid. That makes it a plausible choice for static pages whose layout fits its supported CSS, not a general substitute for a browser when the portal relies on client-side rendering.

<?php
require __DIR__ . '/vendor/autoload.php';

use DompdfDompdf;
use DompdfOptions;

$url = 'https://example.gov.in/';
$html = file_get_contents($url);
if ($html === false) {
    throw new RuntimeException('Could not fetch the page HTML.');
}

$options = new Options();
// Configure only the resources and filesystem paths this page requires.
$options->set('isRemoteEnabled', true);

$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('portal-page.pdf', ['Attachment' => true]);

This example fetches HTML and does not execute the page’s JavaScript; it is unsuitable if the content only appears after browser-side code runs. It also enables remote resources only as an explicit example setting: do not turn on broad fetching without understanding what the renderer can access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Restrict resources and verify fonts

Dompdf documents that remote loading must be enabled for web resources and requires cURL or allow_url_fopen. Local files must remain inside its configured chroot paths. Configure resource access narrowly; a renderer that can fetch arbitrary URLs or read overly broad local paths creates both security and rendering concerns. Dompdf also notes that its built-in fonts do not cover every character: characters outside Windows ANSI encoding coverage need an external font. Test all Hindi and other Indic-script text used by the actual page and make sure the font is available to the renderer. See the Dompdf documentation.

Check the PDF against government guidance and the source page

GIGW Scope and Objective applies to Indian government websites and applications at central, state, and district or local levels; its guidance spans consistency, content presentation, security, usability, user-centricity, and accessibility. The GIGW introduction describes guidance across the lifecycle of government websites, portals, applications, and apps.

A generated PDF is a derivative record, not proof that the portal’s information is authentic or that the PDF is an official document. Preserve the page URL and capture date in your own recordkeeping when relevant, and retain the official page or downloadable source. GIGW recommends HTML or other accessible formats for documents and accessible versions of scanned documents; its accessibility guidance calls for OCR text in scanned PDFs. A screenshot-derived PDF does not itself establish accessibility. See GIGW Guidelines and GIGW Accessibility Guidelines.

Before using the capture in a workflow

  • Compare the PDF with the rendered browser page for missing sections, images, links, table columns, and dynamic results.
  • Check A4 pagination and confirm portrait or landscape is appropriate.
  • Check that Hindi and any other Indic-language text renders correctly rather than as boxes or missing glyphs.
  • Check whether the PDF contains selectable text. For a scan, OCR may be needed for actual text access.
  • Keep the original accessible HTML or official downloadable file available when possible.

Respect portal-specific access rules

Before automating a capture, check the actual portal’s terms, authentication flow, CAPTCHA, consent prompts, and any restrictions on automated access. A cited policy for the National Government Services Portal says pages on that portal must load into a newly opened browser window. That rule is specific to NGSP and is not a general rule for every Indian government website. Do not treat a successful capture as permission to automate access.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common PDF capture failures

Symptom Likely cause What to do
PDF is blank or missing the main content The page relies on JavaScript or content loads after the navigation event. Use browser rendering rather than fetching raw HTML; wait for the selector that marks the needed content as present, then inspect the saved file.
Layout differs substantially from the portal Dompdf does not support the page’s CSS layout, or browser print pagination differs from screen layout. For flexbox, grid, or interactive pages, try headless Chrome/Chromium. Adjust paper orientation and margins, then inspect page breaks.
Images or logos are absent Remote resources are blocked, inaccessible, or not yet loaded; a local path may also be outside Dompdf’s configured chroot. Check resource URLs and access configuration, ensure required assets load before rendering, and avoid opening unrestricted local or remote access.
Hindi or other Indic characters are missing or replaced The renderer’s available fonts do not cover the script. Provide an appropriate external font to Dompdf or verify browser font availability, then regenerate and inspect all relevant text.
Table columns are cut off The table is wider than the printable page area. Try landscape, adjust margins or page styling, and confirm all columns and values remain present.
Capture stops at a login or CAPTCHA The page requires a permitted user access flow or restricts automation. Follow the portal’s policy and authentication requirements. Do not attempt to bypass access controls.
PHP cannot start the browser or create the PDF Chrome/Chromium is unavailable to the PHP process, or installed runtime versions do not meet the library release’s requirements. Check the PHP and browser versions, executable availability, and the installed library’s documentation; reproduce with a permitted test page.

Or skip the browser setup

If your goal is a clean page capture rather than running Chrome from your PHP server, ScreenshotNeo provides a website screenshot API that can return PNG, JPEG, WebP, or PDF. Its one-GET-request API is:

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

See the ScreenshotNeo API documentation for request options and response details. It accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Portal access rules still apply. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does saving a government webpage as PDF make it an official government document?

No. A captured PDF is a derivative copy and does not establish authenticity or official status.

Can I use PHP to capture a portal that requires a CAPTCHA?

Only follow the portal’s permitted access flow and policy; do not bypass access controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.