DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk7 min

How to Turn a Webpage into a PDF with JavaScript

Use Puppeteer for server-side PDFs of full webpages, html2pdf.js for browser-side element exports, jsPDF for data-driven documents, or print CSS for visitor-triggered output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the conversion method based on what you need to save: use Puppeteer to render a complete URL on a server, html2pdf.js to export a selected element in a browser, or jsPDF to build a PDF from application data. For a user-triggered printout, use the browser’s print flow with print-specific CSS. These approaches render content differently, so check the resulting PDF for layout, fonts, images, and page breaks.

Choose where the conversion should run

Need Suitable approach Important constraint
Let a visitor print the page or save it through their browser Browser print flow and print CSS Check the experience in the browsers you support; browser behavior can vary.
Export one existing page element in the browser html2pdf.js It runs in a browser, not Node.js, and its canvas-based rendering path can have layout and pagination limitations.
Build a document from application data, text, or drawing primitives jsPDF You manage document layout and pagination; its HTML method has additional dependencies.
Render a complete webpage automatically on a server Puppeteer It controls a browser, so account for page readiness, print CSS, and resources.
Send a URL or raw HTML to a hosted converter HTML2PDF.app Its documentation identifies media mode, resource availability, fonts, and JavaScript timing as output factors.

The options are not interchangeable: browser-side element capture, programmatic PDF construction, and a server-rendered page have different rendering paths. Choose by input (URL, DOM element, or data), execution environment, and the degree of print-layout control you need.

Render a complete webpage with Puppeteer

Puppeteer is the best fit among these libraries when the source is a full page URL and conversion should happen in a Node.js process. Its Page.pdf() method generates output using print CSS by default. If you need screen styles instead, emulate screen media before generating the PDF. Puppeteer’s guide also notes that PDF generation waits for fonts by default.

Install and run

In a Node.js project, install Puppeteer with:

npm install puppeteer

Save this as webpage-to-pdf.js and run it with node webpage-to-pdf.js. Replace the URL and output path as needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Plustek Mobile Scanner S410 Plus - Portable Sheet-Fed Document Scanner - for Windows 7 / 8 / 10 / 11, Featuring Button-Free Scanning with Included OCR Software
  • Digitize on the Go - Connect to your computer via BUS powered, eliminating the need for batteries or external power sources
  • Button Free Scanning Experience - The S410 Plus is an automatic scanning device, no need to push any buttons or click any screens, and automatically processes images and saves them to the designated folders
  • Versatile Paper Handling - Easily scan documents ranging from Letter and Legal sizes to business cards, plastic ID cards, invoices and receipts
  • Ultra compact & Lightweight - Weighing less than 1 lb, lighter than a bottle of mineral water, and its slim design is perfect for portability
  • Work smarter with Plustek Docaction - Built-in OCR allows you convert the files into editable, such as searchable PDF, excel or word. Seamless save to your local computer, FTP and even shared folder
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();

  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', {
      waitUntil: 'networkidle2',
      timeout: 60000,
    });

    await page.pdf({
      path: 'webpage.pdf',
      format: 'A4',
      printBackground: true,
    });
  } finally {
    await browser.close();
  }
})();

The example waits for network activity to settle before printing, but that does not guarantee that every application-specific component or external resource is ready. Use a readiness condition suited to the target page—for example, wait for a known element when the page renders important content asynchronously. Inspect the saved PDF for missing images, fonts, or late-loaded content.

Control print layout

Puppeteer’s PDF options include page-format and page-size controls, CSS page-size preference, and optional header and footer templates. Add only the settings you need; define the intended paper size, margins, and pagination in print CSS when those are part of your document design. Consult the Puppeteer PDFOptions interface for the available options and the PDF generation guide for the documented workflow.

For example, a page can provide print-specific rules that hide navigation or adjust page breaks:

Rank #2
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
@media print {
  nav,
  .screen-only {
    display: none;
  }

  .new-page {
    break-before: page;
  }
}

Put this CSS in the page’s stylesheet, or inject equivalent styles in the Puppeteer page before calling page.pdf(). Check the output with the actual content: a rule that works for one article may split a table or card awkwardly on another.

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

Export one DOM element in the browser with html2pdf.js

