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

Use html2canvas’s onclone callback to reveal hidden content in the temporary document used for rendering. Your live page stays unchanged, while the cloned element receives a usable display value, visibility, and layout before the canvas is created. Then pass that canvas to jsPDF. This is the safest pattern for elements hidden with display: none; the exact display mode must match the component’s layout.

Why hidden elements disappear

html2canvas does not capture a literal browser screenshot. It reconstructs an image from the DOM and CSS information it can read. An element with display: none has no layout box, so there is nothing for the renderer to paint. The same problem can occur when a parent is collapsed or when application state removes the element from the render tree. CSS support and browser resource restrictions also affect the result; consult the html2canvas documentation for its rendering limitations.

visibility: hidden and opacity: 0 are different cases: they may preserve layout, but they still prevent useful visible output. Off-screen positioning, zero dimensions, and framework-controlled conditional rendering require their own fixes. First determine how the element is hidden in the computed styles and DOM.

The recommended solution: reveal the cloned document

html2canvas provides onclone, called after it creates the document clone and before rendering. You can modify that clone without changing the source page. Query the cloned document, set the target’s display mode and visibility, and make sure the capture root contains the target.

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
  1. Choose a capture root that includes the hidden element.
  2. In onclone, query the clone rather than the live document.
  3. Restore the component’s intended display mode, such as block, flex, or grid.
  4. Set visibility to visible and repair any collapsed parent layout.
  5. Allow images, fonts, and other asynchronous content to finish before exporting.
const root = document.querySelector('#capture');

html2canvas(root, {
  onclone: (clonedDocument) => {
    const target = clonedDocument.querySelector('#hidden-content');
    if (!target) return;

    target.style.display = 'block';
    target.style.visibility = 'visible';
    target.style.opacity = '1';
  }
}).then((canvas) => {
  // Add canvas output to your jsPDF document here.
});

block is only an example. A flex component may need display: flex, and a grid component may need display: grid. If the target is inside a hidden parent, reveal that parent as well. If the element is outside #capture, changing it in the clone cannot add it to the canvas.

The callback and its “modify the cloned document without affecting the original” behavior are documented in the html2canvas configuration options.

Complete jsPDF export example

The following browser example captures a report, reveals a normally hidden appendix only in the clone, and inserts the resulting image into a PDF. Install compatible versions of html2canvas and jspdf using your project’s package manager, or load their browser bundles as appropriate for your application.

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

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

  const canvas = await html2canvas(root, {
    backgroundColor: '#ffffff',
    useCORS: true,
    onclone: (clonedDocument) => {
      const appendix = clonedDocument.querySelector('#hidden-content');
      if (appendix) {
        appendix.style.display = 'block';
        appendix.style.visibility = 'visible';
        appendix.style.opacity = '1';
      }

      // Reveal a collapsed wrapper if your UI hides one.
      const wrapper = clonedDocument.querySelector('#appendix-wrapper');
      if (wrapper) {
        wrapper.style.display = 'block';
        wrapper.style.height = 'auto';
        wrapper.style.maxHeight = 'none';
        wrapper.style.overflow = 'visible';
      }
    }
  });

  const image = canvas.toDataURL('image PNG');
  const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
  const pageWidth = pdf.internal.pageSize.getWidth();
  const pageHeight = pdf.internal.pageSize.getHeight();
  const margin = 10;
  const printableWidth = pageWidth - margin * 2;
  const printableHeight = (canvas.height * printableWidth) / canvas.width;

  let remaining = printableHeight;
  let y = margin;
  pdf.addImage(image, 'PNG', margin, y, printableWidth, printableHeight);
  remaining -= pageHeight - margin * 2;

  while (remaining > 0) {
    pdf.addPage();
    y = margin - (printableHeight - remaining);
    pdf.addImage(image, 'PNG', margin, y, printableWidth, printableHeight);
    remaining -= pageHeight - margin * 2;
  }

  pdf.save('report-with-appendix.pdf');
}

document.querySelector('#export')?.addEventListener('click', exportPdf);

Use the image format and API signatures supported by the jsPDF version installed in your project. jsPDF’s type declarations expose html2canvas-related options, but repository master declarations are not a guarantee for every released runtime; verify against the version in your lockfile and its documentation at jsPDF’s type definitions.

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

For long documents, the example scales one tall canvas across pages. That is simple but can produce very large canvases and text that is less searchable than native PDF text. A paginated capture strategy or jsPDF’s HTML workflow may be preferable for large reports.

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⁴

Alternative: temporarily reveal the live element

