October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
HTML to PDF

How to Convert HTML to PDF with wkhtmltopdf in Node.js

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.

To convert HTML to PDF with wkhtmltopdf in Node.js, install the wkhtmltopdf executable for your deployment operating system, then install the wkhtmltopdf npm wrapper. The npm package does not include the executable: it must be available on PATH, or you must configure the wrapper with its location. The wrapper accepts a URL, HTML string, or readable stream and returns a stream that you can save to a file or send in an HTTP response.

What you need before writing Node.js code

  1. Install the executable. Choose a wkhtmltopdf build for the operating system and architecture where the Node.js process will run. The official downloads page lists platform-specific builds and identifies 0.12.6, released June 11, 2020, as the stable series: wkhtmltopdf downloads.
  2. Install the wrapper. In your project directory, run npm install wkhtmltopdf. The package README documents the wrapper and its executable requirement: node-wkhtmltopdf README.
  3. Check executable discovery. If the executable is not on PATH, configure the wrapper to point to its installed location using the package’s command option. Use a path appropriate to your operating system and deployment; do not assume a development machine’s installation path exists in production.

The project describes its tools as running headlessly without requiring a display or display service. That does not remove the need to install a compatible binary on the machine or container that runs your Node process. Confirm the current downloads page for your target platform and architecture rather than copying an installation command for another system.

Convert a URL to PDF

This example uses the documented wrapper pattern: provide a URL, receive a readable output stream, and pipe it to a file. Run it after installing both the binary and npm package.

const fs = require('node:fs');
const wkhtmltopdf = require('wkhtmltopdf');

wkhtmltopdf('https://example.com', { pageSize: 'A4' })
  .pipe(fs.createWriteStream('page.pdf'))
  .on('finish', () => console.log('PDF written to page.pdf'))
  .on('error', (err) => console.error('PDF stream failed:', err));

Replace the example URL with the page you are authorized to render. The wrapper invokes the external command-line program; it is not a browser implementation bundled into Node. The precise rendering behavior depends on the installed binary and the options it supports.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Tengchi RCA to HDMI Converter, AV to HDMI Adapter
  • RCA Female to HDMI Video Converters Adapter : The cable is used to convert analog composite input to HDMI 1080p output, displayed on a 1080p HD TV/TV/monitor.
  • Input ports: 1xRCA Female (Yellow, White, Red), Output ports: 1xHDMI 1.3 1080p. NOT support 3D and 4K, NOT support HDMI Converts to AV
  • AV to HDMI Converter: Plug and Play, Easy to Install and Operate, Powered by External USB Cable. Note: Please hook up the USB power cable (included) to 5V 1Apower source during use (not included power supply ).
  • Support PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV formats input. For PS2,PS3,Xbox,N64,STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • You Will Get : 1x RCA Female TO HDMI Converter, 1xHDMI cable, 1xUSB cable, 1xUser Manual. ONE YEAR WARRANTY - if you are not satisfied for any reason whatsoever, do not hesitate to contact us .

Convert an HTML string or readable stream

Inline HTML

For a small, trusted document assembled by your application, pass an HTML string instead of a URL:

const fs = require('node:fs');
const wkhtmltopdf = require('wkhtmltopdf');

const html = `<!doctype html>
<html>
  <head><meta charset="utf-8"><title>Invoice</title></head>
  <body><h1>Invoice</h1><p>Invoice number: 1042</p></body>
</html>`;

wkhtmltopdf(html, { pageSize: 'A4' })
  .pipe(fs.createWriteStream('invoice.pdf'));

Use an explicit character encoding in the document and ensure referenced images, stylesheets, and fonts are reachable to the renderer. If the HTML references local files, review the binary’s local-file access settings before enabling them.

Readable stream

The wrapper also accepts a readable stream. This is useful when another part of your application produces HTML incrementally or reads it from a controlled source:

Rank #2
ABLEWE RCA to HDMI,AV to HDMI Converter, 1080P Mini RCA Composite CVBS Video Audio Converter Adapter Supporting PAL/NTSC for TV/PC/ PS3/ STB/Xbox VHS/VCR/Blue-Ray DVD Players
  • RCA to HDMI Converter: Converts analog RCA composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output,displayed on HDTV/Monitor,which can bring back your childhood memories.
  • Plug to Play: ABLEWE Mini RCA to HDMI converter no extra drivers need, just plug and play,easy to use.Please hook up the USB power cable (included) to 5V power source during use.
  • Wide Compatibility: Support source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details.
  • Widely Used:Widely applied to PS2,PS3,Xbox,N64, WII, STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • Attention & Package:Please ensure to connect this rca to hdmi converter to power source to make it work.Package include:1*RCA to HDMI Converter,1*usb power cable(adapter not included),1*User Manual.
