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

To put one rendered HTML region on a single PDF page whose height grows with the content, capture the region with html2canvas, choose a PDF width, derive the height from the canvas aspect ratio, and pass both dimensions as jsPDF’s custom format array. Keep the units straight: the canvas is measured in pixels, while jsPDF uses the unit you configure, such as millimeters or points.

The core calculation

html2canvas returns a bitmap with canvas.width and canvas.height in pixels. jsPDF does not interpret those numbers as millimeters or points. Instead, select a PDF width in your chosen jsPDF unit and calculate a proportional height:

pdfHeight = pdfWidth × (canvas.height ÷ canvas.width)

For example, if the canvas is 1,200 pixels wide and 2,400 pixels tall, a 210 mm PDF width produces a 420 mm page height. The image keeps its aspect ratio and fills one custom page.

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

Complete browser-side implementation

Load html2canvas and jsPDF in a browser page, then capture the element after its fonts, images and dynamic content are ready. This example creates a portrait PDF in millimeters and saves it locally.

async function exportElementToPdf() {
  const element = document.querySelector("#content");
  if (!element) throw new Error("Content element was not found");

  // Include the complete scrollable region, not only its visible box.
  const canvas = await html2canvas(element, {
    windowWidth: element.scrollWidth,
    windowHeight: element.scrollHeight,
    scale: 1
  });

  if (!canvas.width || !canvas.height) {
    throw new Error("The captured canvas has no dimensions");
  }

  // These values are millimeters because the jsPDF unit is "mm".
  const pageWidth = 210;
  const pageHeight = pageWidth * (canvas.height / canvas.width);

  const { jsPDF } = window.jspdf;
  const pdf = new jsPDF({
    orientation: "portrait",
    unit: "mm",
    format: [pageWidth, pageHeight]
  });

  const image = canvas.toDataURL("image/png");
  pdf.addImage(image, "PNG", 0, 0, pageWidth, pageHeight);
  pdf.save("content.pdf");
}

The numeric array in format is [width, height] in the configured unit. The scale: 1 setting makes the relationship between canvas pixels and the source layout easier to inspect; it does not make one pixel equal one millimeter. A higher scale can improve detail but increases memory use and the chance of hitting browser canvas limits.

Waiting for content before capture

Run the function only after asynchronous content has settled. Wait for a specific application state, call it after a data fetch completes, and ensure web fonts and important images have loaded. If the page changes after capture starts, the resulting bitmap can be incomplete even though the PDF code is correct.

Adding margins

Margins must be included in the page geometry. Reserve the desired left and right margins, compute the image height from the remaining width, and add the top and bottom margins to the page height:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const margin = 10; // mm on every side
const pageWidth = 210;
const imageWidth = pageWidth - (margin * 2);
const imageHeight = imageWidth * (canvas.height / canvas.width);
const pageHeight = imageHeight + (margin * 2);

const pdf = new jsPDF({
  orientation: "portrait",
  unit: "mm",
  format: [pageWidth, pageHeight]
});
pdf.addImage(canvas.toDataURL("image/png"), "PNG",
  margin, margin, imageWidth, imageHeight);

If you want a different paper width, change pageWidth; the derived height follows automatically. Use points or inches instead of millimeters only if you express every page and placement value in that same unit.

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

Choosing a one-page canvas versus normal pagination

A custom-height page is useful for receipts, reports, invoices, embeds and continuous web content where one uninterrupted sheet is desirable. It is still a raster image, however, so text can become difficult to read when a very long page is viewed or printed at a reduced scale.

Requirement Custom-height image page Paginated PDF
Continuous single-sheet output Strong fit; height follows the captured ratio. Requires deliberate page-break design.
Selectable or searchable text Not provided by the bitmap alone. Prefer an HTML/text rendering path or generated document content.
Very long content Canvas dimension and pixel-area limits become a risk. Safer because content is split across normal pages.
Predictable breaks and print readability Breaks are not created automatically. Better control over page breaks and margins.

For a long document, capture separate sections or use jsPDF’s HTML rendering and page-break controls rather than forcing everything into one enormous bitmap. Test the output at the size your readers will actually view or print.

Preventing clipped content

Use the element’s scroll dimensions

Clipping usually occurs because the capture viewport is the element’s visible height rather than its full layout height. Passing element.scrollWidth and element.scrollHeight as windowWidth and windowHeight gives html2canvas the dimensions of the complete scrollable region. For nested scrolling containers, temporarily remove the inner overflow restriction or capture a wrapper whose layout includes all content.

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

Make hidden and lazy content explicit

Expand accordions, render virtualized rows, and load lazy images before calling html2canvas. A browser screenshot library cannot capture DOM nodes that your application has not rendered. Freeze animations where possible so an element does not move between layout measurement and rasterization.

Canvas limits and long pages

Browser limits vary by engine, operating system and device. The html2canvas FAQ gives rough evergreen-browser guidance of about 32,767 pixels for a maximum dimension in Chrome/Chromium and Firefox, with approximate maximum areas of 268 million pixels for Chrome/Chromium and 472 million pixels for Firefox. Safari desktop is described as similar to Chrome, while iOS limits are lower and device-dependent. These are not guarantees.

Rank #3
HP Smart Tank 5101 Wireless All-in-One Refillable Printer, Scanner, Copier with 2 Years of Ink Included, Wireless (2.4ghz only) Printer-for-Home use (1F3Y0A)
  • 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
  • INNOVATION YOU CAN TRUST. Cartridge-free printing that keeps you printing longer with fewer interruptions, powered by the trusted HP innovation you rely on today
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster.

