ScreenshotNeo

BlogHTML to image & PDF

Create a PDF from an Indian School Admission Webpage with Playwright

Use Playwright to save an admission webpage as an A4 PDF, wait for the right content, choose print settings, and check the result.

By the ScreenshotNeo team4 October 20269 min read

Use Playwright’s page.pdf() to save an Indian school admission webpage as a PDF. Navigate to the precise form or application page, wait for the content you need to appear, then set the paper size and print options. Playwright uses print CSS by default. Before automating, check whether the school portal already offers a Print, reprint, or PDF download control: the available process differs by portal.

The examples below use Node.js and Chromium. They are based on Playwright’s documented API; no PDF was generated against a named school page. Replace the example URL with a page you are permitted to access, then inspect the resulting PDF before relying on it.

1. Check the admission portal’s own print option

A portal may have a purpose-built print or download workflow, sometimes tied to an Application ID or login. For example, Pragati School Satana’s 2026–27 admission page says applicants who already have an Application ID can use its Print control. The Delhi government admission page lists online forms and reprint links for certain categories. A separate SamarthX portal overview describes PDF download or printing after submission. These are examples of different portal flows, not a guarantee that every school provides them.

Use the portal’s own print or PDF function when it gives you the intended application copy. Use Playwright when you need repeatable rendering, a batch workflow, or a saved copy of a page without a suitable native export.

2. Install Playwright and Chromium

Create a small Node.js project and install Playwright. The browser install command downloads the Chromium browser used by the script.

mkdir admission-pdf
cd admission-pdf
npm init -y
npm install playwright
npx playwright install chromium

Save the following as save-admission.js. Change ADMISSION_URL to the exact page you need. The visible-content selector is deliberately configurable because every portal has different markup.

const { chromium } = require('playwright');

const ADMISSION_URL = 'https://example-school.in/admission';
// Replace this with a selector that appears when the required form is ready.
const READY_SELECTOR = 'form';

(async () => {
  const browser = await chromium.launch({ headless: true });
  try {
    const page = await browser.newPage();
    const response = await page.goto(ADMISSION_URL, {
      waitUntil: 'load',
      timeout: 60_000,
    });

    if (!response) {
      throw new Error('Navigation returned no main-document response.');
    }
    if (!response.ok()) {
      throw new Error(`Admission page returned HTTP ${response.status()}`);
    }

    // Wait for the actual form or content needed in the PDF.
    await page.locator(READY_SELECTOR).waitFor({
      state: 'visible',
      timeout: 30_000,
    });

    await page.pdf({
      path: 'admission-page.pdf',
      format: 'A4',
      printBackground: true,
      margin: {
        top: '12mm',
        right: '12mm',
        bottom: '12mm',
        left: '12mm',
      },
      preferCSSPageSize: false,
    });

    console.log('Saved admission-page.pdf');
  } finally {
    await browser.close();
  }
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run it with node save-admission.js. The script checks the main response and waits for a visible form before printing. Replace form with a portal-specific selector if the relevant content is not inside a form, for example a result panel or an application summary. Choose a selector that signals the content is complete enough to print, not merely that the page shell has loaded.

3. Choose readiness and print behavior

Wait for the content, not an arbitrary delay

page.goto() supports load, domcontentloaded, networkidle, and commit navigation wait conditions. The default is load. Admission forms may populate after navigation through client-side requests, so a navigation event alone may not mean the data you need is visible. Wait for a locator that represents the required form, confirmation, or application details.

Playwright documents networkidle as discouraged for testing. It can be a poor readiness signal for pages with analytics, polling, or other ongoing requests. A fixed waitForTimeout() may hide a race on one run and fail on another. Prefer a visible, page-specific readiness locator. Playwright auto-waits for many actions, and waitForLoadState() is often unnecessary if navigation already reached that state.

page.pdf() renders with print CSS media by default. This is usually appropriate for a printable application. If the portal’s screen layout is the intended output, switch media before generating the PDF:

await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'admission-page.pdf', format: 'A4' });

Print styles can hide navigation, change field widths, or introduce page breaks. If the result differs from the browser view, inspect the page’s print stylesheet and decide whether print or screen media matches the document you need.

4. Select paper size, margins, and backgrounds

Option What it controls Practical choice
format Named paper size; supported examples include A4, A3, A5, Letter, and Legal. Use A4 for a typical school form unless the portal’s own print layout specifies otherwise.
width and height Explicit paper dimensions. Units may be px, in, cm, or mm; unlabeled numbers are pixels. Use these instead of format when you need a nonstandard sheet size.
margin Top, right, bottom, and left page margins. Increase margins if text or fields sit close to the edge; reduce only after checking legibility.
printBackground Whether background graphics are printed. Defaults to false. Set true if colored sections, shaded fields, or backgrounds carry meaning.
preferCSSPageSize Whether CSS @page dimensions take priority over the configured paper size. Set true when the site’s declared page size is intentional. When false, content is scaled to fit the selected paper.
scale Scales rendered content; documented range is 0.1 to 2, default 1. Use sparingly to address fit. Very small text can make an application unreadable.
pageRanges Selects pages, such as 1-3, 5. Use only after checking page numbering in the generated document.
displayHeaderFooter Adds print header and footer templates. Optional. Templates can use title, URL, and date classes; scripts and page styles do not run inside them.
tagged and outline Optional tagged PDF output and document outline. Enable when those document features are useful in your workflow; defaults are false.

