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

To export a React-rendered section as a PDF in the browser, capture its mounted DOM element with html2canvas, add the resulting canvas image to a jsPDF document, then save it. This produces a raster image inside a PDF—not selectable HTML text—and it will not automatically paginate a long report. The result also depends on which CSS features html2canvas supports and whether remote images allow cross-origin access.

How the React-to-PDF pipeline works

html2canvas reads a DOM element and reconstructs it on a canvas using the CSS properties it understands. It is not a literal screenshot of the browser. The project documentation cautions that it can “render correctly” only properties it understands, so some browser styling may differ or be missing. See the html2canvas documentation.

The basic sequence is: wait until React has mounted the target, pass the element to html2canvas, await the returned canvas, turn it into image data, place that image in a jsPDF document, and save the file. Because the page content is added as an image, text in this approach is generally not selectable or searchable as PDF text.

Install the packages and create a working export

Install the dependencies in your React project. The html2canvas getting-started documentation currently shows the scoped package import; many projects also use the package named html2canvas. Check the package and import form that applies to your app and bundler before shipping. jsPDF documents installation with npm install jspdf.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
npm install html2canvas jspdf

The example below captures one section and places the entire image on one A4 portrait page. It is intentionally a one-page image placement, not automatic page layout.

import { useRef, useState } from 'react';
import html2canvas from 'html2canvas';
import { jsPDF } from 'jspdf';

export default function Report() {
  const reportRef = useRef(null);
  const [isExporting, setIsExporting] = useState(false);

  async function downloadPdf() {
    const element = reportRef.current;
    if (!element || isExporting) return;

    setIsExporting(true);
    try {
      const canvas = await html2canvas(element, {
        scale: 2,
        useCORS: true,
        backgroundColor: '#ffffff',
      });

      const image = canvas.toDataURL('image/png');
      const pdf = new jsPDF({
        orientation: 'portrait',
        unit: 'mm',
        format: 'a4',
      });
      const pageWidth = pdf.internal.pageSize.getWidth();
      const pageHeight = (canvas.height * pageWidth) / canvas.width;

      pdf.addImage(image, 'PNG', 0, 0, pageWidth, pageHeight);
      pdf.save('report.pdf');
    } catch (error) {
      console.error('PDF export failed:', error);
      // Show an error message in the interface in a real application.
    } finally {
      setIsExporting(false);
    }
  }

  return (
    <>
      <button type="button" onClick={downloadPdf} disabled={isExporting}>
        {isExporting ? 'Preparing PDF…' : 'Download PDF'}
      </button>
      <section ref={reportRef}>
        <h1>Quarterly report</h1>
        <p>Replace this content with the report you want to export.</p>
      </section>
    </>
  );
}

In JSX source, use normal JSX tags as shown; the escaped angle brackets in the code block keep the example markup readable as HTML. The key integration detail is that the ref points to a real mounted DOM element. Run the capture from a browser-side event, not while React is rendering on the server.

Choose page size and fit deliberately

The jsPDF constructor accepts orientation, units, and format. This example uses portrait A4 and millimetres, then calculates image height from the canvas aspect ratio. That preserves proportions while fitting the image to the page width. If the image height exceeds the page height, it extends beyond the single page; it is not shrunk to fit both dimensions. To fit a single page, calculate a scale using both available page width and height, and accept that the content may become too small to read.

For a different paper size, change format and recalculate against the page dimensions returned by jsPDF. For landscape output, use orientation: 'landscape'. Keep the dimension units consistent: jsPDF page measurements in this example are millimetres, while canvas width and height are pixels; use their ratio to compute image proportions rather than treating pixels as millimetres.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Control capture size, background, and appearance

html2canvas accepts an options object. Its configuration reference documents controls including scale, backgroundColor, width, height, scrollX, scrollY, windowWidth, and windowHeight. See the configuration reference.

  • scale: Defaults to window.devicePixelRatio. A higher value can increase raster detail, but also increases canvas dimensions and memory use. Test on the devices and report sizes your users actually need.
  • backgroundColor: Set a known color, such as white, when the captured section otherwise has a transparent background or the PDF needs a consistent page color.
  • windowWidth and windowHeight: Set the cloned rendering viewport dimensions when the default viewport clips content. For a long element, the FAQ suggests using its scrollWidth and scrollHeight as relevant values.
  • width and height: Set the dimensions for the rendered canvas when you need to control the capture bounds.
  • scrollX and scrollY: Control the scroll position used in rendering, which can matter for fixed or viewport-sensitive layout.
  • useCORS: Request cross-origin image loading through CORS where the image server permits it. It does not override browser security or grant permission that the remote server has not supplied.
  • onclone: Modify the cloned document before rendering, for example to adjust export-only styles without changing the visible page.
  • ignoreElements and data-html2canvas-ignore: Exclude selected elements, such as interactive export controls, from the capture.

For documented options and supported CSS, consult the project’s configuration and supported features pages. Avoid assuming that a CSS property renders correctly just because it appears in the browser.

Handle multiple pages instead of stretching one image

