October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
A4

How to Convert HTML to a JPG Sized for A4 (With Playwright, Puppeteer, and an API)

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

To convert HTML to an A4-sized JPG, render the document in a browser at an explicit A4 canvas, wait for fonts, images, and JavaScript to finish, then export a JPEG. For portrait A4, use 210 mm × 297 mm (8.27 in × 11.7 in); landscape uses 297 mm × 210 mm. Because A4 describes physical dimensions, you must also choose a pixel density: about 794 × 1123 pixels at 96 ppi, 1240 × 1754 at 150 ppi, or 2480 × 3508 at 300 ppi.

Choose the A4 pixel dimensions first

A4 has a fixed physical ratio, but a JPG has pixels. Calculate the raster size from the target pixels per inch:

pixels = inches × ppi

The A4 specification is 8.27 in × 11.7 in. These common targets follow directly from that size:

Use case Portrait JPG Landscape JPG Density assumption
Screen or web preview 794 × 1123 px 1123 × 794 px 96 ppi
General printing 1240 × 1754 px 1754 × 1240 px 150 ppi
Fine print 2480 × 3508 px 3508 × 2480 px 300 ppi

JPG files do not store a universally enforced physical size. A printer or layout program interprets the pixels using a chosen resolution, so state the intended ppi when handing the file to someone else.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
KODAK Dock Plus 4x6 Photo Printer, Smartphone Docking, 4PASS, 50 Sheets
  • Dock Photo Printer: The KODAK Dock Plus is a home photo printer that produces high-quality 4x6” prints directly from compatible smartphones. Featuring an integrated docking station, users can place their phone on the printer for better connection while simultaneously charging the device during printing.
  • Genuine 4PASS dye sublimation printing: Each photo is produced in three color layers and finished with a clear protective lamination layer. In approximately 55 seconds, you receive a smooth, detailed print designed to resist fingerprints, water, and fading for long-lasting quality.
  • Easy to Use: Print photos quickly without complicated setup or technical steps. Simply power on, connect wireless bluetooth, and start printing within seconds. The Dock Plus is built for straightforward operation, making it ideal for first time users and everyday photo printing.
  • Home Printing Station: Designed for stable desktop use, this dock photo printer connects to a power outlet for consistent performance and larger 4x6” prints. Ideal for home printing, photo albums, framing, family events, and everyday picture printing.
  • KODAK Photo Printer APP: Featuring integrated Bluetooth connectivity, this portable printer connects to compatible iOS and Android devices through the KODAK Photo Printer app. Edit, crop, and customize your photos before printing for creative results.

Build an A4 HTML page

