printHtml API reference & best practices

printHtml is the primary web-print-pdf entry—local client renders HTML to PDF and prints. Covers four argument groups, patterns, pitfalls, and evaluation checklist for engineering leads.

Signature

printHtml(html, pdfOptions?, printOptions?, extraOptions?): Promise<PrintResult>

Parameters

ArgStageGuide
htmlInput stringdemos
pdfOptionsLayout → PDFprint options
printOptionsPDF → printerprint options
extraOptionspreview, timeoutprint options

Code example

import webPrintPdf from 'web-print-pdf';

if (!(await webPrintPdf.getConnectStatus())) {
  throw new Error('Start the desktop client first');
}
await webPrintPdf.printHtml(html, pdfOptions, printOptions);

Common patterns

PatternNotes
DOM extractref innerHTML → printHtml
API HTML stringFull document from backend
Preview onlyextraOptions.action preview

When to use

  • You already have HTML reports
  • Need silent named printer
  • Trigger from UI events

Common pitfalls

  • Pair pdf/print options consistently
  • Preflight getConnectStatus
  • Browser/client components only—not SSR

Technical lead checklist

  • License desks that need silent named output
  • PoC one representative report vs Lodop/Print.js
  • Accept: preview matches physical sample

Read next

FAQ

Client must be running?

Yes—use getConnectStatus; see error-handling.

Same-named pdf/print fields?

Configure in pairs—especially paper size.

Preview only?

extraOptions.action = "preview".

Call from SSR?

Browser/client components only.

vs printHtmlByUrl?

ByUrl fetches a URL; printHtml takes HTML string.

Client deployment by platform

The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.

Download client — free trial View npm package Documentation