Playwright modifies printed colors by default. Background printing is separately off by default, so colored form sections may disappear unless you enable printBackground. The page’s CSS can use -webkit-print-color-adjust to request exact colors, but inspect the PDF because the site’s styles and browser rendering affect the result.

5. Handle forms, login, and private application data

  • Public information page: Navigate directly to the public admissions page and print its information or blank form.
  • Application that requires an ID: Use the portal’s official print or reprint workflow where available. Do not guess an ID or automate around access controls.
  • Logged-in application: Authenticate through an appropriate session and follow the portal’s permitted workflow. Keep credentials and session state out of source control and logs. Never publish a student’s personal information or session files.
  • Form not yet submitted: A browser printout may show blank fields or only the current page state. It is not proof that an application was submitted. Use the portal’s confirmation or reprint function for an official submitted copy.
  • Multi-step form: Navigate to the step that contains the information to preserve, wait for its identifying content, and print that state. A PDF of the first step will not include later steps automatically.

6. Inspect the PDF before using or sharing it

Open the generated file and check each page at normal reading size. Specifically look for clipped labels or fields, missing backgrounds or logos, unexpected page breaks, content omitted by print CSS, and blank output caused by incomplete loading. Check that the expected number of pages and the correct application state are present. If the PDF contains student or family details, treat it as private and review the file before sharing it.

When layout problems occur, adjust one variable at a time: paper size, margins, print versus screen media, background printing, then scale. A narrower margin or smaller scale can fit more content, but may also make the form difficult to read.

7. Troubleshooting

Symptom Likely cause Fix
The PDF is blank or missing the form. The page shell loaded before the form, or the selector does not match the page. Inspect the page markup and wait for a visible element unique to the needed form or result.
The script reports a navigation timeout. The server is slow, the network is unavailable, or a page resource prevents the chosen load condition. Check the URL and network access. Consider domcontentloaded for navigation, then explicitly wait for the required content. Increase the timeout only when the page legitimately needs longer.
The script completes but the server showed an error page. page.goto() can return an HTTP error response without throwing. Check response.status() and stop on non-success responses, as the example does.
Colors or shaded sections are missing. Background printing is off by default, or print CSS changes colors. Set printBackground: true; inspect the site’s print rules and the resulting PDF.
The layout looks unlike the browser. page.pdf() uses print media and the site may define print-specific CSS. Keep print media for a print-oriented document, or call emulateMedia({ media: 'screen' }) when screen styling is required.
Text is clipped or too small. Paper size, CSS page size, margins, or scale do not suit the form. Try A4 or the site’s declared page size, adjust margins, and avoid shrinking the content below a readable size.
The output contains only an application login or ID prompt. The target requires authentication or a submitted application identifier. Use the portal’s permitted login and official print/reprint process. Do not treat a public landing page as the completed application.
Chromium fails to launch. The browser binary may not be installed in the environment. Run npx playwright install chromium and check that the runtime allows Chromium to launch.

8. Performance, reliability, and cost

A single PDF job needs a browser process, a page navigation, and the time for the admission content and assets to load. For repeated jobs, reuse a browser process and create a separate page or context for each independent task; close pages and the browser when finished. Do not create unbounded parallel browser sessions: each consumes resources, and too much concurrency can overload the host or target portal.

Reliability depends on the portal’s availability, network access, authentication, and page structure. A selector tied to a stable form or heading is generally more robust than a guessed delay, but portal redesigns can still require maintenance. Check the main response, wait for the relevant content, handle errors, and inspect representative output after a site change. Avoid repeatedly submitting forms or triggering application actions just to produce a PDF.

Playwright itself is open-source browser automation software; this workflow has no ScreenshotNeo API charge. Your operating environment still has compute, storage, and network costs, and an unattended browser may need maintenance as dependencies or portal markup change. Keep generated PDFs and authentication material protected according to the sensitivity of the application data.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its API can return screenshots or PDFs; see the ScreenshotNeo API documentation for PDF output and its available paper and margin settings. This request example shows the one-call capture pattern for the same target page; follow the docs for the PDF response option.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example-school.in/admission -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example-school.in/admission"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example-school.in/admission' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Check that you have permission to capture the target page and avoid exposing student information.

Sign up for 1,000 free screenshots a month, with no card required.

FAQ

How do I save a webpage as a PDF with Playwright?

Navigate to the page, wait for the content you need, then call page.pdf({ path: 'page.pdf', format: 'A4' }) in Chromium.

How do I print an online school admission form?

First look for the school’s own Print, reprint, or PDF control. If you need an automated copy, use Playwright on the correct page and verify whether it is a blank form or a submitted application.

Can Playwright print a logged-in application?

It can render the page available in its authenticated browser session. Follow the portal’s permitted authentication flow and protect credentials, session state, and student details.

Why does a PDF look different from the webpage?

PDF generation uses print CSS by default. Print styles, omitted backgrounds, paper dimensions, and margins can all change the result.