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
html2canvas

How to Capture Scrolled Content Correctly for PDF Export with html2canvas

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

To capture an element’s full scrollable content, set html2canvas’s rendering window to that element’s scrollWidth and scrollHeight. Then inspect the canvas and, for very long content, split it into page-sized captures before assembling the PDF. This fixes many blank or clipped captures, but it cannot guarantee an arbitrarily large canvas or a pixel-perfect browser screenshot.

How do I capture the full page with html2canvas?

Pass the element you actually want to export to html2canvas, and use its scroll dimensions for the rendering window:

const element = document.querySelector('#capture');
if (!element) throw new Error('Capture element #capture was not found');

const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight
});

This follows the library FAQ’s recommended sizing approach for output that is blank or clipped. scrollWidth and scrollHeight include the element’s scrollable content, whereas its visible box may show only a viewport-sized portion. Make sure the selector identifies the intended content container—not the page’s outer shell, a sidebar, or a wrapper with unrelated dimensions.

The example assumes it runs in a browser after the page and target element exist. For example, call it from an event handler or after the application has rendered the content. Check that element is not null before capture, and inspect the resulting canvas dimensions. If the element’s own content has not loaded yet, the scroll measurements may not describe the final page.

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.

The two window settings are not the same as the canvas output dimensions. html2canvas documents width and height as canvas dimensions, and windowWidth and windowHeight as rendering-window settings. The latter can affect media queries, so they may change the layout as well as the area rendered. Set the output size and rendering window deliberately rather than treating all four values as interchangeable.

Make a basic PDF from the inspected canvas

A reliable workflow has two stages: render to a canvas, then pass the canvas image to your chosen PDF library. The following browser example uses jsPDF to make a one-page PDF from the entire capture. Install html2canvas and jspdf in your project, load them through your bundler, and run this after the element is available. The canvas is scaled to fit a landscape A4 page without changing its aspect ratio; a very tall canvas will therefore be small on that single page.

import html2canvas from 'html2canvas';
import { jsPDF } from 'jspdf';

async function exportCapture() {
  const element = document.querySelector('#capture');
  if (!element) throw new Error('Capture element #capture was not found');

  const canvas = await html2canvas(element, {
    windowWidth: element.scrollWidth,
    windowHeight: element.scrollHeight
  });

  if (!canvas.width || !canvas.height) {
    throw new Error('html2canvas returned an empty canvas');
  }

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

  pdf.addImage(image, 'PNG', 0, 0, imageWidth, imageHeight);
  pdf.save('capture.pdf');
}

exportCapture().catch(console.error);

This example deliberately puts the full image on one page; it does not create readable multi-page pagination automatically. If the capture is long, use page-sized or bounded sections and place those in the PDF as separate pages. Decide whether page breaks should follow content boundaries, fixed vertical intervals, or application-specific sections. Preserve the aspect ratio, inspect text size at actual print scale, and verify that page boundaries do not cut through important content.

Choose a single canvas or page-sized captures

A single canvas is simpler when the target is modest in size and you want one continuous image. It becomes a poor fit when the canvas is so tall or wide that the browser cannot reliably create it, or when fitting it on one PDF page makes text unreadable. html2canvas’s FAQ cautions that canvas limits vary by browser, operating system, and hardware. Its older numeric limits should not be treated as current universal guarantees.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach Useful when Main trade-off
One full canvas The content dimensions are manageable, and a single continuous image suits the PDF. A very large canvas may fail or consume substantial memory; fitting a long image to one page can make it illegible.
Page-sized or bounded captures The document is very long, or each PDF page needs readable content at a chosen page size. You must decide where sections start and end, and check that the rendered regions align without gaps, overlaps, or misplaced fixed elements.

Before choosing, measure the target’s width and height and consider the browsers and devices your users actually run. Also account for responsive breakpoints, fixed headers and footers, image origins, PDF page size, legibility, memory use, and final file size. There is no documented universal height threshold at which sectioning becomes mandatory; test the specific pages and environments you support.