const fs = require('node:fs');
const { Readable } = require('node:stream');
const wkhtmltopdf = require('wkhtmltopdf');

const htmlStream = Readable.from([
  '<!doctype html><html><body>',
  '<h1>Streamed report</h1>',
  '</body></html>'
]);

wkhtmltopdf(htmlStream, { pageSize: 'A4' })
  .pipe(fs.createWriteStream('report.pdf'));

For direct file output, the wrapper also documents an output option that writes to a filename. Use either that documented mode or stream piping, and handle failures instead of treating the existence of a destination filename as proof that rendering succeeded.

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

Pass page and rendering options

The wrapper maps wkhtmltopdf command-line options to camel-cased JavaScript names. Options that take no command-line value are represented as booleans; options taking values receive the corresponding value. The package README demonstrates options including pageSize, allow, and repeatable customHeader. Check the exact option name and behavior against the manual for the binary version you actually deploy: wkhtmltopdf command-line manual.

  • Page geometry: choose a supported page size or configure dimensions and margins as appropriate for the document.
  • Headers and footers: use the relevant binary options for repeated page elements; verify the syntax and expected values in the installed version’s manual.
  • JavaScript: JavaScript is enabled by default in the documented options, with a default delay of 200 ms. That delay is a configurable wait, not proof that every asynchronous application has finished rendering.
  • Media and load behavior: consult the manual for media loading and load-error options. A page that loads incompletely or depends on delayed API responses may need a different rendering approach or careful wait configuration.
  • Local files: local-file access is disabled by default unless explicitly allowed. The manual documents --allow and an enable-local-file-access option. Grant access only to the files the conversion job needs.

Because wrapper option mapping and binary capabilities are separate concerns, validate both against the package README and the manual for the deployed binary before relying on less common flags.

Rank #3
GINGIN AV to HDMI Converter, AV to HDMI Adapter Support 720p/1080p for PS1/PS2/PS3/Xbox 360/WII/N64/SNES/STB/VHS/VCR/Blue-Ray DVD Players
  • Composite to HDMI Converter: Converts analog AV composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output, displayed on smart TV, Projector or HD Display, which bring back your old and cherish memories.
  • Plug to Play: This HDMI Converter no extra drivers need, just plug and play,easy to use. Please hook up the USB Power Cable (included) to 5V power source during use. Note: The Video Converters only support converts AV to HDMI, can't converts HDMI to AV.
  • Widely Used: This composite to hdmi adapter is widely applied to PS1, PS2, PS3, Xbox, N64, Wii, STB, VHS, VCR, DVD Players and other devices with standard composite AV input. Note: It can only be used when PS2 is set to RGB output.
  • Wide Compatibility: This Video Audio Converter Adapter supports source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details. Important Note: This converter can't improve video quality!
  • Attention & Package: Please ensure to connect this av hdmi converter to power source to make it work. Package include: 1*AV to HDMI Adaptor, 1*USB Power Cable(adapter not included), 1*User Manual.

Write the PDF safely in a Node application

When rendering on behalf of an HTTP request or background job, treat conversion as an external process with its own failure modes. Save to a temporary or job-specific destination, wait for the stream to complete, and only then expose the finished PDF. Avoid sharing a fixed output path across concurrent requests.

For lower-level process control, Node’s child_process.execFile() takes an executable and an argument array and does not spawn a shell by default. Its callback reports process errors and output. This can be useful when you need explicit command arguments or process-level error handling, but it does not change wkhtmltopdf’s security characteristics. See the Node.js execFile documentation.

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

Security warning for user-submitted HTML

Do not run wkhtmltopdf on untrusted HTML and JavaScript. The wkhtmltopdf project warns that doing so can lead to complete server takeover. Its status page recommends sanitizing user-submitted HTML and JavaScript and considering Mandatory Access Control tools such as AppArmor or SELinux: wkhtmltopdf status.