Put all content in a page-sized element. Reset the browser’s default body margin and use box-sizing: border-box so padding and borders stay inside the 210 mm × 297 mm box.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    @page { size: A4 portrait; margin: 0; }
    * { box-sizing: border-box; }
    html, body { margin: 0; padding: 0; }
    body { background: #e9e9e9; font-family: Arial, sans-serif; }
    .page {
      width: 210mm;
      height: 297mm;
      padding: 18mm;
      margin: 0 auto;
      background: white;
      overflow: hidden;
    }
    h1 { margin-top: 0; }
    @media print { body { background: white; } .page { margin: 0; } }
  </style>
</head>
<body>
  <main class="page">
    <h1>Your heading</h1>
    <p>Your HTML content goes here.</p>
  </main>
</body>
</html>

@page controls print layout. The explicit .page dimensions control the element you will rasterize. Keep essential text inside a safe margin; add bleed only when your print workflow specifically requires it.

Convert HTML to JPG with Playwright

Install Playwright and its browser, then save this script as html-to-jpg.mjs. It captures the A4 element rather than the gray area around it.

npm install playwright
npx playwright install chromium
import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage({
  viewport: { width: 794, height: 1123 },
  deviceScaleFactor: 1
});
await page.goto('file:///absolute/path/to/page.html', { waitUntil: 'networkidle' });
await page.evaluate(async () => {
  await document.fonts.ready;
  await Promise.all([...document.images].map(img => img.complete
    ? Promise.resolve()
    : new Promise(resolve => { img.onload = img.onerror = resolve; })));
});
await page.addStyleTag({ content: `*, *::before, *::after { animation: none !important; transition: none !important; }` });
await page.locator('.page').screenshot({
  path: 'a4.jpg',
  type: 'jpeg',
  quality: 92,
  scale: 'css'
});
await browser.close();

Playwright supports JPEG output and a scale option. With scale: 'css', one output pixel represents each CSS pixel. A device scale can produce more pixels on a high-DPI context, so set deviceScaleFactor and scale deliberately. If your CSS A4 box is rendered as roughly 794 × 1123 CSS pixels, the script produces that size at CSS scale.

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.
Rank #2
HP Envy Photo 7975 Wireless Color Inkjet Photo Printer, Print, scan, Copy, Easy Setup, Mobile Printing, Best-for-Home, 3 Month Instant Ink Trial Included, AI-Enabled (B63K3A)
  • From America's most trusted printer brand, the HP Envy Photo 7975 is a premium multi-purpose home printer with everything families need to learn, work, and create. Loaded with features to print high-quality photos, homework, office docs and everything else. It's also AI-enabled to intuitively adapt to your workflow, with wireless and security features that keep your multifunction printer up to date and secure.
  • PERFECT FOR HOME - The HP Envy Photo 7975 is great for printing documents, high-quality true-to-screen borderless photos, creative projects and more. Print speeds up to 10 pages per minute color, 15 pages per minute black.
  • PERFECTLY FORMATTED PRINTS WITH HP AI - Print web pages and emails with precision-no wasted pages or awkward layouts; HP AI easily removes unwanted content, so your prints are just the way you want.
  • KEY FEATURES - Print, copy, scan, automatic 2-sided printing, advanced photo features, separate photo tray, auto document feeder, mobile and wireless printing.
  • EFFORTLESS PRINTING - Smoothly navigate printing with a large intuitive printer color touchscreen.

Capture at 150 or 300 ppi

For a 150-ppi or 300-ppi file, use a larger viewport while preserving the page’s physical proportions. A practical approach is to define the page in CSS pixels at the target dimensions and express internal spacing proportionally, or capture at a device scale that multiplies the 96-ppi baseline. Always inspect the resulting file’s actual dimensions; do not infer them from the CSS alone.

When the HTML is a string

Use page.setContent() instead of a file URL, and provide a base URL if relative images, stylesheets, or fonts must resolve.

await page.setContent(htmlString, { waitUntil: 'networkidle' });
await page.locator('.page').screenshot({ path: 'a4.jpg', type: 'jpeg', quality: 92, scale: 'css' });

Convert HTML to JPG with Puppeteer

Puppeteer offers the same browser-rendering model: inject HTML, set a deterministic viewport, wait for assets, and call page.screenshot().

npm install puppeteer
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 794, height: 1123, deviceScaleFactor: 1 });
await page.goto('file:///absolute/path/to/page.html', { waitUntil: 'networkidle0' });
await page.evaluate(async () => {
  await document.fonts.ready;
  await Promise.all([...document.images].map(img => img.complete
    ? Promise.resolve()
    : new Promise(resolve => { img.onload = img.onerror = resolve; })));
});
await page.addStyleTag({ content: `*, *::before, *::after { animation: none !important; transition: none !important; }` });
await page.locator('.page').screenshot({ path: 'a4.jpg', type: 'jpeg', quality: 92 });
await browser.close();