Use html2pdf.js when a visitor should export a selected element without sending the rendering job to your Node.js server. The project describes a pipeline from a container to a canvas, image, and PDF, and documents calls such as html2pdf(element) and html2pdf().from(element).save(). It must run in a browser, not Node.js.

Browser example

Include a version-pinned CDN script in an HTML page, then call it after the target element exists. A pinned URL keeps the project version fixed until you deliberately update it; substitute the version you have chosen for VERSION.

Rank #3
CZUR Lens800 Pro Portable 8MP A4 Document Scanner
  • Product Performance: 8MP Camera, 270 DPI, Resolution: 3264*2448
  • OCR Recognition: CZUR's software can digitize documents into Word/Excel/PDF/Editable PDF, recognizing 180+ languages. Please note that Thai, Hebrew, and Arabic are currently not supported. If you need the complete OCR language support list, please feel free to contact us for more details
  • Fast Scanning & Multi-Targeting: Ultra Fast Scanning Speed 1s/page and catch multiple targets (like business cards)
  • Maximal Capture Size A4: CZUR Lens can scan various types of documents; medical forms; certificates; contracts; business cards; letters, etc. up to A4 size (8.27'' *11.69''). Not recommended for very Glossy Paper
  • Multifunctional: CZUR Lens can work both as a scanner and webcam. To fold Lens to make it an HD webcam
<div id="report">
  <h1>Quarterly report</h1>
  <p>Content to export goes here.</p>
</div>
<button id="download-pdf">Download PDF</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/VERSION/html2pdf.bundle.min.js"></script>
<script>
  document.getElementById('download-pdf').addEventListener('click', () => {
    const element = document.getElementById('report');
    html2pdf().from(element).save();
  });
</script>

Replace VERSION with a real version number before deployment; it is intentionally not a package-version claim. The project README provides installation and usage details at html2pdf.js.

Know the rendering trade-off

This route captures the DOM through a canvas-based path rather than asking a browser’s print engine to paginate the page. The project documents cloning and CSS issues. Test representative content, especially long pages, complex layouts, page breaks, and embedded resources, before relying on it for a production export.

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

Build a PDF from data with jsPDF

If the PDF is a designed document assembled from known fields—such as an invoice, report, or receipt—jsPDF lets client-side JavaScript create the document using text and drawing operations. This is often more predictable than trying to convert an arbitrary webpage because you control the layout and pagination directly.

Rank #4
CZUR Shine Ultra Smart Portable Document Scanner, Thin Book Scanner
  • Design and Speed: Work with Windows XP/7/8/10/11 AND macOS 10.13 or later. Not compatible with Android and iOS. Designed for A3&A4(11.69*16.53 & 8.27*11.75 inch) document, any objects smaller than A3 size can be scanned with Ultra-fast scanning speed, about 1 second per page. Perfect device to scan FLAT papers
  • USB Document Camera & Scanner: Work as both a document camera for remote teaching&learning compatible with ZOOM; Goole Meet and a document scanner to scan papers and convert/OCR files. OCR supports 180+ languages for text recognition. Please note that Thai, Hebrew, and Arabic are currently not supported. If you need the complete OCR language support list, please feel free to contact us for more details
  • Patented Flattening Curved Book Page Technology: Shine Ultra applies CZUR’s patented technology to flatten the curved surface after pixel transformation to flattening of the book page (Only suitable for thinner books, ET series is recommended for thicker books)
  • High Resolution & AI Tech: CMOS 13MP (4160*3120, A4≈340 AND A3≈245 DPI) camera. Smart Paging and Auto Cropping; Combine Sides; Stamp Mode; and Multiple Color Modes
  • Height Adjustable & Portable: 2-level height adjustable neck. 90 degree foldable and lightweight 4 lbs with foot pedal for convenient operation

When using jsPDF’s HTML method, account for the project’s documented dependencies on html2canvas and, when passing an HTML string, DOMPurify. Treat HTML conversion as a separate rendering path and verify its output rather than assuming it matches browser printing. See the jsPDF project README for its documented API and setup.

Use browser printing for a visitor-triggered PDF