Rank #4
BD&M RCA to HDMI Converter, AV to HDMI Adapter Supports PAL/NTSC for PS2, PS3, Xbox, VHS, VCR, DVD Players
  • Convert RCA to HDMI Instantly – BD&M RCA to HDMI Converter easily converts analog RCA/composite AV signals to HDMI output, allowing you to connect older devices to modern HDTVs, monitors, and projectors with clear video and audio quality.
  • Wide Device Compatibility – Supports VHS players, VCRs, DVD players, camcorders, retro gaming consoles, and more including PS1, PS2, PS3, Xbox, N64, Wii, and older AV devices with standard RCA output.
  • 1080P HDMI Output – Advanced signal processing delivers stable and sharp video output with support for 720P/1080P HDMI resolution, improving compatibility with modern TVs and displays.
  • Plug & Play Setup – No drivers or software required. Simply connect the RCA cables, HDMI cable, and included USB power cable for quick and easy installation in minutes.
  • Compact & Reliable Design – Lightweight mini converter design makes it perfect for home entertainment setups, retro gaming, travel, or converting old media collections while maintaining stable performance.

Sanitization is not a substitute for isolating the renderer. If your product accepts documents from users, limit what the conversion process can read and access, run it with the least privileges practical, and apply operating-system containment appropriate to your environment. In particular, do not grant broad local-file access just to make one document’s assets load.

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

When wkhtmltopdf may not fit

The project suggests considering other tools for specific workloads: WeasyPrint or the commercial tool Prince for report generation with controlled HTML, and Puppeteer or its wrappers for converting sites that use dynamic JavaScript. These are project recommendations for those use cases, not a universal ranking. Select based on whether input is controlled, how much the page relies on dynamic JavaScript, how closely output must match a target browser, which deployment platforms are supported, and what isolation your service requires.

If your goal is a screenshot image or PDF from a public URL rather than running the wkhtmltopdf binary in your Node service, ScreenshotNeo is a separate website screenshot API and MCP server. It does not replace this local conversion workflow for arbitrary HTML strings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Convert to PDF
  • Export or Convert Text, HTML, PNG, JPG, or Camera Pictures to PDFs
  • Unlimited use
  • No ads
  • No personal data taken
  • GDPR compliant

Troubleshooting common failures

Symptom Likely cause What to check
Executable not found or spawn error The npm wrapper is installed but the wkhtmltopdf binary is absent or not discoverable. Install the binary for the runtime OS and architecture, confirm it is available on PATH, or configure the wrapper’s command path.
Works locally but fails in deployment The server or container has a different operating system, architecture, or binary installation. Install and verify the executable in the actual deployment image; use the official downloads page to check build availability for that target.
PDF has missing images, fonts, or styles Resources may be inaccessible from the rendering process, or the page may not have completed loading. Check resource URLs, network access, media-loading behavior, and the manual’s wait/load options. For local assets, review the local-file access policy and allow only necessary paths.
Content is blank or incomplete The page may rely on asynchronous JavaScript or take longer to render than the configured wait. Check whether JavaScript is enabled, adjust the documented delay or other supported load behavior, and consider a browser-oriented renderer for highly dynamic sites.
Option appears ignored The JavaScript option name may not map as expected, or the installed binary may not support the behavior assumed. Confirm camel-case mapping in the wrapper README and exact flag semantics in the manual for the installed version.
Conversion hangs or returns an error A page load, inaccessible dependency, or process failure may prevent normal completion. Capture and inspect stream/process errors, verify the URL and dependencies are reachable from the server, and configure the documented load behavior for the binary version.
Unsafe document can access server resources Untrusted HTML or JavaScript is being rendered without sufficient sanitization and isolation. Stop processing untrusted content in that configuration; sanitize input and isolate the renderer with platform controls such as AppArmor or SELinux, as the project warns.

Or skip the browser setup

If your task is to capture a URL as a PDF or screenshot without installing and managing a local renderer, ScreenshotNeo offers a single-request API. This example follows its documented API pattern; the API key is available through its account flow. See the ScreenshotNeo API documentation for parameters and response details.

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

ScreenshotNeo accepts cookie or 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 response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free 1,000 screenshots per month, with no card required.

Version and deployment considerations

The official downloads page lists wkhtmltopdf 0.12.6, released June 11, 2020, as the stable series. Binary availability varies by operating system and architecture, so confirm a compatible build for the environment where Node runs. The project’s status page describes future work as dependent on maintainer time and volunteer contributions, without a promised release deadline. Avoid assuming a particular release cadence or that a build is available for every platform.

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

Frequently Asked Questions

Does npm install wkhtmltopdf install the PDF converter itself?

No. It installs the Node.js wrapper; the wkhtmltopdf executable must be installed separately and discoverable by the wrapper.

Can I use wkhtmltopdf without a graphical desktop?

The project says the tools run headlessly and do not require a display or display service.

What is the current stable wkhtmltopdf version listed by the project?

The official downloads page lists version 0.12.6, released June 11, 2020.

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.

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

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
Windows Errors? Fix Them Before They SpreadFree repair 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.