October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
HTML to PNG

How to Convert Pasted HTML to PNG

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

To turn pasted HTML into a PNG that reflects real browser rendering, load the markup into a Playwright page with page.setContent(html), then save a screenshot with page.screenshot({ path: 'output.png', type: 'png' }). Use fullPage: true when the whole document should appear, not just the visible viewport. For an element already displayed in a browser, html2canvas is a quicker in-page option, but it reconstructs an image from the DOM and supported CSS rather than capturing the browser’s pixels.

Choose the right way to render pasted HTML

The key decision is whether you need a browser screenshot or a convenient image of an element in an existing page. Playwright opens a real browser page, renders the supplied markup, and captures the result. This is generally the better fit for complex styles, automation, and server-side jobs. Playwright’s Page API documents both setting page content from an HTML string and taking screenshots.

html2canvas runs in a browser page and builds a canvas representation from the DOM and style information it can access. It can be handy when the content is already on screen and you want to capture a selected element without starting a separate browser automation process. It does not take a screenshot of the browser surface, and some CSS may be missing or rendered differently. The html2canvas documentation describes this distinction.

Question Playwright html2canvas
What does it capture? Pixels rendered by a browser page. A reconstruction from DOM and style information.
Best suited to Pasted HTML, server-side automation, or work where browser rendering matters. An element already rendered in a browser where its CSS is supported.
Where does it run? In a browser automation setup, including Node.js. In a browser; the project FAQ says it is not suitable for Node.js alone because Node does not provide the browser APIs it needs.
What can differ? Results depend on browser version, fonts, resources, viewport, and page state. Unsupported CSS, cross-origin resources, or inaccessible frames can be omitted or differ.

Convert a pasted HTML string with Playwright

This Node.js example passes a literal HTML string to Chromium, sets a predictable viewport, and saves a full-page PNG. It uses inline CSS and content so it can run without an external stylesheet or image server.

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.
#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
  1. Install Node.js if it is not already available on your computer.
  2. Create a project and install Playwright: run npm init -y, then npm install playwright, then npx playwright install chromium.
  3. Save the script below as convert.js.
  4. Run it with node convert.js. The output file will be output.png in the current directory.
const { chromium } = require('playwright');

(async () => {
  const html = `
    <!doctype html>
    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
          * { box-sizing: border-box; }
          body {
            margin: 24px;
            font: 16px/1.5 Arial, sans-serif;
            color: #18202a;
            background: #f4f6f8;
          }
          main {
            max-width: 720px;
            margin: 0 auto;
            padding: 28px;
            background: white;
            border-radius: 12px;
          }
          h1 { margin-top: 0; }
        </style>
      </head>
      <body>
        <main>
          <h1>Hello, PNG</h1>
          <p>This image was rendered from pasted HTML.</p>
        </main>
      </body>
    </html>
  `;

  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({
      viewport: { width: 1200, height: 800 },
      deviceScaleFactor: 1
    });
    await page.setContent(html);
    await page.screenshot({
      path: 'output.png',
      type: 'png',
      fullPage: true
    });
  } finally {
    await browser.close();
  }
})();

Replace the example string with the markup you pasted. Preserve a complete document where practical: include a doctype, character encoding, and the styles the design needs. A fragment such as <h1>Title</h1> can also be passed to setContent, but it has no styling unless you include styles or load them separately.

Viewport, full page, and pixel scale

The viewport sets the browser’s CSS-pixel width and height, which affects line wrapping and responsive layout. A normal screenshot captures the current viewport; fullPage: true captures the full scrollable document. Choose the one that matches the intended image rather than assuming full-page output is always preferable: a very tall document can create a large PNG and use substantial memory.

Playwright supports CSS-pixel and device-pixel screenshot scales. CSS scale yields one output pixel per CSS pixel; device scale follows the device pixel ratio and can create a larger, sharper image. The example explicitly uses device scale factor 1 for predictable dimensions. Increase it when higher pixel density matters, and account for the corresponding increase in output size and memory use.

Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

External styles, images, and dynamic content

If the pasted markup refers to remote stylesheets, fonts, images, or scripts, the page must be able to fetch those resources and they must be ready before capture. A fixed delay is not reliable for every page: a fast page wastes time, while a slow request can still be incomplete. Prefer waiting for a known selector, image, font, or application-ready signal that indicates the specific content is ready. The correct signal depends on what the HTML loads.

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

For static markup with inline styles, page.setContent followed by a screenshot is usually enough. For content that changes after scripts run, wait for the change that matters before taking the screenshot. Do not assume a screenshot operation will wait for an application’s own asynchronous work to finish.

Capture an element with html2canvas

Use this method when the target element is already in a browser document and the library’s supported CSS is sufficient. Install and load html2canvas in that page, then select the element and download the generated canvas as a PNG:

Rank #3
Sale
Epson Workforce ES-400 II High-Speed Color Duplex Desktop Document Scanner
  • FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
  • INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
  • SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
  • EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
  • SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning
const canvas = await html2canvas(document.querySelector('#capture'));
const link = document.createElement('a');
link.download = 'output.png';
link.href = canvas.toDataURL('image/png');
link.click();

The selector must match an existing element; in this example the page needs an element such as <div id="capture">...</div>. The html2canvas examples also show selecting a capture area, cropping with x, y, width, and height, and changing scale for pixel density. These controls affect the reconstructed canvas, not the browser’s underlying screenshot.

Because the result is recreated from DOM and style data, check it against the actual page before relying on it for exact visual matching. If a CSS effect is unsupported, choosing a different scale will not make that effect appear; use a real browser screenshot for greater rendering fidelity.

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

Handle common conversion problems

  • The PNG looks unstyled: Put essential CSS in a <style> element in the supplied HTML, or confirm that linked stylesheets are reachable and loaded before capture. A screenshot can only reflect styles that were available to the page.
  • Images are missing: Check that each URL can be reached from the browser environment and that the image has loaded. With html2canvas, cross-origin images require suitable CORS support or a proxy configured for the task; the library cannot bypass browser security rules. See the html2canvas FAQ.
  • An iframe is blank or absent: html2canvas cannot read cross-origin iframe contents. Same-origin frame support is subject to the project’s documented conditions. If the frame is essential, consider a browser screenshot of the page instead, while remembering that browser security and resource loading still apply.
  • The result cuts off the bottom: In Playwright, set fullPage: true when the whole scrollable document is required. For html2canvas, the FAQ suggests matching windowWidth and windowHeight to the element’s scroll dimensions for some clipping cases.
  • The image is blank or partly drawn: The canvas or image may be too large for the browser or device. Limits vary by platform, so there is no single safe maximum to rely on. Reduce the capture dimensions or divide a very tall page into sections.
  • The PNG is blurry: Increase device-pixel scale in the browser capture or the html2canvas scale where appropriate. Higher density also increases pixel dimensions and memory use; it cannot restore detail absent from the source.
  • The script errors before capture: Check that Playwright is installed in the project and that its Chromium browser is installed with npx playwright install chromium. Confirm the script is run from that project directory and that the HTML string is valid JavaScript template-string content.

The html2canvas project’s documentation describes its output as based on DOM information rather than an actual screenshot. That limitation is the reason to choose Playwright when matching a browser-rendered page matters, not a defect that can be fixed by changing PNG encoding.

Rank #4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your HTML is available at a URL that ScreenshotNeo can reach, its screenshot API can capture that rendered page without installing Playwright. ScreenshotNeo accepts a URL and returns an image or PDF; the API facts provided do not establish direct submission of a raw pasted HTML string. To use your own markup, publish it at a reachable URL first. API parameters and options are in the ScreenshotNeo documentation.

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

Replace https://example.com with the URL of the page containing your HTML. The example saves a WebP response as shot.webp; it is not a local-HTML upload command. ScreenshotNeo removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. For repeated captures, its other listed options include full-page output, element selection, PDF, custom CSS and JavaScript, readiness waits, bulk capture, and a usage API. Learn more at ScreenshotNeo, or sign up for the free plan.

Cost, reliability, and choosing a workflow

For occasional conversions of markup you already have, Playwright has no per-image service billing in the workflow shown here, but you do need to install and run browser automation. The browser, fonts, and resources available to that environment determine what gets rendered. html2canvas avoids a separate browser automation setup when running on an existing page, but it is a less faithful reconstruction and depends on browser access to the DOM and resources.

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

For recurring captures of hosted pages, a screenshot API can move browser setup and capture work to a service. With ScreenshotNeo, the stated billing behavior excludes bot checks, blank pages, failed loads, timeouts, and cache hits; response headers include X-Page-Verdict and X-Billed to say what happened. Its listed prices are monthly: Free 1,000 shots, Starter $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; yearly billing gives two months free. Every feature is on every plan. Those plans apply to its URL-based service, not to capturing an arbitrary unsaved HTML string directly.

Best Value
Sale
ScanSnap iX2500 Wireless or USB High-Speed Document Scanner, Black
  • OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
  • CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
  • STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
  • PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
  • AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss

Whichever route you choose, make the capture deterministic: keep the viewport fixed, include the required CSS, wait for content that matters, decide viewport versus full page, and inspect the resulting PNG at its intended display size. Those choices affect the rendered image more directly than the file extension.

Frequently Asked Questions

Can I convert an HTML file saved on my computer?

Yes. Read the file contents into a string in your Playwright script and pass that string to page.setContent. If it references relative assets, make sure they can be resolved in the browser context; an HTML file’s local relative paths may not work as expected when inserted as page content.

Can I convert pasted HTML directly with ScreenshotNeo?

The stated ScreenshotNeo API accepts a URL, not a raw HTML string. Host the page at a URL the service can reach before using its screenshot endpoint.

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

Quick Recap

Bestseller No. 4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

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
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.