Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use jsPDF’s html() method and pass the actual DOM element. It renders that element through html2canvas and then writes the result to a PDF. A minimal export looks like this:
import { jsPDF } from "jspdf";
const element = document.querySelector("#content-to-export");
if (!element) throw new Error("PDF content element was not found");
const doc = new jsPDF({ format: "a4", unit: "mm" });
doc.html(element, {
x: 10,
y: 10,
width: 190,
callback: (pdf) => pdf.save("document.pdf"),
});
The rest of the work is choosing a page size and width that match your layout, loading the required dependencies, and checking the generated pages for CSS, images, fonts, and page-break issues.
What the jsPDF div-to-PDF path actually does
doc.html(element, options) does not embed the browser’s live layout engine in the PDF. jsPDF uses html2canvas to construct a canvas representation of the selected DOM node and places that rendered output in the PDF. This distinction explains why a page that looks perfect in Chrome can need adjustment in the exported file.
Pass a DOM element, not a selector string:
const element = document.querySelector("#content-to-export");
if (!element) {
throw new Error("PDF content element was not found");
}
const doc = new jsPDF({ format: "a4", unit: "mm" });
doc.html(element, {
x: 10,
y: 10,
width: 190,
callback: (pdf) => pdf.save("document.pdf"),
});
The callback runs after rendering has finished. Calling save() there prevents a partially rendered document from downloading.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match#1 Best Overall
- 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
Set up jsPDF and its HTML renderer
Install and import jsPDF
In an npm-based browser application, install jsPDF and import its constructor:
npm install jspdf
import { jsPDF } from "jspdf";
jsPDF’s HTML method depends on html2canvas. When you provide an HTML string rather than an element, the documented path also uses DOMPurify. The library can dynamically load optional dependencies, but bundlers may put them in separate chunks. Verify that your installed jsPDF build includes the HTML support and that your bundler can resolve the optional packages.
Use a browser, not Node.js, for this method
html2canvas relies on browser APIs and is intended for modern evergreen browsers, including current Chrome/Chromium, Firefox, and Safari. It is not a Node.js renderer. For server-side generation, use a browser automation or server PDF workflow instead of trying to run this DOM method without a browser.
Build a complete browser example
This page includes a button, a target div, and a few practical safeguards. The target can contain headings, paragraphs, lists, tables, and images that the renderer can access.
<button id="download-pdf" type="button">Download PDF</button>
<div id="content-to-export">
<h1>Project report</h1>
<p>This content is exported from the selected div.</p>
<ul>
<li>The browser renders this element first.</li>
<li>html2canvas reconstructs the supported visual styles.</li>
</ul>
</div>
<script type="module">
import { jsPDF } from "jspdf";
const button = document.querySelector("#download-pdf");
const element = document.querySelector("#content-to-export");
button.addEventListener("click", async () => {
if (!element) {
throw new Error("PDF content element was not found");
}
button.disabled = true;
try {
const doc = new jsPDF({
format: "a4",
unit: "mm",
orientation: "portrait",
});
await doc.html(element, {
x: 10,
y: 10,
width: 190,
windowWidth: element.scrollWidth,
callback: (pdf) => pdf.save("project-report.pdf"),
});
} finally {
button.disabled = false;
}
});
</script>
The exact promise behavior depends on your installed jsPDF build and typings. The documented worker interface supports promise-style chaining and save(); if your version exposes only a callback, keep the callback and do not assume await doc.html() is available. Check the version’s bundled typings and documentation.
Choose page size, margins, and width
The PDF’s units and page format are independent of CSS pixels. In the example, A4 is measured in millimeters, with a 10 mm left and top position and a 190 mm content width. That width leaves approximately 10 mm on the right of an A4 portrait page.
Common layout decisions
- Page format: use
format: "a4"for an A4 document or choose another jsPDF-supported format required by your audience. - Orientation: use
orientation: "landscape"for wide tables and dashboards; portrait is usually better for reports. - Coordinates:
xandyplace the rendered content on the page in the unit selected byunit. - Width: set
widthto the printable content width rather than the full page width when you need margins. - Long content: inspect every generated page. A large div can span pages, and a width that works for a short sample can expose awkward breaks in a full report.
Make the capture layout explicit
html2canvas reads the DOM under a particular viewport and scroll state. You can make those conditions reproducible with options such as windowWidth, windowHeight, scrollX, scrollY, and scale:
Rank #2
- 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⁴
doc.html(element, {
x: 10,
y: 10,
width: 190,
windowWidth: 1280,
windowHeight: 900,
scrollX: 0,
scrollY: 0,
scale: 2,
callback: (pdf) => pdf.save("report.pdf"),
});
A higher scale can make text and images look sharper, but it also increases canvas memory use. Treat these as rendering choices, then open the PDF at its intended size rather than judging only the on-screen canvas.
Free tools Windows power users keep installed
One-click scans. No signup required.
Control what appears in the exported div
Hide buttons and other controls
Mark elements that should never enter the clone with data-html2canvas-ignore:
<button data-html2canvas-ignore>Print controls</button>
For dynamic rules, html2canvas provides ignoreElements. A clone callback can also alter the copied document before rendering, for example by adding an export-only class:
doc.html(element, {
x: 10,
y: 10,
width: 190,
html2canvas: {
ignoreElements: (node) => node.matches?.(".no-pdf"),
onclone: (clonedDocument) => {
clonedDocument.documentElement.classList.add("pdf-export");
},
},
callback: (pdf) => pdf.save("report.pdf"),
});
Keep the callback and ignore predicate compatible with the html2canvas version installed in your project; option names and typings should be checked against that version.
Prepare responsive CSS
A responsive div may change columns, font sizes, or wrapping when the renderer uses a different viewport. Give the export target a stable width or apply an export class that defines the intended layout. Avoid relying on a horizontally scrolled container: capture the full element and set windowWidth deliberately.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsImages, fonts, iframes, and browser security
Images and CORS
Images generally must be same-origin or available through permitted cross-origin loading. html2canvas exposes useCORS and proxy options, but neither bypasses browser content policy or an image server’s access controls.
doc.html(element, {
x: 10,
y: 10,
width: 190,
html2canvas: {
useCORS: true,
},
callback: (pdf) => pdf.save("with-images.pdf"),
});
Configure the image host to send an appropriate CORS header, or copy the asset to an origin your page can access. A proxy is an infrastructure choice, not a way to defeat authentication or cross-origin restrictions.
Rank #3
- 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.
Iframes
Same-origin frames can be traversed recursively. Cross-origin frames cannot be read by the renderer, and sandboxed frames without allow-same-origin are likewise inaccessible. If a frame is blank in the PDF, export its content separately or move the required data into the same-origin document.
Unicode and custom fonts
jsPDF’s standard PDF fonts have limited character coverage. Accented characters, non-Latin scripts, emoji, and some symbols may be missing or garbled. Embed a TTF font containing the required glyphs and register it with jsPDF before rendering. The font must also be available to the page when html2canvas computes the layout.
Why CSS can differ from the browser
html2canvas does not take a literal screenshot of the browser compositor. It reconstructs a visual representation from DOM information and supports only the CSS properties it understands. Complex filters, blend modes, unusual positioning, generated content, and other advanced effects can therefore differ or disappear.
For predictable output:
- Use ordinary flow layout, explicit widths, and stable line heights in the export version of the CSS.
- Wait until web fonts and images have loaded before calling
doc.html(). - Remove animations and transitions from the export class.
- Test tables, flex or grid combinations, sticky elements, gradients, and transformed nodes in the actual PDF.
- Compare the PDF at 100% zoom and on paper if it will be printed.
Long documents and page breaks
A single tall div is convenient, but it does not guarantee ideal pagination. Headings can be separated from the paragraph that follows, rows can split, and a large canvas can consume substantial memory.
Use print-oriented CSS where the renderer supports it, keep sections reasonably sized, and inspect all pages. For difficult reports, divide the document into logical sections and render them with deliberate positions or pages instead of assuming one automatic pass will produce a finished book.
Do not treat the width option as a page-break setting. It controls layout scale; page sizing and breaks still need verification in the output.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
element is null |
The selector ran before the DOM existed or the ID/class is wrong. | Run after the page has loaded, query the correct element, and throw a clear error before creating the PDF. |
| Nothing downloads | Rendering has not completed, an exception was swallowed, or the callback is never reached. | Use the documented callback or worker promise for your jsPDF version, log errors, and call save() only after completion. |
| CSS or spacing looks wrong | html2canvas supports a reconstructed subset of CSS, or the viewport changed responsive rules. | Set windowWidth, add export CSS, simplify unsupported styling, and inspect the PDF. |
| Images are blank | Cross-origin policy, missing CORS headers, or images not loaded yet. | Wait for loading, use same-origin assets, configure the image host for CORS, and use useCORS where appropriate. |
| An iframe is empty | The frame is cross-origin or sandboxed without same-origin access. | Export accessible content separately or make the required data same-origin. |
| Text is clipped or wraps differently | Width, scale, viewport, or font metrics differ from the browser view. | Set the PDF width and viewport explicitly, load the intended font, and test at the final page size. |
| Characters are missing | The built-in PDF font lacks the glyphs. | Embed and register a TTF font containing every script and symbol you need. |
| Browser freezes on a large report | A high-resolution canvas requires too much memory. | Reduce scale, limit the capture area, split the report, or move generation to a browser-based server workflow. |
Security and data handling
If you pass an HTML string instead of a DOM element, sanitize untrusted content before rendering; the documented jsPDF path uses DOMPurify for that case. A DOM element is not automatically safe merely because it is on your page: user-provided text, URLs, and embedded resources still need the same validation and access controls as the rest of your application.
Rank #4
- 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
When this browser method is the right choice
| Requirement | jsPDF html() fit |
|---|---|
| Export a visible section after a user click | Good fit: pass the selected element directly. |
| Use the exact browser CSS pixel-for-pixel | Not guaranteed: html2canvas reconstructs supported styles. |
| Run without a browser, in Node.js | Not a fit for this html2canvas-based path. |
| Include arbitrary cross-origin frames or images | Restricted by browser security and the remote server’s CORS policy. |
| Produce a long, publication-quality document | Possible, but page breaks, memory use, fonts, and every asset need explicit testing. |
Or skip the browser setup
If you need a clean screenshot or PDF of a web page rather than a user’s local div, ScreenshotNeo provides a website screenshot API and MCP server. It accepts cookie and consent banners before capture 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, and the response identifies the result with X-Page-Verdict and X-Billed headers.
One GET request returns PNG, JPEG, WebP, or PDF. The API also supports full-page capture with lazy images, CSS-selector element capture, custom CSS and JavaScript, device and viewport settings, PDF paper size and margins, cookies and headers, waiting rules, request blocking, geolocation and timezone, transparent backgrounds, resizing, caching, signed links, asynchronous jobs, webhooks, bulk capture, and a usage API. AI agents can use the MCP tools take_screenshot, get_page_info, and capture_pdf from Claude, Cursor, or another MCP client.
For a PDF or image of a URL, the cURL call is:
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 all parameters. Python:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
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, and yearly billing gives two months free. Create a free ScreenshotNeo account to try it.
FAQ
Can I pass a CSS selector directly to doc.html()?
No. Query the selector first with document.querySelector(), verify that it returned an element, and pass that element to jsPDF.
Does this preserve selectable PDF text?
The html2canvas-backed route renders through a canvas representation, so you should not assume the result has the same selectable, searchable text structure as a PDF built from text primitives. Check the output required by your workflow.
Why does a hidden div export badly?
Elements with display: none have no layout for html2canvas to measure. Render the element in the document, or create an export-only layout that is visible to the renderer but outside the user’s normal view.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.

