$ show artiebits/pdf-to-printer
pdf-to-printer is a small, focused Node.js/Electron library that prints PDFs and images to Windows printers by shelling out to a bundled SumatraPDF executable. The public API exposes three async functions: `print()`, `getPrinters()`, and `getDefaultPrinter()`. `print()` validates the target file, builds SumatraPDF command-line arguments from a typed options object (printer, pages, orientation, paper size, duplex, copies, etc.), and executes the binary via `child_process.execFile`. Printer discovery uses PowerShell's `Get-CimInstance Win32_Printer` and parses the formatted text output into structured `Printer` objects with device ID, name, and supported paper sizes. The code is TypeScript with strict mode, unit-tested with Jest, and bundled with webpack for UMD distribution. It is Windows-only by design and throws on other operating systems.
The LLM identified 2 files worth highlighting for reuse:
Parses raw `Get-CimInstance Win32_Printer` text output into structured printer objects. It handles multi-line records, trims labels/values, converts PowerShell array syntax like `{A4, Letter...}` into string arrays, and maps Windows property names to a clean `Printer` interface. The function is self-contained (only a type import) and can be lifted into any Windows printer discovery tool with minimal changes.
Detects whether the app is running inside an Electron ASAR archive and rewrites binary paths from `app.asar` to `app.asar.unpacked`. This is a critical, dependency-free utility for any Electron app that needs to execute a bundled native binary. It is a clean, isolated pattern that can be copied directly into other Electron projects.