When the user should choose the browser’s print destination, prepare the page with print-specific CSS and provide a print action. This avoids adding a separate PDF-generation library for a straightforward print workflow. Browser-specific details of the print interaction are not established here, so validate the desired behavior in each target browser rather than assuming one universal flow.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use a hosted converter for URL or HTML input

HTML2PDF.app documents an API that accepts a public page URL or raw HTML and returns a PDF, with conversion performed in headless Chromium. This can avoid operating your own browser-rendering process, but the result still depends on the page’s resources and behavior. Its documentation calls out media mode, fonts, resource availability, and JavaScript timing as factors to check. Program availability and commercial terms are not established here; see its API documentation for the service details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
CZUR ET24 Pro Professional Book Scanner, 24MP Document Camera
  • Flattening Technology Upgraded: ET24 Pro computer scanner applies CZUR’s latest technology that can flatten the 3D curved surface after pixel transformation to complete flattening of the book page
  • Camera Upgraded: 24MP HD camera, 320 DPI, 5696*4272 Resolution. Note: Very glare papers are NOT recommended
  • System Compatibility Upgraded: Document scanner for desktop/laptop, support macOS 10.13 or later AND Windows XP/7/8/10/11, also support Linux system(Only for Ubuntu 20.04 to 24.04)
  • CPU and Graphic Algorithm Library Upgraded: We have upgraded ET24’s CPU and CZUR’s Algorithm Library, ensures ET24’s stable performance; faster Graphic Processing Procedure; High OCR Accuracy
  • HDMI Supported: As a document camera, ET24 Pro support HDMI connection ensures faster & stable data transform

Or skip the browser setup

If you need a webpage screenshot rather than a PDF, ScreenshotNeo is a website screenshot API and MCP server. For a PDF, use Puppeteer or a PDF-generation approach above. ScreenshotNeo’s one-request API returns an image or PDF for a URL. Install no browser automation in your application for this call; get an API key and save the response:

ScreenshotNeo API documentation

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The API can return PNG, JPEG, WebP, or PDF; specify the output format using the documented parameters. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture, and those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Troubleshoot missing or incorrect PDF content

  • Content appears blank or incomplete: Navigation completion alone may not mean the application has rendered its data. Wait for a page-specific selector or other readiness signal, then inspect the output.
  • Images or external resources are missing: Confirm they load in the rendering environment and are available when the PDF is created. Hosted-converter documentation also identifies resource availability as a factor.
  • Fonts look wrong: Ensure the desired fonts have loaded before capture. Puppeteer’s PDF generation waits for fonts by default, but check the output if fonts are external or load late.
  • The PDF uses unexpected styling: Puppeteer uses print CSS by default. If you intend to use screen CSS, emulate screen media before generating the PDF. Also check the page’s @media print rules.
  • Content is cut off or pages break badly: Review paper size, margins, print styles, and page-break rules. For html2pdf.js, test long pages and complex elements because its canvas-based path has different pagination behavior.
  • HTML-to-PDF output differs from the browser: Rendering method matters. A canvas capture, a browser print engine, and a hand-built PDF do not promise identical results; choose the path that best matches the required layout and validate its output.

Choose based on output and operating cost

For a complete page rendered automatically, Puppeteer gives you control over a browser and its PDF options, but you must run and manage that workflow. For an in-browser export of a selected element, html2pdf.js avoids a server conversion step but requires testing its canvas rendering and pagination. For structured documents, jsPDF lets you control the layout directly. A hosted service can offload browser operation, though output remains sensitive to page readiness and resource loading. The most reliable choice is the one tested against the actual pages, fonts, assets, and page lengths your users will export.

Frequently Asked Questions

Can html2pdf.js run in Node.js?

No. The project documents it as a browser package.

Does Puppeteer print screen styles by default?

No. PDF output uses print CSS by default; emulate screen media before PDF generation if you need screen styles.

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

Will a successful page navigation guarantee that all content is in the PDF?

No. Application-specific asynchronous content and external resources may still need to finish loading.

Quick Recap

Bestseller No. 2
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
CZUR Lens800 Pro Portable 8MP A4 Document Scanner
CZUR Lens800 Pro Portable 8MP A4 Document Scanner
Product Performance: 8MP Camera, 270 DPI, Resolution: 3264*2448; Single USB Connection: One single USB connection provides power & data
$99.00

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

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.