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
World desk7 min

How to Convert HTML to PNG or PDF with an API

Render HTML in a browser, then capture a PNG or generate a PDF. Compare local Playwright automation with hosted conversion APIs and see the settings that shape the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert HTML to PNG, render it in a browser and capture a screenshot; to convert HTML to PDF, generate a PDF from the rendered page. You can run the browser yourself with Playwright or send HTML to a hosted conversion API. The right choice depends on how much control you need, where your content can be processed, and whether you want to operate browser software.

Choose a rendering path

HTML has to be rendered before it becomes an image or PDF. A browser resolves CSS, fonts, images, and JavaScript; the conversion step then captures the rendered page as pixels or lays it out for printing.

As an Amazon Associate I earn from qualifying purchases.

  • Run Playwright yourself: your application controls the browser and receives the output as a buffer. This suits workflows that need direct control over page loading and rendering.
  • Use a hosted conversion API: send HTML in an HTTP request and receive the converted output. This avoids operating browser processes in your application, but places the conversion with the provider.

The documentation cited here describes capabilities, not comparative latency, quality, cost, or reliability. Choose based on integration, rendering controls, and data-handling requirements rather than assumed performance.

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

Convert HTML locally with Playwright

Playwright’s page.screenshot() and page.pdf() are separate operations. Screenshot output is a buffer and defaults to PNG; PDF output is also returned as a buffer. See the Playwright Page API and its screenshots guide for current language-specific signatures and options.

#1 Best Overall
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
  • Convert your PDF files into Word, Excel & Co. the easy way
  • Convert scanned documents thanks to our new 2022 OCR technology
  • Adjustable conversion settings
  • No subscription! Lifetime license!
  • Compatible with Windows 11, 10, 8.1, 7 - Internet connection required

Render supplied HTML and save a PNG

This Node.js example loads an HTML string into a page, waits for the document load event, captures a full-page PNG, and writes the returned bytes to disk. It assumes Playwright and its browser have already been installed in your project.

const { chromium } = require('playwright');
const fs = require('node:fs/promises');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
    const html = `<!doctype html>
      <html><head><meta charset="utf-8">
      <style>body{font:16px Arial,sans-serif;padding:32px}</style>
      </head><body><h1>Hello from HTML</h1><p>Rendered in a browser.</p></body></html>`;

    await page.setContent(html, { waitUntil: 'load' });
    const png = await page.screenshot({ fullPage: true, type: 'png' });
    await fs.writeFile('page.png', png);
  } finally {
    await browser.close();
  }
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

To capture a website rather than an HTML string, navigate to it with await page.goto('https://example.com', { waitUntil: 'load' }) before calling page.screenshot(). For JavaScript-heavy pages, choose a readiness condition appropriate to that site; the load event alone does not guarantee that every dynamic element has finished rendering.

Render supplied HTML and save a PDF

Use page.pdf() for a PDF buffer. By default, Playwright applies print CSS media, so print-specific styles can change the appearance from the browser’s screen view.

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.
Rank #2
DeskFX Free Audio Effects & Audio Enhancer Software [PC Download]
  • Transform audio playing via your speakers and headphones
  • Improve sound quality by adjusting it with effects
  • Take control over the sound playing through audio hardware
const { chromium } = require('playwright');
const fs = require('node:fs/promises');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    const html = `<!doctype html>
      <html><head><meta charset="utf-8">
      <style>body{font:16px Arial,sans-serif;margin:32px}</style>
      </head><body><h1>PDF from HTML</h1><p>Print-ready content.</p></body></html>`;

    await page.setContent(html, { waitUntil: 'load' });
    const pdf = await page.pdf({ format: 'A4', printBackground: true });
    await fs.writeFile('page.pdf', pdf);
  } finally {
    await browser.close();
  }
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

If you want the PDF to use screen rather than print media, call await page.emulateMedia({ media: 'screen' }) before page.pdf(). Consult the Page API for the current PDF settings, including page dimensions and print-related options.

