Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
html2canvas

How to Print a Web Page with html2canvas

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

html2canvas can turn a selected part of a web page into a canvas, which you can download as an image or send to a browser print dialog. It does not print the page by itself, and the result is not a literal browser screenshot: the library rebuilds the page from its DOM and supported styles. For conventional, paginated printing, the browser’s native print flow may be a better fit; for an image of the page, html2canvas is useful when its rendering and cross-origin limits suit your page.

Choose the output before you capture

“Print a web page” can mean three different things: send the live page to the printer, capture a visual image, or create a paginated PDF. They are not interchangeable.

Goal Practical route Main trade-off
Print readable text with normal page breaks Use the browser’s print command or window.print(), with print-specific CSS as needed. The browser lays out the document for paper; the printed appearance may differ from the screen layout.
Capture a selected element as an image Render it with html2canvas, then download the canvas or print an image of it. The output is rasterized, can be large, and may differ from the live page where CSS or assets are unsupported.
Make a multi-page PDF Use a PDF workflow designed and tested for pagination, or print through the browser’s PDF destination. A single tall canvas does not automatically become a well-paginated, searchable document.

html2canvas’s own documentation describes its method this way: “The script traverses through the DOM of the page it is loaded on.” That is why the output should be checked against the actual page rather than treated as a pixel-for-pixel browser photograph. See the html2canvas project documentation.

Capture an element with html2canvas

Install the package in a project that bundles browser JavaScript:

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.
npm install html2canvas

Then select the content you want, wait for the capture to finish, and decide what to do with the returned canvas. The following example provides both an image download and an image-oriented print button. Put it in a page where the target element exists; adapt the selectors and labels to your application.

import html2canvas from 'html2canvas';

const target = document.querySelector('#print-area');
const captureButton = document.querySelector('#capture');
const printButton = document.querySelector('#print-capture');
const downloadLink = document.querySelector('#download-capture');
const preview = document.querySelector('#preview');

if (!target || !captureButton || !printButton || !downloadLink || !preview) {
  throw new Error('A required capture or output element was not found.');
}

let latestCanvas;

captureButton.addEventListener('click', async () => {
  captureButton.disabled = true;
  try {
    latestCanvas = await html2canvas(target, {
      windowWidth: target.scrollWidth,
      windowHeight: target.scrollHeight
    });
    preview.replaceChildren(latestCanvas);
    downloadLink.href = latestCanvas.toDataURL('image/png');
    downloadLink.download = 'web-page-capture.png';
    downloadLink.hidden = false;
    printButton.disabled = false;
  } catch (error) {
    console.error('Capture failed:', error);
    alert('The page could not be captured. Check the console and page assets.');
  } finally {
    captureButton.disabled = false;
  }
});

printButton.addEventListener('click', () => {
  if (!latestCanvas) return;
  const printWindow = window.open('', '_blank');
  if (!printWindow) {
    alert('Allow pop-ups for this site, then try printing again.');
    return;
  }

  const image = printWindow.document.createElement('img');
  image.src = latestCanvas.toDataURL('image/png');
  image.alt = 'Captured web page';
  image.style.cssText = 'display:block;max-width:100%;height:auto;margin:0 auto';
  printWindow.document.body.style.margin = '0';
  printWindow.document.body.append(image);
  image.onload = () => printWindow.print();
});

Example markup for those selectors:

<section id="print-area">
  <h1>Report</h1>
  <p>The content to capture goes here.</p>
  <button data-html2canvas-ignore>Interactive control not for the capture</button>
</section>
<button id="capture">Create image</button>
<button id="print-capture" disabled>Print captured image</button>
<a id="download-capture" hidden>Download PNG</a>
<div id="preview"></div>

Capturing a focused content container is usually more useful than capturing document.body: menus, navigation, floating controls, and capture buttons otherwise become part of the image. The library recognizes data-html2canvas-ignore for excluding individual elements. For more involved changes to the cloned page, use the documented onclone option rather than altering the visible page only for the capture.

Set dimensions and rendering options deliberately

