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

Replace doc.addHTML() with the maintained doc.html() API. Install and import html2canvas, wait for the returned Promise (or use the callback), and size the capture from the element’s full scroll dimensions. Most “addHTML is not a function,” “html2canvas is not defined,” blank-PDF, missing-image and clipped-output errors follow from one of those issues.

Why addHTML fails in current jsPDF

addHTML (and its predecessor fromHTML) is a legacy plugin path. jsPDF maintainers have stated that they will no longer support those methods. The maintained replacement is doc.html(), which uses html2canvas to turn a DOM element into PDF content.

That change affects more than the method name. Old integrations commonly pass an onrendered callback and assume a browser-global html2canvas. Current html2canvas is Promise-based, and module bundlers do not automatically create a global variable when you import a package. Update the API call, dependency handling and asynchronous flow together.

Check your versions and runtime first

Confirm the installed packages

npm ls jspdf html2canvas dompurify

The html method depends on html2canvas. If you pass an HTML string rather than an existing DOM node, jsPDF also uses DOMPurify for sanitization. Install the packages your build needs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
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
npm install jspdf html2canvas dompurify

Keep this code in a browser context. html2canvas requires window, document and computed styles; it is not a server-side Node.js renderer.

Verify the target element

const element = document.querySelector('#invoice');
if (!element) throw new Error('Missing #invoice element');
if (!element.isConnected) throw new Error('#invoice is not attached to the document');

Run the capture only after the element has been mounted and its images, fonts and dynamic data have loaded. A hidden element or a selector that returns null can produce an empty or failed document even when the PDF code itself is correct.

Recommended migration: use doc.html()

This module example replaces the legacy call and handles a long element, retina-quality rendering and cross-origin images that return suitable CORS headers:

import { jsPDF } from 'jspdf';

const element = document.querySelector('#invoice');
if (!element) throw new Error('Missing #invoice element');

const doc = new jsPDF();
await doc.html(element, {
  margin: [10, 10, 10, 10],
  autoPaging: 'text',
  html2canvas: {
    scale: 2,
    useCORS: true,
    windowWidth: element.scrollWidth,
    windowHeight: element.scrollHeight
  },
  callback: (pdf) => pdf.save('invoice.pdf')
});

Because doc.html() is asynchronous, place it inside an async function or use a Promise chain. Saving in the callback guarantees that layout and rendering have completed. You can also await the method and save afterward when your installed jsPDF version resolves the Promise:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
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
async function makePdf() {
  const element = document.querySelector('#invoice');
  const doc = new jsPDF();
  await doc.html(element, {
    margin: 10,
    autoPaging: 'text',
    html2canvas: { scale: 2, useCORS: true },
    callback: (pdf) => pdf.save('invoice.pdf')
  });
}

Script-tag builds

If you do not use a bundler, load compatible jsPDF and html2canvas browser builds before your application script, then call doc.html(). Do not mix a legacy addHTML plugin file with a modern jsPDF build. If the package expects an optional dependency, use the distribution configuration documented for that build rather than assuming an import creates window.html2canvas.

Diagnose “html2canvas is not defined”

The old implementation explicitly looked for a global html2canvas or rasterizeHTML. If neither existed, it threw an error. In an ES-module build, import the dependency explicitly:

import html2canvas from '@html2canvas/html2canvas';

const element = document.querySelector('#invoice');
const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight,
  useCORS: true
});

Use the package name and import form supported by the version in your lockfile. The diagnostic call returns a Promise that resolves to a canvas; logging that canvas helps separate an html2canvas rendering problem from jsPDF pagination or file-saving code.

Do not “fix” the error with a random global

Adding an unrelated script, assigning an imported module to window.html2canvas, or copying the old plugin can create version mismatches. A supported jsPDF build plus an explicitly installed dependency is more reliable than recreating the legacy global contract.

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

Fix blank, partial or cut-off PDFs

Set the capture viewport to the complete element

Browsers can render only part of a very tall or wide canvas when the capture viewport remains at the visible window size. Set windowWidth and windowHeight from scrollWidth and scrollHeight, as in the migration example. This is especially important for invoices, dashboards and pages with lazy-loaded sections.

Reduce scale for oversized canvases

scale: 2 improves detail but multiplies canvas width and height, and therefore memory use. If the canvas is blank or only its top portion appears, try scale: 1, a smaller capture region, or several sections rendered into separate PDF pages. Browser canvas limits vary by engine and device; they are limits, not guaranteed capacities.

Make content available before capture

  • Wait for application data and web fonts to finish loading.
  • Force lazy images to load by scrolling them into view or replacing lazy-loading behavior for the print view.
  • Capture an element that is visible and has a non-zero width and height.
  • Remove animated transitions during capture so layout does not change between measurements.

Use pagination deliberately

autoPaging: 'text' attempts to keep text flowing across pages. Complex positioned elements, transformed containers and large single images can still break across pages. For those layouts, split the source DOM into page-sized sections and call doc.html() for each section, or simplify the print stylesheet.

Why the PDF does not look like the browser

html2canvas reconstructs a representation from the DOM; it does not take a pixel-perfect screenshot. Its maintainers note that every CSS property must be implemented individually, so full CSS support is not possible. Gradients, filters, blend modes, pseudo-elements, transforms, sticky positioning and unusual font rendering may differ.

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