Settings that change the output

  • Screenshot format: PNG is the default; the documented formats also include JPEG and WebP. Choose the format your downstream system needs.
  • Capture area: a normal screenshot captures the viewport. Set fullPage: true to capture the full scrollable page.
  • Scale and transparency: screenshot options include CSS-pixel or device-pixel scaling and a transparent background. These affect image dimensions and appearance.
  • PDF page setup: select page dimensions and relevant print settings for the document you need. PDF generation uses print media unless you switch to screen media.
  • Readiness: ensure fonts, images, and dynamic content have loaded before capture. A page that has technically loaded may still be visually incomplete.

Convert HTML with a hosted API

A hosted service moves browser operation behind an HTTP request: your application submits HTML and receives a rendered file or response. The html2png.dev API reference documents a raw-HTML POST to https://html2png.dev/api/convert and lists PNG, JPEG, WebP, and PDF output. Its documented controls include viewport dimensions, device scale factor, delay, zoom, transparent background, and selector. These are provider-documented features, not independently tested behavior.

Before putting a provider into production, verify its current request format, limits, response behavior, and security and data-handling terms. In particular, establish whether your HTML, embedded data, and rendered output may be sent to a third party.

Rank #3
Data Recovery Stick for Windows Data Recovery Software – Photos, Files
  • The Data Recovery Stick requires no technical skills — simply plug it into your Windows computer, click Start, and the software automatically begins scanning and recovering lost files within minutes. Compatible with Windows Vista, 7, 8, 10, & 11, it's designed to be a reliable first step when accidental deletion occurs.
  • Recover photos (JPG, BMP, PNG, TIFF), Microsoft Office documents (Word, Excel, PowerPoint, Publisher, Access), Open Office files, MP3 music files, PDFs, RTF documents, AutoCAD files, and HTML web pages. Whether it's personal memories or critical business files, the Data Recovery Stick covers the file types that matter most.
  • Works with hard drives, USB drives, SD cards, memory sticks, and other common storage formats that use FAT or NTFS file systems — making it a single solution for hard drive recovery, USB drive recovery, SD card recovery, and more. Note: a media reader is required for micro SD cards and some mass storage devices.
  • No Installation Required - The Data Recovery Stick runs entirely from the USB drive with no software installation on your computer — helping prevent new data from overwriting the files you're trying to recover. This also makes it ideal for use across multiple computers or in emergency situations where installation isn't practical.
  • Use the Data Recovery Stick on as many computers as often as needed — simply clear the recovered data between uses to free up storage space. Software updates keep the tool compatible with newer systems and devices, backed by 25+ years of data software expertise from Paraben Consumer Software.

ScreenshotNeo: one-call conversion

ScreenshotNeo accepts HTML/CSS to image and can return PNG, JPEG, WebP, or PDF. It is a hosted option when you want to make a request instead of managing browser setup. The API uses a URL parameter; for HTML/CSS input, consult the ScreenshotNeo API documentation for the supported request parameters.

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

Here is the documented cURL request for capturing a page URL:

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

Equivalent Python and Node.js request examples:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; those cleanup 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 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. Sign up for ScreenshotNeo’s free plan.

Choose based on control, output, and data handling

Decision Playwright in your environment Hosted conversion API
Who operates the browser? Your application environment runs browser automation. The provider operates the conversion service.
Input HTML you load into a page, or a page you navigate to. Depends on the provider’s documented request; html2png.dev documents raw HTML in a POST body.
Output handling Playwright returns screenshot or PDF bytes for your code to save or process. Follow the provider’s response format and handling instructions.
Rendering controls Page API controls include capture area, scale, transparency, and PDF print settings. Controls vary by provider; html2png.dev documents viewport, device scale factor, delay, zoom, transparency, and selector.
Data location Rendering runs in the environment you configure. HTML is sent to the provider; review its current security and data-handling terms.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot incomplete or unexpected output