html2canvas options are version-sensitive; consult the configuration reference for the installed package. These options are particularly relevant when preparing a printable capture:

Rank #2
Sale
Canon PIXMA TS6520 Wireless Color Inkjet Printer, Duplex Printing, Copier/Scanner, 1.42" OLED Display, Compact, White
  • 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
  • scale: controls the rendered pixel density. A larger value can make an image sharper in print, but increases pixel count and memory use. It does not improve unsupported CSS or make text selectable.
  • windowWidth and windowHeight: set the window dimensions used for rendering calculations. For a tall element, setting these to its scrollWidth and scrollHeight can help avoid a viewport-sized layout when the intended capture is the full element. This is not a universal fix for clipping; inspect the output.
  • useCORS: requests cross-origin images in a way that can allow them on the canvas when the image server permits cross-origin access. It cannot grant permission the server does not provide.
  • proxy: specifies a proxy route for resources when you have a suitable proxy configured. A proxy must be designed safely; do not expose a general-purpose proxy to untrusted URLs.
  • ignoreElements: lets you filter elements out of the capture; the ignore data attribute is a simpler option for markup you control.
  • onclone: lets you adjust the cloned document used for rendering—for example, remove an element or change a style without changing the live page.

Wait for content your page loads asynchronously before calling html2canvas. If a chart, image, or custom font has not loaded yet, the canvas may capture an incomplete state. The option reference also documents image loading behavior; the project’s configuration lists a default image load timeout of 15,000 milliseconds. Treat that as a library setting, not a guarantee that every page resource will be ready within that time.

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

Download an image, print it, or make a PDF

Download the captured canvas

For a simple image download, the essential operation is:

const canvas = await html2canvas(target);
const link = document.createElement('a');
link.download = 'capture.png';
link.href = canvas.toDataURL('image/png');
link.click();

The html2canvas examples use canvas.toDataURL() to produce an image. If the canvas contains a resource that violates browser canvas security rules, export can fail because the canvas is tainted. A PNG image is a raster output: its text is not selectable or searchable as text.

Rank #3
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

Print a captured image

The earlier example opens a new window containing the canvas image and calls that window’s print dialog. The browser and user still control the final paper or PDF output. This approach is suitable when a visual snapshot is the goal, but a very tall canvas may shrink to fit a sheet or divide awkwardly. Test page scaling and page breaks using the target browser and printer or PDF destination.

Use native print or a PDF workflow for paginated documents

If readers need selectable text, accessibility, predictable page breaks, or a document with multiple pages, do not assume one canvas is the right intermediate format. Native browser printing preserves the browser’s document-printing model; use print CSS to hide controls and adjust layout. A PDF pipeline may work better for application-generated documents, but html2canvas’s official examples do not establish a universal PDF recipe. Any approach that turns a canvas into PDF pages needs deliberate page sizing, splitting, and fidelity testing.

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

Understand the limits before relying on the result

It reconstructs the DOM; it does not photograph the browser

The library reads the page structure and style information and renders a representation. Its project documentation says full CSS support is not possible because properties must be implemented individually; some properties are only partially supported or unsupported. Complex effects, layout behavior, and browser-specific rendering can therefore differ. Compare the output with the live page in the browser you support, especially after CSS changes.

Rank #4
Sale
Brother Work Smart 1360 Wireless Color Inkjet All-in-One Print, Scan, Copy
  • AFFORDABLE ALL-IN-ONE FOR HOME AND HOME OFFICE: Print, copy, and scan on one compact wireless printer designed for everyday home office printing, schoolwork, documents, and reports. Produce beautiful prints for results that stand out.
  • EASY TO USE WITH CLOUD APP CONNECTIONS: Print from and scan to popular Cloud apps(2), including Google Drive, Dropbox, Box, OneDrive, and more from the simple-to-use 1.8” color display on your printer.
  • FULL-SIZE FEATURES IN A COMPACT DESIGN: This printer includes automatic duplex (2-sided) printing, a 20-sheet single-sided Automatic Document Feeder (ADF)(3), and a 150-sheet paper tray(3). Engineered to print at fast speeds of up to 16 pages per minute (ppm) in black and up to 9 ppm in color(4).
  • MULTIPLE CONNECTION OPTIONS: Connect your way. Interface with your printer on your wireless network or via USB.
  • MOBILE PRINTING MADE EASY: Go mobile with the Brother Mobile Connect app(5) that delivers easy onscreen menu navigation for printing, copying, scanning, and device management from your mobile device. Monitor your ink usage with Page Gauge to help ensure you don’t run out(6).