A single addImage call does not divide a long canvas into designed PDF pages. If the report is taller than the paper, the basic example can leave content outside the page. Choose a pagination strategy based on the document:

  • Capture page-sized sections: Structure the React output into deliberate page regions, capture each in turn, and add a new jsPDF page between images. This gives you control over page boundaries and makes it easier to avoid splitting a chart or heading.
  • Slice a long canvas: Render the full region, then draw successive page-height slices into smaller canvases and add each slice to a PDF page. This requires careful pixel-to-page-unit calculations and testing so slices align without gaps or repeated content.
  • Use browser print or a PDF-oriented renderer: If the PDF needs flowing selectable text, semantic document structure, or CSS page-break rules, a raster-image workflow may be the wrong fit. Compare text fidelity, pagination control, runtime, asset access, output size, render time, and implementation complexity before choosing an approach.

The official html2canvas and jsPDF pages describe the canvas and image-placement APIs, but do not specify one universally correct multipage algorithm. Test page breaks with the actual content, fonts, viewport, and paper format used in production.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HP Smart Tank 5000 Wireless All-in-One Ink Tank Printer, Scanner, Copier with 2 Years of Ink Included, Best-for-Home, Cartridge-Free, Refillable and AI-Enabled. (5D1B6A)
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.

Make images and styling reliable

Cross-origin images

By default, allowTaint is false. html2canvas skips images that would taint the canvas. Setting useCORS: true works only if the remote image server returns an appropriate Access-Control-Allow-Origin response header. If you control the asset, configure that server; otherwise, a same-origin proxy may be an option where permitted. The library cannot bypass the browser’s same-origin security rules. See the html2canvas FAQ and proxy documentation.

Wait for content before capturing

Call the export after the target has rendered and any data needed for it has loaded. If images or charts load asynchronously, make the export button unavailable until the content is ready, or explicitly wait for those assets in your app before calling html2canvas. The canvas API resolves asynchronously, so await it before reading the canvas or saving the PDF.

Exclude interface controls and adjust export styling

Use data-html2canvas-ignore on an element you do not want included, or pass an ignoreElements predicate. For export-specific tweaks, onclone lets you alter the cloned document while leaving the visible page unchanged. This can be useful for removing buttons, adjusting widths, or changing a background solely in the capture copy.

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

Performance, browser limits, and deployment

Canvas memory use grows with its pixel dimensions. Increasing scale multiplies both dimensions and can sharply increase total pixel area. Large captures may become slow or exceed browser canvas limits, producing blank or partial output. The html2canvas FAQ gives rough, platform-dependent guidance for current evergreen browsers—not fixed guarantees: it lists a maximum dimension around 32,767 pixels for Chrome/Chromium, Firefox, and desktop Safari, and rough maximum areas around 268 megapixels for Chrome/Chromium and 472 megapixels for Firefox. Actual limits vary with browser, operating system, GPU, and available memory; the FAQ notes lower iOS Safari limits can depend on device RAM.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
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

If a long region is clipped, the FAQ recommends setting windowWidth and windowHeight to the element’s scrollWidth and scrollHeight in relevant cases. For especially long documents, dividing work into page-sized regions can reduce the size of any one canvas. Validate the approach on lower-memory target devices, and handle rejected captures in the UI rather than leaving the user with no feedback.

html2canvas relies on browser APIs such as window, document, and computed styles; it is not suitable for Node.js or React server rendering. If PDF creation must run on a server, use a browser automation or PDF-generation architecture designed for server execution. The html2canvas FAQ names Puppeteer and Playwright for server-side screenshot generation.

Troubleshooting common export failures

Symptom Likely cause What to try
A remote image is missing The host does not grant CORS access, or loading would taint the canvas. Use useCORS: true only when the host sends the required CORS header; otherwise serve the asset from an authorized same-origin path or configure a permitted proxy.
The PDF is blank or partially rendered The canvas exceeded a browser or device limit, or the content was not ready. Reduce scale, capture smaller regions, wait for assets, and inspect the browser console. For viewport clipping, try windowWidth: element.scrollWidth and windowHeight: element.scrollHeight.
Some CSS looks different or disappears The property may be unsupported or only partially implemented by html2canvas. Check the supported-features page, simplify the style, or adjust the cloned document with onclone. Confirm the change in the generated PDF, not just the browser view.
The report is cut off at the bottom The capture was placed as one image on one page, or the viewport/canvas height did not cover the full element. Implement explicit multipage regions or slicing, and verify the capture dimensions against the element’s scroll dimensions.
Calling the function during server rendering fails html2canvas expects browser DOM and style APIs. Only import or invoke it in a client-side context, after mount. For server-side work, select a server-capable rendering design.
Export freezes or consumes too much memory The target region or scale creates an oversized canvas. Lower scale, split the target into smaller capture areas, and avoid retaining multiple large canvases at once.

Or skip the browser setup

If you need a screenshot of a live web page rather than a PDF generated from your React component tree, ScreenshotNeo offers a website screenshot API and MCP server. Its one-call endpoint returns PNG, JPEG, WebP, or a PDF. For a PDF, specify the output format using the API’s documented parameters.

cURL example for a screenshot response:

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 PDF output and other parameters. The API request does not replace a client-side export of a specific React DOM region; it captures a URL. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

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.

Frequently asked questions

Can this method produce selectable text?

No. This workflow embeds a rasterized canvas image in the PDF, so the content is not preserved as ordinary PDF text.

Will one html2canvas capture automatically create several PDF pages?

No. Add and size page images yourself, or choose a different rendering strategy that handles pagination.

Can I call html2canvas from a React server component or Node.js?

Not as a server-side DOM capture: the library depends on browser APIs. Invoke it in a client-side browser context.

Quick Recap

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.