Images, fonts, or dynamic content are missing

The capture may run before external assets or client-side rendering finish. Wait for a relevant selector or a site-specific readiness condition rather than assuming the initial load event means the page is visually complete. Check that the content can be loaded from the browser environment and that external resources are accessible.

Rank #4
Convert to PDF
  • Export or Convert Text, HTML, PNG, JPG, or Camera Pictures to PDFs
  • Unlimited use
  • No ads
  • No personal data taken
  • GDPR compliant

The screenshot cuts off the page

A viewport capture covers only the visible area. For Playwright, use fullPage: true when you need the complete scrollable document. A hosted endpoint may have a selector or viewport setting; check its current documentation for whether it supports the capture area you need.

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

The PDF looks different from the browser

PDF generation uses print CSS by default in Playwright. Review print styles and page layout settings. If the intended result is the screen design, emulate screen media before generating the PDF.

The result has the wrong dimensions or background

For screenshots, check the viewport, full-page setting, scale option, and transparency setting. Hosted services may use their own defaults; for html2png.dev, the reference documents a default viewport of 1200 by 630 and a device scale factor range of 1–4. Those values are specific to that provider’s documentation.

Best Value
MixPad Multitrack Recording Software for Sound Mixing and Music Production Free [Mac Download]
  • Mix an audio, music and voice tracks
  • Record single or multiple tracks simultaneously
  • Intuitive tools to split, trim, join, and many other editing features
  • Loaded with audio effects including EQ, compression, reverb, and more.
  • Load an audio file and export to all popular audio formats from studio quality wav to high compression formats

A hosted request fails or returns an unexpected response

Confirm the endpoint, request method, body format, output format, and authentication requirements against the provider’s current API reference. The html2png.dev documentation cited here does not establish service limits, privacy terms, or operational reliability, so confirm those directly before relying on it in production.

Performance, reliability, and cost considerations

With Playwright, your application is responsible for running the browser and managing its lifecycle; this offers direct control but adds browser operations to your deployment. A hosted API replaces that work with a network dependency and sends the request to a provider. The cited documentation does not provide a measured speed, fidelity, reliability, or price comparison between the approaches.

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

For production use, test representative HTML—including remote fonts, large images, long pages, and dynamic components—in the actual deployment environment. Decide how your application should handle timeouts, failed requests, and retries, and avoid retrying blindly when the request may already have produced a result. For a hosted service, evaluate provider limits and data terms; for a local browser, account for browser installation and process management.

Frequently Asked Questions

Can one HTML conversion request return both a PNG and a PDF?

The documented interfaces use separate output operations or a selected output format. Generate the image and PDF as separate outputs unless the API you use explicitly supports multiple files in one response.

Does converting HTML mean converting a file without rendering it?

No. The HTML must be laid out by a browser engine before it can be captured as image pixels or paginated as a PDF.

Quick Recap

Bestseller No. 1
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
Convert your PDF files into Word, Excel & Co. the easy way; Convert scanned documents thanks to our new 2022 OCR technology
Bestseller No. 2
DeskFX Free Audio Effects & Audio Enhancer Software [PC Download]
DeskFX Free Audio Effects & Audio Enhancer Software [PC Download]
Transform audio playing via your speakers and headphones; Improve sound quality by adjusting it with effects
Bestseller No. 4
Convert to PDF
Convert to PDF
Export or Convert Text, HTML, PNG, JPG, or Camera Pictures to PDFs; Unlimited use; No ads; No personal data taken
$4.99
Bestseller No. 5
MixPad Multitrack Recording Software for Sound Mixing and Music Production Free [Mac Download]
MixPad Multitrack Recording Software for Sound Mixing and Music Production Free [Mac Download]
Mix an audio, music and voice tracks; Record single or multiple tracks simultaneously; Intuitive tools to split, trim, join, and many other editing features

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.

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

Leave a Reply

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

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.