Cross-origin images and iframes have security boundaries

Images generally need to be same-origin or served with suitable CORS permission, or be fetched through a configured proxy. Setting useCORS: true is not a way around a server’s access policy. Cross-origin iframes cannot be read by page JavaScript under browser security restrictions, so html2canvas cannot simply capture their contents. The official FAQ discusses missing images and empty or clipped canvases.

Long pages use memory and may exceed canvas limits

A canvas stores pixels, so a larger capture and higher scale can sharply increase memory use. Browser, operating system, device, and hardware affect maximum dimensions; the project FAQ warns that oversized canvases can produce blank or partial output. There is no single safe maximum to promise across browsers. If output is blank or cut off, try a smaller target, reduce scale, or capture sections separately and check each result.

It runs in the browser

html2canvas relies on browser APIs and the current page context. It is not a Node.js server-side page renderer. The project FAQ suggests Puppeteer or Playwright for server-side screenshots, and browser-native tab capture APIs for browser extensions.

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.
Best Value
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture problems

  • Images are missing: check whether each image URL is same-origin or sends appropriate CORS headers. Try useCORS only when the resource server permits it; otherwise arrange an appropriate proxy or use another capture method. Cross-origin iframe contents are not readable through this approach.
  • The canvas is blank or only partly rendered: test a smaller element, lower scale, and capture sections separately. Check the console for load or security errors and verify that the element has visible dimensions at capture time.
  • The bottom or sides are clipped: inspect the target’s scrollWidth and scrollHeight, and consider passing them as windowWidth and windowHeight. Ensure the target is not being clipped by its own CSS overflow rules.
  • Styles differ from the page: confirm the affected styles are supported by the installed html2canvas version. Reduce the example to a minimal target and compare individual features; for exact browser-rendered appearance, use a browser screenshot tool rather than expecting this DOM renderer to reproduce every CSS feature.
  • Content appears before it is ready: wait for the specific image, font, chart, or application state before calling capture. The returned promise signals that rendering has completed; it does not mean an unrelated application request has finished.
  • Download or export throws a security error: investigate cross-origin assets that taint the canvas. Capture may appear to work while toDataURL() is rejected, because export has the stricter requirement that the canvas remain origin-clean.
  • The print window does not open: browsers may block a popup unless it opens in direct response to a user action. Keep the print call associated with the user’s button click, and let the user permit pop-ups for the site if needed.
  • Printing is too small or splits badly: that is a pagination issue, not a capture failure. Prefer native print or a paginated PDF workflow when the document must fit paper sensibly.

When to use another capture approach

For a browser extension that needs a literal tab capture, use the browser’s native capture API. For a server-side screenshot, the html2canvas project FAQ points developers toward Puppeteer or Playwright. If your goal is a shareable or printable visual from a URL without building and maintaining browser setup, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its clean-shot workflow removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server provides screenshot tools for AI agents. The ScreenshotNeo site describes the service and options.

Or skip the browser setup

One GET request can capture a URL as an image or PDF. This cURL example saves a WebP screenshot of the target page:

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 request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does html2canvas open the printer dialog?

No. It returns a canvas; your code must separately initiate printing or download the image.

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

Can html2canvas capture a cross-origin iframe?

No. Browser security prevents page JavaScript from reading cross-origin iframe contents.

Can I run html2canvas directly in a Node.js script?

It is designed to run in a browser page. For server-side screenshots, the project FAQ suggests Puppeteer or Playwright.

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
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.