Use a page-element screenshot when you need exactly one A4 sheet. A full-page screenshot captures the document’s complete scroll height, which may be longer than A4.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Liene M100 4x6'' Photo Printer, Phone Printer 100 Sheets & 3 Cartridges, Full-Color Photo, Portable Instant Photo Printer for iPhone Android, Thermal Dye Sublimation, Wi-Fi Picture Printer 100 Papers
  • User-Friendly Portable Photo Printer for iPhone, Android & PC - Get beautiful and colourful memories with Liene 4x6 photo printer! After opening the entire package, you can find one cartridge + 20 sheets of photo paper (placed inside the machine packaging), as well as an additional box containing 80 sheets of photo paper (which includes two cartridges + 80 sheets of photo paper). Full package includes smartphone photo printer, Liene 4x6 photo printer papers (100 sheets), 3 colour cartridges, and fully sealed cassette to prevent dust. Minimalist and magnetic design for compact storage.
  • Superior Quality 4x6 Photo Printer - Print photos like no other thanks to the thermal-dye sublimation tech adopted by the picture printer for iphone. The dyes deeply penetrate the paper for vibrant photo printing, and the laminated surface is resistant to water, scratches, fingerprints and fading. Clean the print head promptly if smudges are observed on printed photos during operation. Get Liene photo printers now for yourself and your loved ones, print your happy moments together and keep your love forever!
  • Wi-Fi Photo Printer for Smartphone - The built-in hotspot of the photo printer makes it easy to print pictures from your phone, avoiding outside interference with a fast and stable connection. No other networks required! Simply connect your device to the independent instant photo printer 4x6 hotspot.
  • Multiple Device Compatibility - Liene phone printer provides instant photo printing for up to 5 simultaneous connections. Share with family and friends or print from your different devices. No additional cables or Bluetooth required when printing photos with this picture printer. Note: Ensure the ink cartridge clicks into place before printing.
  • Customize your Printing with the Liene App - Customize your photos with our specialized App! You can add a Square border, insert filters, enhance the contrast and brightness, check printing status, and more. You can even print your ID and Visa photos from home with this photo printer for iphone 4x6 prints.

Handle content longer than one A4 sheet

Do not silently shrink a long document until its text is unreadable. Choose one of these explicit workflows:

  • Create one .page element per sheet and capture each element as a4-01.jpg, a4-02.jpg, and so on.
  • Generate an A4 PDF with print CSS, then rasterize each PDF page to a JPG with a tool that lets you select output resolution.
  • Allow a full-page capture only when a tall image, rather than a print sheet, is the intended result.

Make captures repeatable and legible

  • Fonts: wait for document.fonts.ready; otherwise fallback fonts can change line breaks.
  • Images: wait for every image’s load or error event. Lazy-loaded images may require scrolling or an explicit full-page strategy before capture.
  • JavaScript data: wait for the selector that proves the data is present, not merely for the initial navigation event.
  • Animations: disable transitions and animations so repeated exports match.
  • Viewport: keep width, height, and device scale fixed. Responsive breakpoints can otherwise change the layout.
  • JPEG quality: use a high quality for small type and thin rules, then check the file size. JPEG introduces artifacts; PNG may be better for diagrams, text-heavy graphics, or transparency, but the requested output here is JPG.
  • Colors: a browser screenshot is screen color, not a proof of a printer’s color-management result.

Common failures and fixes

The JPG is the wrong dimensions

Check whether you captured the whole page, an element, or a device-scaled surface. Print the image’s width and height with an image utility and adjust viewport or scale until it matches the selected A4 target.

Content is clipped

Clipping usually means the content exceeds the fixed-height page or an ancestor has overflow: hidden. Either paginate the content, increase the page count, or remove the overflow rule after confirming that a one-sheet output is not required.

Fonts or images are missing

Verify that URLs are reachable from the browser process, relative paths have a correct base URL, and the script waits after navigation. Cross-origin restrictions, authentication, and failed network requests can leave an element visually empty even though the screenshot call succeeds.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Canon PIXMA TS4320 – Wireless Color Inkjet Printer with Print, Copy, Scan
  • Affordable Versatility - A budget-friendly all-in-one printer perfect for both home users and hybrid workers, offering exceptional value
  • Crisp, Vibrant Prints - Experience impressive print quality for both documents and photos, thanks to its 2-cartridge hybrid ink system that delivers sharp text and vivid colors
  • Effortless Setup & Use - Get started quickly with easy setup for your smartphone or computer, so you can print, scan, and copy without delay
  • Reliable Wireless Connectivity - Enjoy stable and consistent connections with dual-band Wi-Fi (2.4GHz or 5GHz), ensuring smooth printing from anywhere in your home or office
  • Scan & Copy Handling - Utilize the device’s integrated scanner for efficient scanning and copying operations