Render sections without changing the intended layout

Sectioning is a practical response to canvas constraints, not a pagination feature prescribed by html2canvas. One implementation strategy is to capture bounded elements that correspond to meaningful document sections. Another is to render regions at a consistent width and place each region on its own PDF page. In either case, compare the output at page joins: repeated headers may be intentional, but a header or sticky control captured in the wrong position can make a join look broken.

Do not reduce scale blindly to make a capture fit. html2canvas’s default scale is based on the device pixel ratio, so output resolution can vary by device. A lower scale can reduce bitmap dimensions and resource demands but may make text and fine details less legible. Validate the PDF at the intended print or viewing size on the devices that matter to your application.

Set window size and scroll offsets for the right reason

windowWidth and windowHeight control the rendering window; width and height control the output canvas dimensions. A larger rendering window can expose more scrollable content, but setting its width can also trigger a different responsive breakpoint. If the PDF should reflect a particular layout, choose the intended layout width rather than automatically using a width that makes the page switch to desktop or mobile styling.

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.

scrollX and scrollY are separate controls: they set the scroll offsets used during rendering. The configuration reference identifies fixed-position elements as a case where these offsets matter. A fixed header, footer, or floating control may otherwise appear at an unexpected position in a capture, especially if you are rendering a region rather than a whole element. Choose offsets based on the desired visual result and test with the page’s actual fixed and sticky behavior; there is no one offset that is correct for every layout.

What html2canvas can—and cannot—reproduce

html2canvas is not a literal browser screenshot tool. Its documentation explains that it reconstructs a rendering from information available in the page’s DOM and that the result may not be 100% accurate to the real representation. This matters for PDF export: a successful canvas can still differ visually from what the browser displayed.

CSS support is property-specific. Consult the project’s supported and unsupported CSS feature list for the properties used on your page; the documented examples of unsupported properties include box-shadow and filter. Check any visual effect that is essential to the document, rather than assuming that all browser-rendered styling will be reproduced. Compare a representative export against the page in each target browser.

Rank #4
Sale
Funny Coding I Know HTML How To Meet Ladies T-Shirt
  • Funny saying for any front-end developer, web developer, computer programmer, computer systems engineer, mobile app developer, software developer, or code lover who likes to code, make funny programming jokes, and take memorable photos.
  • Wear it proudly at International Programmers' Day, school, coding classes, or coding communities! It also makes a funny present for a computer programming lover friend.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Content can also differ because the capture width changes media queries, fonts or images are not ready, or the page uses fixed or sticky elements. Inspect the actual exported canvas and PDF, not only whether the capture promise resolved. Treat fidelity as something to verify against your page and installed html2canvas version.

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

Handle images from other origins

Remote images can taint a canvas when browser security rules prevent the page from reading the image data. A tainted canvas can prevent later operations such as encoding it as a data URL for a PDF. html2canvas documents the useCORS and proxy options for cross-origin image handling, and its proxy documentation describes using a proxy approach.

useCORS is not a way to override the image server’s policy: whether a cross-origin image can be loaded for capture depends on that server’s CORS response headers and your deployment configuration. If you control the image server, verify its headers for the origin serving the page. If not, assess whether a suitable proxy is available and permitted for those assets. Test the exact image hosts and capture environment; a local development result does not establish that production will behave the same way.

Why is my html2canvas image cut off?

  1. Confirm the target. Log the selected element and inspect its scrollWidth, scrollHeight, clientWidth, and clientHeight. If the selector points at a smaller wrapper than the visible document, correct it.
  2. Set the rendering window from the target. Use windowWidth: element.scrollWidth and windowHeight: element.scrollHeight as shown above. This is the documented first fix for blank or clipped output.
  3. Check responsive behavior. If the layout changes after setting windowWidth, choose the width that matches the intended PDF layout and inspect its media-query results.
  4. Inspect fixed and sticky items. If a header or footer is missing, duplicated, or misplaced, test deliberate scrollX and scrollY values for the page’s rendering position.
  5. Check canvas size and device limits. If the element is extremely tall or wide, try a bounded capture. Limits depend on browser, operating system, and hardware, so a value that works on one device is not a reliable guarantee on another.
  6. Verify the canvas before PDF conversion. Check its dimensions and preview it. If it is empty or incorrect, investigate the html2canvas rendering first rather than debugging the PDF layout downstream.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common PDF export failures and fixes

