{"id":31032275,"url":"https://github.com/esimkowitz/printers-js","last_synced_at":"2025-10-17T00:48:09.159Z","repository":{"id":313563793,"uuid":"1051232623","full_name":"esimkowitz/printers-js","owner":"esimkowitz","description":"Cross-runtime printer library for Node.js, Deno, and Bun","archived":false,"fork":false,"pushed_at":"2025-10-07T19:06:18.000Z","size":6082,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T21:06:43.406Z","etag":null,"topics":["bun","deno","napi","nodejs","printer","printing","rust-lang","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/@printers/printers","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esimkowitz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-09-05T16:43:55.000Z","updated_at":"2025-10-07T19:06:21.000Z","dependencies_parsed_at":"2025-09-29T19:37:27.912Z","dependency_job_id":null,"html_url":"https://github.com/esimkowitz/printers-js","commit_stats":null,"previous_names":["esimkowitz/deno-printers","esimkowitz/printers-js"],"tags_count":48,"template":false,"template_full_name":null,"purl":"pkg:github/esimkowitz/printers-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimkowitz%2Fprinters-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimkowitz%2Fprinters-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimkowitz%2Fprinters-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimkowitz%2Fprinters-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esimkowitz","download_url":"https://codeload.github.com/esimkowitz/printers-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimkowitz%2Fprinters-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279262216,"owners_count":26136463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","deno","napi","nodejs","printer","printing","rust-lang","typescript"],"created_at":"2025-09-14T00:56:13.638Z","updated_at":"2025-10-17T00:48:09.152Z","avatar_url":"https://github.com/esimkowitz.png","language":"TypeScript","readme":"# @printers/printers\n\n[![NPM](https://img.shields.io/npm/v/%40printers%2Fprinters)](https://www.npmjs.com/package/@printers/printers)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/esimkowitz/printers-js/blob/main/LICENSE)\n[![CI](https://github.com/esimkowitz/printers-js/actions/workflows/ci.yml/badge.svg)](https://github.com/esimkowitz/printers-js/actions/workflows/ci.yml)\n\nCross-runtime printer library for Node.js, Deno, and Bun with native performance and comprehensive printing capabilities.\n\n## Features\n\n- 🔄 **Cross-runtime compatibility** - Node.js, Deno, and Bun support\n- 🖨️ **Cross-platform printing** - Windows, macOS, and Linux\n- 🦀 **Native performance** - Rust backend with Node-API bindings\n- 🔒 **Safe testing** - Simulation mode prevents accidental printing\n- 📊 **Real-time monitoring** - Printer state changes and job tracking\n- 🔧 **Flexible options** - Simple, CUPS, and raw printing configuration\n- ⚡ **Async control** - Choose immediate return or wait for completion\n\n## Installation\n\n### Node.js\n\n```bash\nnpm install @printers/printers\n```\n\n### Deno\n\n\u003e [!NOTE]\n\u003e This package exposes a Node-API addon for running the Rust backend natively. To use Node-API addons in Deno, you must enable `nodeModulesDir` in your `deno.json` configuration file and pass the `--allow-ffi` flag when running your program. To learn more, see the [Node and npm compatibility](https://docs.deno.com/runtime/fundamentals/node/#node-api-addons) and [Security and permissions](\u003chttps://docs.deno.com/runtime/fundamentals/security/#ffi-(foreign-function-interface)\u003e) documentation.\n\nAdd to `deno.json`:\n\n```json\n{\n  \"nodeModulesDir\": \"auto\"\n}\n```\n\n```bash\ndeno add npm:@printers/printers\n```\n\nRun with required permissions:\n\n```bash\ndeno run --allow-ffi --allow-env your-script.ts\n```\n\n### Bun\n\n```bash\nbun add @printers/printers\n```\n\n## Documentation\n\n📚 **[Complete Documentation](./docs/README.md)** - Comprehensive guides and examples\n\n### Feature Guides\n\n- **[Cross-Runtime Support](./docs/CrossRuntimeSupport.md)** - Node.js, Deno, and Bun compatibility\n- **[Printing Options](./docs/PrintingOptions.md)** - Simple, CUPS, and raw printing configuration\n- **[Job Tracking](./docs/JobTracking.md)** - Monitor and manage print jobs\n- **[Printer State Monitoring](./docs/PrinterStateMonitoring.md)** - Real-time printer state change events\n\n## Quick Start\n\n```typescript\nimport { getAllPrinters, getPrinterByName } from \"@printers/printers\";\n\n// List all available printers\nconst printers = getAllPrinters();\nconsole.log(\n  \"Available printers:\",\n  printers.map(p =\u003e p.name)\n);\n\n// Print a document\nconst printer = getPrinterByName(\"My Printer\");\nif (printer) {\n  const jobId = await printer.printFile(\"document.pdf\", {\n    simple: {\n      copies: 2,\n      duplex: true,\n      quality: \"high\",\n    },\n  });\n  console.log(\"Print job submitted:\", jobId);\n}\n```\n\n## API Reference\n\n### Core Functions\n\n#### `getAllPrinters(): Printer[]`\n\nReturns an array of all available system printers.\n\n#### `getPrinterByName(name: string): Printer | null`\n\nFind a printer by its exact name.\n\n#### `getAllPrinterNames(): string[]`\n\nReturns an array of printer names.\n\n#### `printerExists(name: string): boolean`\n\nCheck if a printer exists on the system.\n\n### Printer Class\n\n#### Properties\n\n- `name: string` - Printer display name\n- `state?: PrinterState` - Current printer state (`\"idle\"`, `\"printing\"`, `\"paused\"`, `\"offline\"`, `\"unknown\"`)\n- `isDefault?: boolean` - Whether this is the default printer\n- `location?: string` - Physical location description\n- `driverName?: string` - Printer driver name\n- `stateReasons?: string[]` - Array of state reason strings\n\n#### Methods\n\n- `printFile(filePath: string, options?: PrintJobOptions): Promise\u003cnumber\u003e` - Print a file and return job ID\n- `printBytes(data: Uint8Array, options?: PrintJobOptions): Promise\u003cnumber\u003e` - Print raw bytes and return job ID\n- `getActiveJobs(): PrinterJob[]` - Get currently active/pending jobs\n- `getJobHistory(limit?: number): PrinterJob[]` - Get completed job history\n- `getJob(jobId: number): PrinterJob | null` - Get specific job details\n- `cleanupOldJobs(maxAgeSeconds: number): number` - Remove old jobs\n\n### State Monitoring\n\n#### `subscribeToPrinterStateChanges(callback): Promise\u003cPrinterStateSubscription\u003e`\n\nSubscribe to real-time printer state change events.\n\n```typescript\nconst subscription = await subscribeToPrinterStateChanges(event =\u003e {\n  console.log(`${event.eventType}: ${event.printerName}`);\n});\n\n// Later: unsubscribe\nawait subscription.unsubscribe();\n```\n\n#### `getPrinterStateSnapshots(): Map\u003cstring, PrinterStateSnapshot\u003e`\n\nGet current state of all printers.\n\n#### `startPrinterStateMonitoring(config?): Promise\u003cvoid\u003e`\n\nStart printer state monitoring with optional configuration.\n\n### Print Options\n\n#### `PrintJobOptions`\n\n```typescript\ninterface PrintJobOptions {\n  jobName?: string; // Job name for identification\n  waitForCompletion?: boolean; // Wait for completion (default: true)\n  simple?: SimplePrintOptions; // Easy-to-use options\n  cups?: CUPSOptions; // Full CUPS options\n  raw?: Record\u003cstring, string\u003e; // Raw key-value options\n}\n```\n\n#### `SimplePrintOptions`\n\n```typescript\ninterface SimplePrintOptions {\n  copies?: number;\n  duplex?: boolean;\n  paperSize?: \"A4\" | \"Letter\" | \"Legal\" | \"A3\" | \"A5\" | \"Tabloid\";\n  quality?: \"draft\" | \"normal\" | \"high\";\n  color?: boolean;\n  pageRange?: string; // e.g., \"1-5,8,10-12\"\n  landscape?: boolean;\n}\n```\n\n## Examples\n\n### Basic Printing\n\n```typescript\nconst printer = getPrinterByName(\"My Printer\");\n\n// Simple printing\nawait printer.printFile(\"document.pdf\", {\n  simple: { copies: 2, duplex: true },\n});\n\n// With job tracking\nconst jobId = await printer.printFile(\"document.pdf\", {\n  waitForCompletion: false,\n});\n\nconst job = printer.getJob(jobId);\nconsole.log(`Job ${jobId}: ${job?.state}`);\n```\n\n### State Monitoring\n\n```typescript\n// Subscribe to printer events\nconst subscription = await subscribeToPrinterStateChanges(event =\u003e {\n  switch (event.eventType) {\n    case \"connected\":\n      console.log(`Printer ${event.printerName} connected`);\n      break;\n    case \"disconnected\":\n      console.log(`Printer ${event.printerName} disconnected`);\n      break;\n    case \"state_changed\":\n      console.log(\n        `${event.printerName}: ${event.oldState} → ${event.newState}`\n      );\n      break;\n  }\n});\n```\n\n### Custom Page Sizes\n\n```typescript\nimport { createCustomPageSize } from \"@printers/printers\";\n\nconst photoSize = createCustomPageSize(4, 6, \"in\"); // \"Custom.4x6in\"\n\nawait printer.printFile(\"photo.jpg\", {\n  cups: {\n    media: photoSize,\n    \"print-quality\": 5,\n  },\n});\n```\n\n## Testing \u0026 Safety\n\n### Simulation Mode\n\nEnable simulation mode to test without real printing:\n\n```bash\n# Unix/Linux/macOS\nPRINTERS_JS_SIMULATE=true node your-script.js\n\n# Windows Command Prompt\nset PRINTERS_JS_SIMULATE=true \u0026\u0026 node your-script.js\n\n# Windows PowerShell\n$env:PRINTERS_JS_SIMULATE=\"true\"; node your-script.js\n```\n\nCheck simulation status:\n\n```typescript\nimport { isSimulationMode } from \"@printers/printers\";\nconsole.log(\"Simulation mode:\", isSimulationMode);\n```\n\n## Platform Support\n\n| OS      | Architecture | Node.js | Deno | Bun |\n| ------- | ------------ | ------- | ---- | --- |\n| Windows | x64          | ✅      | ✅   | ✅  |\n| Windows | ARM64        | ✅      | ❌   | ❌  |\n| macOS   | x64          | ✅      | ✅   | ✅  |\n| macOS   | ARM64        | ✅      | ✅   | ✅  |\n| Linux   | x64          | ✅      | ✅   | ✅  |\n| Linux   | ARM64        | ✅      | ✅   | ✅  |\n\n## Development\n\nFor development setup, build instructions, and contribution guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md).\n\n## License\n\nMIT License - see [LICENSE](./LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimkowitz%2Fprinters-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesimkowitz%2Fprinters-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimkowitz%2Fprinters-js/lists"}