The page changes between runs

Freeze animations, use a fixed viewport, wait for network idle plus the required selector, and provide deterministic test data. Client-side clocks, ads, and personalized responses can still vary unless your page supplies stable inputs.

Text looks soft

Increase the raster dimensions or device scale, use a higher JPEG quality, and avoid resizing the JPG repeatedly. A 96-ppi export is suitable for screen use but gives less detail than a 150- or 300-ppi target at print size.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a one-request website screenshot API and an MCP server for AI agents. It accepts a URL and returns PNG, JPEG, WebP, or PDF. Before capture it can accept consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.

For an A4 workflow, set the target page’s CSS to A4, then request the URL. The service also supports full-page capture, element selectors, custom CSS and JavaScript, waiting for selectors or network idle, device presets and arbitrary viewports, retina scale, PDF paper size and margins, and image resizing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for output and option names. The same request in Python:

Best Value
Sale
Epson Expression Premium XP-7100 Wireless Color All-in-One Inkjet Printer
  • CLEAR AND VIBRANT PRINT QUALITY ― All-in-one inkjet color printer produces sharp text for eye-catching documents and impressive color photos and graphics; Your next print job will be vivid and bright with this photo printer
  • PRINTER FOR HOME USE ― Designed to increase your productivity at home, this wireless color printer features a 30 page auto document feeder (ADF), auto 2-sided print, copy, and scan, multiple media feeds, and print quality you can count on
  • CREATIVITY MADE EASY ― Epson color printer provides creative versatility, allowing you to print photos and documents on specialty paper¹ and DVDs; You can even print bright and crisp borderless photos up to 8 X 10 in
  • SIMPLE FUNCTIONALITY ― Convenient features make printing, scanning, and copying a snap; Use the large, intuitive 4.3 in touchscreen to view, edit and print photos directly from USB or SD card slot²
  • CONVENIENT WIRELESS PRINTER ― Ultimate wireless plus ethernet; Easily print photos and documents directly from your tablet or smartphone³; Includes Wi-Fi direct for network-free printing⁴
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo includes an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots, and every feature is available on every plan. Create a free ScreenshotNeo account.

Cost, performance, and reliability choices

  • Local browser: no per-capture API charge, but you maintain Chromium, fonts, concurrency, memory, and network access.
  • Hosted API: simpler deployment and parallel jobs, with usage limits and network-dependent latency. Cache repeated URLs when the content is unchanged; choose a TTL that matches how often the page updates.
  • Large pages: full-page and high-density captures consume more memory and produce larger files. Capture a selected element or resize after rendering when the final artifact does not require every pixel.
  • Security: treat cookies, authorization headers, custom JavaScript, and private URLs as secrets. Do not expose API keys in client-side page code.

Practical checklist

  1. Choose portrait (210 × 297 mm) or landscape (297 × 210 mm).
  2. Select 96, 150, or 300 ppi and calculate the target pixels.
  3. Set an explicit A4 page element and reset body margins.
  4. Render with Playwright or Puppeteer at a fixed viewport.
  5. Wait for fonts, images, data, and any lazy-loaded content.
  6. Disable motion and capture the page element as JPEG.
  7. Verify the exported width, height, cropping, and text legibility.
  8. Paginate rather than squeezing multi-page content into one image.

Frequently Asked Questions

Can I use a browser’s print dialog instead of automation?

Yes, but print-to-image workflows vary by browser and operating system. Automation gives you a repeatable viewport, wait conditions, and JPEG quality setting.

Should I use 96, 150, or 300 ppi?

Use 96 ppi for screen previews, 150 ppi for ordinary printing, and 300 ppi when fine print detail justifies the larger file.

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

Can an A4 JPG contain multiple pages?

A single JPG is one raster canvas. Export separate A4 images or create an A4 PDF and rasterize each page.

Why does a CSS A4 page not always equal 2480 × 3508 pixels?

Millimeters define physical CSS layout, while output pixels depend on viewport, device scale, and screenshot scale. Set those values explicitly and verify the file.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.