Symptom Likely cause What to check or change
Canvas is blank or clipped The rendering window is smaller than the target’s scrollable dimensions, or the wrong element was selected. Verify the selector and dimensions, then set the window from scrollWidth and scrollHeight.
Capture works on one device but fails on another The requested canvas exceeds practical limits in one browser, operating system, or hardware configuration. Test target environments and capture in bounded regions instead of relying on one enormous bitmap.
Header, footer, or floating control is misplaced Fixed-position rendering uses scroll offsets that do not suit the capture. Adjust and test scrollX and scrollY against the actual fixed-element behavior.
Shadows, filters, or other styles differ The required CSS property may not be supported in html2canvas’s reconstruction. Check the CSS feature list and test the specific styles the PDF needs to preserve.
Remote images disappear or canvas encoding fails A cross-origin image may taint the canvas, or its server may not permit CORS loading. Check image-server headers and deployment settings; evaluate useCORS or the documented proxy option.
Content wraps or changes unexpectedly The rendering-window width triggers different media-query rules. Use the intended layout width and inspect the responsive result before PDF assembly.
Text is too small in the PDF A tall canvas was shrunk to fit a single page, or capture scale is unsuitable. Use multiple pages or sections and validate scale and legibility at the final page size.

Or skip the browser setup

If you need a clean capture without building and maintaining your own browser-rendering workflow, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request can return a PNG, JPEG, WebP, or PDF. For a screenshot response, the basic cURL call is:

Best Value
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
  • Programming Language Lover Code Apparel. App or Web Design and Development Expert Funny Dress. Best Valentines Idea For Coding Lover. HTML Code or Meaning Costume
  • Funny I Know HTML - How To Meet Ladies Computer Programmer Quotes
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Replace the example URL with the page you want to capture. See the ScreenshotNeo API documentation for request options. The same request pattern is available in Python and Node.js:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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}`);
  • Before capture, it accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 shots per month with no card required. Paid plans start at $5 for 3,000 shots; every feature is available on every plan.

Sign up for 1,000 free screenshots a month, with no card required.

FAQ

Does the scroll-dimension setting guarantee a full-page result on every device?

No. It sets a larger rendering window for the target, but canvas limits and rendering behavior vary across browsers, operating systems, and hardware.

Should I use html2canvas for a legal or archival record?

Do not treat the generated PDF as a guaranteed literal record of what a browser displayed. html2canvas reconstructs from DOM information, and its output may differ from the page’s actual browser representation.

Frequently Asked Questions

Does the scroll-dimension setting guarantee a full-page result on every device?

No. It sets a larger rendering window for the target, but canvas limits and rendering behavior vary across browsers, operating systems, and hardware.

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

Should I use html2canvas for a legal or archival record?

Do not treat the generated PDF as a guaranteed literal record of what a browser displayed. html2canvas reconstructs from DOM information, and its output may differ from the page’s actual browser representation.

Quick Recap

Bestseller No. 2
SaleBestseller No. 4
Funny Coding I Know HTML How To Meet Ladies T-Shirt
Funny Coding I Know HTML How To Meet Ladies T-Shirt
Lightweight, Classic fit, Double-needle sleeve and bottom hem
$14.27
Bestseller No. 5
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
Funny I Know HTML - How To Meet Ladies Computer Programmer Quotes; Lightweight, Classic fit, Double-needle sleeve and bottom hem
$19.99

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.