A tall canvas can therefore fail silently, produce a blank bitmap or contain only part of the page. Estimate the resulting pixel width and height before capture, and treat a very large area as a reason to paginate or capture sections. Lowering scale reduces pixel dimensions, but also reduces detail.

Images, cross-origin content and CSS

Images hosted on another origin

The browser’s same-origin policy applies to images. Set useCORS: true only when the image server sends suitable CORS headers:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight,
  useCORS: true,
  scale: 1
});

If the server cannot grant CORS access, use a server-side proxy that you control, or replace the asset with a same-origin version. Do not assume that adding useCORS can bypass a server’s policy.

CSS differences

html2canvas re-creates the page from DOM and computed styles; it does not reproduce every CSS property or browser painting behavior. Filters, complex blend modes, unusual backgrounds, pseudo-elements and advanced layout details may differ. Create a print-specific wrapper or stylesheet when exact output matters, and validate the actual styles used by your site.

Node.js and server-side generation

html2canvas depends on window, document and computed browser styles, so it is a client-side library. It is not a drop-in Node.js renderer. For server-side screenshots, use browser automation such as Puppeteer or Playwright, then build a PDF from the captured result or use the browser’s PDF support. That approach requires managing a browser process, fonts, navigation waits, authentication and resource failures.

Rank #4
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)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The bottom of the element is cut off

  • Cause: The capture used the visible viewport dimensions.
  • Fix: Pass scrollWidth and scrollHeight, remove restrictive overflow on the capture wrapper, and ensure all dynamic sections are rendered.

The PDF is blank or only partly rendered

  • Cause: The canvas exceeded a browser dimension or total-area limit, or capture ran before content loaded.
  • Fix: Reduce scale, split the document into sections, wait for fonts and images, or switch to paginated output.

Images disappear

  • Cause: Cross-origin images lack permission for canvas use.
  • Fix: Configure the image host’s CORS headers and use useCORS: true, proxy the assets, or serve them from the same origin.

The PDF styling does not match the page

  • Cause: html2canvas has incomplete CSS support and rasterizes the result.
  • Fix: Simplify or override the print layout, test the specific CSS features in your target browsers, and use a text-oriented or browser PDF path when fidelity and selectable text are more important than a single image page.

The page is unreadably long

  • Cause: A single bitmap page is being reduced to fit a viewer or printer.
  • Fix: Use normal pages, choose a wider page format where appropriate, or capture logical sections separately.

Performance, reliability and file size

  • Memory: Canvas memory grows with width, height and scale. Large pages can stall the tab or fail before jsPDF runs.
  • Speed: More DOM nodes, high-resolution images, web fonts and expensive CSS increase rasterization time. Capture only the required region.
  • Output size: PNG preserves sharp text but can be large. JPEG can reduce size for photographic content, at the cost of compression artifacts; choose the format that suits the document.
  • Repeatability: Fix the viewport, wait conditions, timezone-dependent data and animations when generating comparable PDFs.
  • Security: Treat custom URLs, HTML and scripts as untrusted input in any server-side workflow. Restrict navigation and resource access in browser automation.

Or skip the browser setup

ScreenshotNeo provides a single-call website screenshot API when you do not want to maintain browser capture code. It accepts a URL and returns PNG, JPEG, WebP or PDF; full-page capture can load lazy images, and PDF options include paper size, margins, landscape mode and page ranges. Cookie banners, newsletter popups and chat widgets are removed before the shot. Bot checks, blank pages, timeouts and failed loads are not billed, and response headers identify the page verdict and billing status. Its MCP server lets Claude, Cursor and other MCP clients call take_screenshot, get_page_info and capture_pdf.

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.
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 documentation for authentication and PDF parameters. A free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Sign up for the free ScreenshotNeo plan.

FAQ

Can I use pixels directly as jsPDF dimensions?

Only if you deliberately configure a pixel-based unit supported by your jsPDF version. In the common millimeter or point setup, convert by preserving the canvas aspect ratio and choosing page dimensions in the configured unit.

Will a custom-height PDF remain accessible?

No. The example places one raster image on the page, so it does not preserve the DOM’s text structure, semantics or selectable text.

Should I use PNG or JPEG?

PNG is usually safer for text, lines and flat UI colors. JPEG is often smaller for photographic pages but may blur fine text or introduce artifacts.

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

Frequently Asked Questions

Can I use pixels directly as jsPDF dimensions?

Only with a deliberately pixel-based jsPDF unit. Otherwise choose dimensions in millimeters, points or another configured unit and preserve the canvas aspect ratio.

Will a custom-height PDF remain accessible?

Not when it is created as one raster image; the DOM’s text structure and semantics are not retained.

Should I use PNG or JPEG?

PNG generally preserves text and interface details; JPEG can be smaller for photographic content but may blur fine text.

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
Bestseller No. 3
HP Smart Tank 5101 Wireless All-in-One Refillable Printer, Scanner, Copier with 2 Years of Ink Included, Wireless (2.4ghz only) Printer-for-Home use (1F3Y0A)
HP Smart Tank 5101 Wireless All-in-One Refillable Printer, Scanner, Copier with 2 Years of Ink Included, Wireless (2.4ghz only) Printer-for-Home use (1F3Y0A)
PREMIUM SUPPORT - Strong technical expertise to solve issues faster.; THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
$161.49

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.

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.