# HTMLPDF 0.2.0 — installation and usage HTML and CSS to PDF in JavaScript. Includes a command-line tool, a JavaScript library, compiled ESM modules, TypeScript source, tests, fonts, and sample PDFs. No browser engine, native addon, Word, or LibreOffice is required. ## Quick start (Windows, macOS, Linux) Install Node.js (the package requires >=18; use a supported release). Verify `node --version`. Extract the complete ZIP, then open a terminal in the extracted `htmlpdf-0.2.0` directory, not inside the ZIP preview. Keep `dist/` and `fonts/` together. Paths with spaces must be quoted. Commands work in PowerShell and POSIX shells unless noted. node dist/cli.js --help node dist/cli.js examples/sample.html -o output/sample.pdf Compiled code is included: npm install and npm run build are NOT needed to run these commands. Without -o, output is written next to the input with a .pdf suffix. Parent output directories are created. Existing output files are overwritten. Never use the input filename as the output; avoid same-basename inputs sharing an output folder. ## CLI examples node dist/cli.js "documents/report.html" -o "output/report.pdf" node dist/cli.js documents/ -o pdfs/ node dist/cli.js page.html --size "A4 landscape" --margin "15mm 20mm" node dist/cli.js page.html --css print.css --fonts "my-fonts" node dist/cli.js page.html --http Folder mode reads .html, .htm, and .xhtml files, case-insensitively, immediately inside the folder (not recursively), in sorted order, one conversion at a time. An empty folder produces no files and exits successfully. Multiple input paths are supported: use an existing output directory or a trailing slash for -o so they do not all overwrite one filename. Options: - -o, --output PATH: output file or directory; a new directory for a single file must have a trailing slash. Folder input treats PATH as a directory. - --size SIZE: A4, letter, legal, A3, A5, "A4 landscape", or "210mm 297mm". - --margin VALUE: CSS length/shorthand such as 20mm or "1in 0.75in". - --css FILE: extra stylesheet applied after document styles. - --fonts DIR: add a font directory; repeat for multiple directories. - --system-fonts: also scan installed system fonts. - --http: opt in to HTTP(S) image, stylesheet, and font requests. This does not turn the input argument into a website URL; save the HTML to disk first. - --no-outline: omit heading bookmarks. - --no-compress: disable PDF stream compression, useful for debugging. - -q, --quiet: only print errors; hides warnings and font substitutions too. - -h, --help: print usage. There is no --version flag in this release. Exit codes: 0 success (including empty folders), 1 conversion/input failure, 2 invalid arguments. Setup errors such as an unreadable --css file can also terminate the process. Batch results can include successful PDFs and failures. ## Install the library into another project From your application directory, use an absolute path to the extracted package: npm install "/absolute/path/htmlpdf-0.2.0" On Windows, for example: npm install "C:/Tools/htmlpdf-0.2.0". This uses the local package, not an unrelated npm registry release. Keep that directory available when npm links it locally. In an ESM .mjs file: import { convertFile, convertHtml } from 'htmlpdf/node'; import { writeFile } from 'node:fs/promises'; const result = await convertFile('report.html', 'output/report.pdf'); console.log(result.pages, result.warnings, result.fontSubstitutions); const { pdf } = await convertHtml('

Hello

', { pageSize: 'A4', margin: '15mm' }); await writeFile('hello.pdf', pdf); Run with `node app.mjs`. Alternatively import directly from ./dist/node.js when your script is in the extracted package. Optional CLI registration: `npm link` inside the package makes `htmlpdf` available on your npm executable PATH; the direct node command works without this global step. ## Browser API Serve the extracted files over HTTP(S); do not open an ES-module demo with file://. Use a bundler or import the core dist/index.js module directly. The core does not automatically load fonts. Supply font bytes and a resource loader: import { convert, FontRegistry } from './dist/index.js'; const fonts = new FontRegistry(); const response = await fetch('./fonts/LiberationSans-Regular.ttf'); fonts.addFile(new Uint8Array(await response.arrayBuffer()), 'pack'); const result = await convert('

Hello

