electron 获取打印机列表
- winprints = new BrowserWindow({ show: false });
- console.log(winprints.webContents.getPrinters())
获取到的结果为:
- {
- name: 'Zebra_LP2844',
- description: 'Zebra LP2844',
- status: 3,
- isDefault: false,
- options: {
- copies: '1',
- 'device-uri': 'usb://Zebra/LP2844?location=14200000',
- finishings: '3',
- 'job-cancel-after': '10800',
- 'job-hold-until': 'no-hold',
- 'job-priority': '50',
- 'job-sheets': 'none,none',
- 'marker-change-time': '0',
- 'number-up': '1',
- 'printer-commands': 'none',
- 'printer-info': 'Zebra LP2844',
- 'printer-is-accepting-jobs': 'true',
- 'printer-is-shared': 'true',
- 'printer-location': '',
- 'printer-make-and-model': 'Zebra EPL2 Label Printer',
- 'printer-state': '3',
- 'printer-state-change-time': '1484872644',
- 'printer-state-reasons': 'offline-report',
- 'printer-type': '36932',
- 'printer-uri-supported': 'ipp://localhost/printers/Zebra_LP2844',
- system_driverinfo: 'Z'
- }
- }
设置静默打印
- winprints.webContents.print({ silent: true, printBackground: true,deviceName:'Zebra_LP2844'});
参数介绍
- silent Boolean (可选) - 不询问用户打印设置及静默打印. 默认为 false.
- printBackground Boolean (可选) - 同时打印网页的背景颜色和图片. 默认为 false.
- deviceName String (可选) - 使用打印机设备名称. 默认为 ''.
打印机状态码
- //
- // 摘要:
- // 指定打印队列或其打印机的状态。
- [Flags]
- public enum PrintQueueStatus
- {
- //
- // 摘要:
- // 未指定状态。
- None = 0,
- //
- // 摘要:
- // 打印队列已暂停。
- Paused = 1,
- //
- // 摘要:
- // 由于错误情况,打印机无法打印。
- Error = 2,
- //
- // 摘要:
- // 打印队列正在删除打印作业。
- PendingDeletion = 4,
- //
- // 摘要:
- // 打印机卡纸。
- PaperJam = 8,
- //
- // 摘要:
- // 打印机中没有或已用完当前打印作业所需的纸张类型。
- PaperOut = 16,
- //
- // 摘要:
- // 打印机正在等待用户将打印介质放入手动送纸盒。
- ManualFeed = 32,
- //
- // 摘要:
- // 打印机中的纸张导致未指定的错误情况。
- PaperProblem = 64,
- //
- // 摘要:
- // 打印机处于脱机状态。
- Offline = 128,
- //
- // 摘要:
- // 打印机正在与打印服务器交换数据。
- IOActive = 256,
- //
- // 摘要:
- // 打印机正忙。
- Busy = 512,
- //
- // 摘要:
- // 设备正在打印。
- Printing = 1024,
- //
- // 摘要:
- // 打印机的输出纸盒已满。
- OutputBinFull = 2048,
- //
- // 摘要:
- // 状态信息不可用。
- NotAvailable = 4096,
- //
- // 摘要:
- // 打印机正在等待打印作业。
- Waiting = 8192,
- //
- // 摘要:
- // 设备正在执行某种工作,如果此设备是集打印机、传真机和扫描仪于一体的多功能设备,则不需要打印。
- Processing = 16384,
- //
- // 摘要:
- // 打印机正在初始化。
- Initializing = 32768,
- //
- // 摘要:
- // 打印机正在预热。
- WarmingUp = 65536,
- //
- // 摘要:
- // 打印机中只剩下少量墨粉。
- TonerLow = 131072,
- //
- // 摘要:
- // 打印机墨粉用完。
- NoToner = 262144,
- //
- // 摘要:
- // 打印机不能打印当前页。
- PagePunt = 524288,
- //
- // 摘要:
- // 打印机要求通过用户操作来更正错误情况。
- UserIntervention = 1048576,
- //
- // 摘要:
- // 打印机无可用内存。
- OutOfMemory = 2097152,
- //
- // 摘要:
- // 打印机上的门已打开。
- DoorOpen = 4194304,
- //
- // 摘要:
- // 打印机处于错误状态。
- ServerUnknown = 8388608,
- //
- // 摘要:
- // 打印机处于节能模式。
- PowerSave = 16777216
- }