Build a print-oriented capture view

  • Use ordinary block layout and explicit widths for the printable container.
  • Replace visual effects with solid colors and borders where fidelity matters.
  • Disable sticky headers, hover states and transitions in a print-only class.
  • Set explicit font sizes, line heights and image dimensions.
  • Test the exact browser and CSS combination used by your users.

If exact browser pixels are a requirement rather than a convenience, use a real browser renderer such as Puppeteer or Playwright on the server instead of html2canvas.

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

Missing images, tainted canvases and iframes

Same-origin images

Images served from the same origin normally work. For another origin, the image server must return an appropriate CORS header, and the capture should set useCORS: true. The browser, not html2canvas, enforces this policy; a JavaScript option cannot bypass a server that does not grant access.

html2canvas: {
  useCORS: true,
  imageTimeout: 15000
}

Check the image request in browser developer tools. A redirect to a host without CORS headers, an expiring signed URL or a blocked mixed-content request can make an otherwise valid image disappear.

Cross-origin iframes

html2canvas cannot read a cross-origin iframe’s contentDocument because of browser security rules. Capture content that your page owns, proxy permitted resources through your origin, or render the complete page in a headless browser. Same-origin policy still applies even when the iframe is visually visible.

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

Fonts and SVG

Wait for document.fonts.ready before capturing if typography matters. For SVG or data-URI images, verify that the browser can display the asset independently; malformed SVG, blocked external stylesheets or a tainted canvas can prevent it from appearing in the PDF.

Best Value
Sale
ScanSnap iX1300 Wireless or USB Double-Sided Color Document Scanner, Black
  • FITS SMALL SPACES AND STAYS OUT OF THE WAY. Innovative space-saving design to free up desk space, even when it's being used
  • SCAN DOCUMENTS, PHOTOS, CARDS, AND MORE. Handles most document types, including thick items and plastic cards. Exclusive QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
  • GREAT IMAGES EVERY TIME, NO EXPERIENCE REQUIRED. A single touch starts fast, up to 30ppm duplex scanning with automatic de-skew, color optimization, and blank page removal for outstanding results without driver setup
  • SCAN WHERE YOU WANT, WHEN YOU WANT. Connect with USB or Wi-Fi. Send to Mac, PC, mobile devices, and cloud services. Scan to Chromebook using the mobile app. Can be used without a computer
  • PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. ScanSnap Home all-in-one software brings together all your favorite functions. Easily manage, edit, and use scanned data from documents, receipts, business cards, photos, and more
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser code versus Node.js

html2canvas is client-side only. It relies on browser globals and cannot run directly in a Node.js process. For server-generated PDFs, launch Chromium with Puppeteer or Playwright, navigate to the page, wait for network and application readiness, and print or screenshot there. Keep jsPDF/html2canvas in the browser when the user is clicking a “Download PDF” button.

Error-to-fix map

Symptom Likely cause Fix
addHTML is not a function Removed or incompatible legacy plugin Migrate to doc.html() and update the asynchronous flow.
Callback never runs Legacy onrendered callback or a rejected Promise Use callback with doc.html(); add try/catch around await.
html2canvas is not defined Dependency not installed, imported or exposed as expected Install/import html2canvas or use the supported browser build.
Blank or clipped output Canvas dimensions exceed a browser limit or viewport is too small Set scroll dimensions, lower scale and split very large sections.
Images missing Cross-origin response lacks CORS permission Host assets same-origin, configure CORS, or use a permitted proxy.
Works in browser, fails in Node html2canvas requires DOM APIs Use Puppeteer/Playwright for server rendering.

Production checklist

  1. Record the jsPDF and html2canvas versions in your lockfile.
  2. Remove every addHTML, fromHTML and onrendered call.
  3. Install and import optional dependencies through your package manager.
  4. Capture a mounted, visible element after data, fonts and images are ready.
  5. Use scrollWidth/scrollHeight for long content.
  6. Test same-origin, CORS-enabled and blocked-image cases.
  7. Try a lower scale or sectioned rendering for large documents.
  8. Use a headless browser when CSS fidelity or server execution is mandatory.

Or skip the browser setup

If your goal is a dependable website screenshot or PDF rather than a client-side jsPDF conversion, ScreenshotNeo provides a single API request. It accepts cookie and consent banners as a visitor, then removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing result.

Use the API documentation at https://screenshotneo.com/docs/ for all options, including full-page lazy-image loading, CSS-selector element capture, dark mode, device presets, retina scale, PDF paper and page-range controls, custom CSS/JavaScript, click and wait actions, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching, signed image links, asynchronous webhooks, bulk capture and usage reporting. ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.

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
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}`);

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Create a free ScreenshotNeo account to get an API key.

Frequently Asked Questions

Can I keep using addHTML with an older jsPDF release?

You may be able to pin an old integration, but the method is no longer maintained. Migrating to doc.html() avoids the legacy plugin and callback contract.

Should I call html2canvas before doc.html()?

Only for diagnosis or a custom pipeline. For normal PDF generation, let doc.html() invoke its html2canvas dependency and configure it through the html2canvas option.

Does useCORS bypass an image server’s security policy?

No. The image response must grant CORS access; otherwise the browser can still omit or taint the canvas.

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.

What is the best option for a server-side PDF?

Use a headless browser such as Puppeteer or Playwright. html2canvas requires a browser DOM and is not a Node.js renderer.

Quick Recap

Bestseller No. 1
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.