You can show the element in the real DOM, wait for layout, capture it, and restore its prior styles in a finally block. This can work when application code cannot be represented correctly in a clone, but it may flicker, trigger observers, alter focus, or expose content briefly to users. It also requires reliable waiting for fonts, images, and component updates.

async function captureByTemporarilyShowing(root, target) {
  const old = {
    display: target.style.display,
    visibility: target.style.visibility,
    opacity: target.style.opacity
  };
  try {
    target.style.display = 'block';
    target.style.visibility = 'visible';
    target.style.opacity = '1';
    await new Promise(requestAnimationFrame);
    return await html2canvas(root);
  } finally {
    target.style.display = old.display;
    target.style.visibility = old.visibility;
    target.style.opacity = old.opacity;
  }
}

This is an application-level technique, not a canonical html2canvas recipe. Prefer onclone when the cloned layout can represent the component correctly.

What not to use

ignoreElements and data-html2canvas-ignore exclude nodes from rendering. They cannot make a hidden node appear. Remove those exclusions from the capture subtree when the content is intended for the PDF, then handle visibility with clone styles.

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.

Hidden-state checklist

  • display: none: assign an appropriate display mode in onclone.
  • visibility: hidden: set visibility: visible; inspect parents for the same rule.
  • opacity: 0: set opacity to 1 in the clone if the content should be visible in the export.
  • Collapsed parent: restore height, max-height, overflow, and display on the parent.
  • Conditional framework rendering: if the node is not present in the cloned DOM at all, render an export-only version inside the capture root; a style change cannot revive a node that was never rendered.
  • Zero-size content: give the element dimensions and check computed styles in the clone.
  • Wrong selector: log or assert that clonedDocument.querySelector() returns a node.

Images, fonts, iframes, and cross-origin limits

Cross-origin images can taint a canvas or fail to load unless the server supplies suitable CORS headers and the request is configured correctly. useCORS: true is not a bypass for a server that denies cross-origin access. Proxied resources may be required. Cross-origin iframes have additional browser security restrictions, and html2canvas cannot reproduce every browser-rendered CSS feature. Check the project’s resource and browser limitations before treating a missing image or iframe as a visibility bug.

Wait for content that is inserted asynchronously. In application code, await image decoding where possible, ensure web fonts have loaded, and only then call html2canvas. A visible element with unfinished resources can still produce a blank or incomplete area.

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

Troubleshooting common failures

The element is still missing

Confirm that the target is inside the node passed to html2canvas. Then verify the selector against clonedDocument, not document. Inspect every hidden ancestor and restore its layout. A component removed by conditional rendering must be rendered into the capture subtree first.

The layout is broken after revealing it

Replace block with the original component mode, such as flex or grid. Reapply required width, height, position, and overflow rules. Inline styles in the clone can override stylesheet rules without changing the live page.

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

The PDF contains a blank image or security error

Look for cross-origin images, fonts, and iframes. Check response headers, CORS configuration, and whether a proxy is needed. A browser canvas cannot freely read pixels from an origin that has not granted access.

Only part of a long page appears

Check the capture root’s dimensions and overflow rules. Ensure lazy-loaded images are loaded before capture. Consider capturing sections separately and adding each section to jsPDF rather than creating one enormous canvas.

jsPDF rejects an option or method

Compare the code with the installed jsPDF release, not only the current repository declaration. APIs and option behavior can vary by version; pin compatible package versions and consult the release documentation.

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

Performance and quality decisions

  • Canvas scale: higher pixel density improves sharpness but increases memory use and PDF size.
  • Capture scope: pass the smallest root that contains the intended report and revealed content.
  • Pagination: section-by-section captures reduce peak memory and avoid browser canvas limits.
  • Assets: optimize oversized images and wait for fonts instead of repeatedly retrying captures.
  • Accessibility: a canvas-based PDF is an image; it does not preserve selectable text, semantic headings, or document structure automatically.

Or skip the browser setup

If your goal is a clean screenshot or PDF of a URL rather than a client-side DOM export, ScreenshotNeo provides a single request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; you can turn each cleanup step off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether it was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

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

For browser-side hidden HTML, you still need the clone technique above. For URL capture, this is the one-call starting point:

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 output and options. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can html2canvas capture an element with display: none directly?

No. Give it layout and visibility in the cloned document through onclone, or use a carefully managed live-DOM reveal.

Does onclone change my page?

No. Changes made to the callback’s cloned document are used for rendering and do not modify the original source document.

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.

Why does changing the child’s display have no effect?

A hidden or collapsed ancestor, a missing capture root, or conditional rendering may still prevent layout. Inspect the entire cloned subtree.

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.