The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →To convert a webpage into a PDF with JavaScript, choose where the conversion should run: use html2pdf.js to export an element in the browser, Puppeteer to render a whole page in an automated browser, or jsPDF to build a document from application data. These methods use different rendering paths, so the right choice depends on whether you need an existing page, a selected region, or a deliberately designed PDF.
Choose the right JavaScript approach
| Need | Best fit | Where it runs | Important constraint |
|---|---|---|---|
| Let a visitor export a selected part of the current page | html2pdf.js | Browser | It captures through a container, canvas, image, and PDF pipeline; verify complex layouts and pagination. |
| Save a rendered URL or full page as part of a server workflow | Puppeteer | Node.js controlling a browser | PDFs use print CSS by default; application-specific asynchronous content may need additional readiness checks. |
| Create a designed document from text, data, and drawing operations | jsPDF | Client-side JavaScript | You manage layout and pagination; its HTML method has supporting dependencies. |
| Convert a public URL or raw HTML through a hosted API | HTML2PDF.app | Hosted headless Chromium | Media mode, resource availability, fonts, and script timing can affect output. |
The table describes distinct architectures rather than interchangeable ways to get pixel-identical PDFs. Existing HTML, a selected DOM element, and structured data are different inputs, and each route has its own layout and operational trade-offs.
Export a page element in the browser with html2pdf.js
html2pdf.js is intended for webpage or element conversion in a browser; it does not run in Node.js. Its documented simple call accepts an element, and its chainable worker form lets you specify the source and save the result. This is a practical choice when a user clicks an export button and the content is already rendered in the page.
Install and wire up an export button
One option is to install the package in a browser-based application with a JavaScript bundler:
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 errors#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
npm install html2pdf.js
Then import it and pass the element you want to export:
import html2pdf from 'html2pdf.js';
const exportButton = document.querySelector('#export-pdf');
const content = document.querySelector('#report');
exportButton.addEventListener('click', async () => {
if (!content) throw new Error('PDF content element was not found');
await html2pdf().from(content).save();
});
For a page using script tags rather than a bundler, use a version-pinned CDN URL from the project’s README, then call html2pdf(element) or the worker chain. Pinning a version avoids silently switching to a different project version when the unversioned CDN target changes.
Prepare the content and test the result
- Export a deliberate content container rather than the entire document if navigation, controls, or unrelated page content should not appear.
- Use print-oriented styles when they help organize the exported content, but verify how the canvas-based conversion handles the CSS you rely on. The project documents cloning and CSS issues.
- Test representative long pages, page breaks, embedded resources, fonts, and images. A successful save does not by itself establish that every visual detail survived conversion.
- Keep the user interaction clear: the browser-side package needs the page and target element to be present in the browser when conversion runs.
Generate a PDF from a URL with Puppeteer
For automated rendering, Puppeteer controls a browser and exposes Page.pdf(). Its documentation says the method generates a PDF with the print CSS media type. If the desired output should reflect screen styles instead, emulate screen media before calling page.pdf(). PDF generation waits for fonts by default, but a completed navigation still may not mean that all application-specific asynchronous content or external resources are ready.
Runnable Node.js example
Install Puppeteer in a Node.js project:
npm install puppeteer
Save this as an ES module, for example page-to-pdf.mjs, then run node page-to-pdf.mjs https://example.com. Replace the example URL with the page you are authorized to capture.
Outdated 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 matchPC 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 & 11Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import puppeteer from 'puppeteer';
const url = process.argv[2];
if (!url) {
throw new Error('Usage: node page-to-pdf.mjs https://example.com');
}
const browser = await puppeteer.launch({ headless: true });
try {
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true
});
} finally {
await browser.close();
}
This example uses networkidle2 as a navigation wait condition, not a guarantee that every site-specific widget or delayed component has finished. For pages with known application readiness signals, wait for a selector or other condition that represents the content you need before generating the PDF. Inspect the output for late-loaded images, missing fonts, and print-specific layout changes.
Control media, page size, and pagination
Puppeteer’s PDF options include paper format and page-size controls, CSS page-size preference, and optional header and footer templates. Use the PDFOptions reference to select settings supported by your installed Puppeteer version. Choose a paper format and margins that suit the document, and check page breaks and headers in the produced file rather than assuming the browser layout will paginate as intended.
When screen styling is specifically required, set it before PDF generation:
await page.emulateMediaType('screen');
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });
Use print media when the page’s print stylesheet is the desired document layout. Use screen media only when preserving screen-specific styling is intentional; the two modes can produce different results.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Build a document from data with jsPDF
When the source is application data rather than a finished webpage, jsPDF lets client-side JavaScript place text and drawing primitives into a PDF. This gives you direct responsibility for layout, text placement, and pagination, which is useful for a predictable report or receipt but is not a drop-in renderer for arbitrary websites.
import { jsPDF } from 'jspdf';
const doc = new jsPDF();
doc.setFontSize(18);
doc.text('Monthly report', 20, 20);
doc.setFontSize(12);
doc.text('Revenue: $12,500', 20, 35);
doc.save('report.pdf');
If you use jsPDF’s HTML method to process existing markup, account for its documented html2canvas dependency and, when you provide an HTML string, DOMPurify. Confirm that the resulting layout meets your requirements; direct PDF drawing and browser-rendered HTML do not follow the same rendering path.
Use a hosted conversion service when you do not want to run a browser
HTML2PDF.app documents an API that accepts a public page URL or raw HTML and returns a PDF using headless Chromium. Its documentation warns that media mode, resource availability, fonts, and JavaScript timing can affect the conversion. The technical documentation alone does not establish program availability or commercial terms, so check those separately before building a production dependency.
Or skip the browser setup
For a one-call screenshot or PDF workflow, ScreenshotNeo provides a website screenshot API and MCP server. Its API can return a PDF as well as PNG, JPEG, or WebP; for a rendered page PDF, use the API’s PDF options described in the ScreenshotNeo documentation.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The example saves a WebP screenshot. Configure PDF output using the documented API parameters. ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.
The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 shots, and every feature is on every plan. Sign up for ScreenshotNeo’s free plan.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Check the PDF before relying on it
- Fonts: confirm that the intended font is present and that text has not reflowed unexpectedly. Puppeteer waits for fonts by default, but other routes have different rendering behavior.
- Images and other resources: ensure the page has loaded the resources the document needs, especially when scripts load them asynchronously or they come from external hosts.
- CSS mode: check whether print or screen styling is appropriate for the target layout. Puppeteer uses print styling by default.
- Pagination: inspect page breaks, cut-off content, margins, headers, and footers. A tall page or complex layout may not paginate as expected.
- Output path and permissions: for server-side generation, confirm the process can write to the requested file location and that the resulting file can be opened.
Troubleshoot common conversion problems
The html2pdf.js call fails in Node.js
The project is a browser package, not a Node.js renderer. Run it in the browser where the element exists, or use Puppeteer for server-side page rendering.
The PDF looks different from the webpage
First check which rendering route you chose. Puppeteer uses print CSS by default; screen media can be selected explicitly. html2pdf.js converts through canvas and image stages, so complex CSS and cloned content can behave differently. Review the relevant styles and test with the actual page content.
Images, fonts, or dynamic content are missing
Navigation completion is not necessarily application readiness. Wait for a page-specific selector or signal, verify that external resources are available to the rendering browser, and inspect the generated file. Puppeteer waits for fonts by default during PDF generation, but that does not replace checking resource access or delayed application behavior.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
The document is cut off or breaks in the wrong place
Check the chosen paper size, margins, print styles, and page-break behavior. For a canvas-based conversion, test the target content with html2pdf.js rather than assuming the browser’s native print layout will be reproduced.
A jsPDF HTML conversion has missing styles or unexpected content
Verify the required supporting dependencies are available and that the supplied markup is suitable for its HTML-processing path. If the document is primarily data and text, creating it with jsPDF’s drawing API gives you more direct control over layout.
Frequently asked questions
Can JavaScript convert only one part of a webpage to PDF?
Yes. In the browser, pass the target element to html2pdf.js, for example with html2pdf().from(element).save().
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Can I generate a PDF from a URL without opening it manually?
Yes. Puppeteer can navigate to a URL in a controlled browser and save the rendered page with Page.pdf().
Which method should I use for a report built from data?
Use jsPDF when you want to construct a document from text and drawing operations and are prepared to manage layout and pagination yourself.
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.