', { fonts, pageSize: 'A4', margin: '15mm', loadResource: async () => null }); const url = URL.createObjectURL(new Blob([result.pdf], {type:'application/pdf'})); const link = document.createElement('a'); link.href = url; link.download = 'hello.pdf'; link.textContent = 'Download PDF'; document.body.append(link); // Revoke url when replacing/removing the link, after download is finished. For images and stylesheets, provide baseUrl and a loader returning Uint8Array or null. Restrict permitted resources in that loader. Browser HTTP fetches are subject to CORS. Use a Web Worker to keep parsing and layout off the UI thread. WOFF2 needs a Brotli decoder supplied with setBrotliDecoder() in browsers; Node uses its built-in zlib decoder. TTF, OTF, and WOFF do not need that extra decoder. ## Fonts and resource behavior The download automatically loads Liberation Sans/Serif/Mono, Carlito, Caladea, DejaVu Sans/Serif, and NanumGothic in Node. These are substitutes, not Microsoft's fonts. The optional fonts-cjk directory mentioned in the upstream README is NOT included. Supply your own appropriately licensed fonts for additional scripts. Font coverage does not imply complex-script shaping or RTL support. HTMLPDF_FONT_DIRS adds directories: semicolon-separated on Windows, colon-separated on macOS/Linux. In PowerShell: $env:HTMLPDF_FONT_DIRS = 'C:\Fonts;D:\TeamFonts' In a POSIX shell: export HTMLPDF_FONT_DIRS='/opt/fonts:/home/me/fonts' You can also use --fonts, --system-fonts, @font-face, or FontRegistry.addFile(). Local references resolve relative to the HTML file; data URLs are supported. The Node loader can read files accessible to the process. Use trusted documents or a restricted custom loader/environment. Network resources are disabled unless http:true / --http is supplied. That option sends resource requests to the referenced servers. Scripts in the HTML are not executed. No live webpage capture. ## How conversion works and its limits The engine parses HTML, resolves CSS and fonts, builds and lays out boxes, splits content into pages, then writes PDF 1.7 text, vectors, images, links, and embedded font subsets. It is an independent renderer, not Chromium. It supports blocks, floats, flexbox, grid, tables, print CSS, page breaks, SVG, PNG/JPEG/GIF/BMP, heading outlines, and page metadata. @page size/margin rules override API/CLI page settings. GIF uses the first frame; form controls are static. Unsupported: JavaScript, multi-column layout, RTL and complex-script shaping, hyphenation, ::first-letter/::first-line, filters/blend modes, WebP, and splitting a single tall table row or image across pages. Review representative PDFs; source README benchmark figures are historical author reports, not a fidelity guarantee. ## Troubleshooting - node not found: install Node, reopen the terminal, check node --version. - Cannot find dist/cli.js: extract all files and cd into htmlpdf-0.2.0 first. - Missing assets: preserve relative paths, check case, and inspect warnings. Remote assets need explicit --http; offline conversion cannot fetch them. - Wrong fonts/page breaks: inspect fontSubstitutions, add matching fonts, and check print styles/@page. Missing characters need an appropriate font. - Blank content: JavaScript-generated content must be saved as static HTML. - Slow/large output: reduce image sizes or split the document; all layout and PDF data are buffered in memory. There is no universal engine file-size limit. - Permission denied: choose a writable output folder and close locked PDFs. ## Build and test (optional, developers only) npm ci npm run build npm test These steps download development dependencies; normal conversion has zero npm runtime dependencies. Auxiliary Python comparison scripts in tools/ are developer utilities, not CLI requirements; they can need Playwright/Chromium, PDF utilities, and Python dependencies. See README.md and RELEASE-NOTES.md for verification. ## License and contents Software: MIT (LICENSE), copyright 2026 ArumSoft. Fonts: separate original terms in FONT-NOTICES.txt and OFL-1.1.txt, including DejaVu's Bitstream/Arev notices. Preserve these notices when redistributing. This release includes dist/, src/, fonts/, tests/, tools/, examples/, package manifests, and documentation. No node_modules, Python bytecode caches, browser binaries, or optional CJK pack.