electron 静默打印,及 打印机状态汇总

electron 获取打印机列表

  1. winprints = new BrowserWindow({ show: false });
  2.       console.log(winprints.webContents.getPrinters())

获取到的结果为:

  1. {
  2.     name: 'Zebra_LP2844',
  3.     description: 'Zebra LP2844',
  4.     status: 3,
  5.     isDefault: false,
  6.     options: {
  7.       copies: '1',
  8.       'device-uri': 'usb://Zebra/LP2844?location=14200000',
  9.       finishings: '3',
  10.       'job-cancel-after': '10800',
  11.       'job-hold-until': 'no-hold',
  12.       'job-priority': '50',
  13.       'job-sheets': 'none,none',
  14.       'marker-change-time': '0',
  15.       'number-up': '1',
  16.       'printer-commands': 'none',
  17.       'printer-info': 'Zebra LP2844',
  18.       'printer-is-accepting-jobs': 'true',
  19.       'printer-is-shared': 'true',
  20.       'printer-location': '',
  21.       'printer-make-and-model': 'Zebra EPL2 Label Printer',
  22.       'printer-state': '3',
  23.       'printer-state-change-time': '1484872644',
  24.       'printer-state-reasons': 'offline-report',
  25.       'printer-type': '36932',
  26.       'printer-uri-supported': 'ipp://localhost/printers/Zebra_LP2844',
  27.       system_driverinfo: 'Z'
  28.     }
  29.   }



设置静默打印

  1. winprints.webContents.print({ silent: true, printBackground: true,deviceName:'Zebra_LP2844'});

参数介绍

  1.  
  2.     silent Boolean (可选) - 不询问用户打印设置及静默打印. 默认为 false.
  3.     printBackground Boolean (可选) - 同时打印网页的背景颜色和图片. 默认为 false.
  4.     deviceName String (可选) - 使用打印机设备名称. 默认为 ''.
  5.  


打印机状态码

  1. //
  2. // 摘要:
  3. // 指定打印队列或其打印机的状态。
  4. [Flags]
  5. public enum PrintQueueStatus
  6. {
  7. //
  8. // 摘要:
  9. // 未指定状态。
  10. None = 0,
  11. //
  12. // 摘要:
  13. // 打印队列已暂停。
  14. Paused = 1,
  15. //
  16. // 摘要:
  17. // 由于错误情况,打印机无法打印。
  18. Error = 2,
  19. //
  20. // 摘要:
  21. // 打印队列正在删除打印作业。
  22. PendingDeletion = 4,
  23. //
  24. // 摘要:
  25. // 打印机卡纸。
  26. PaperJam = 8,
  27. //
  28. // 摘要:
  29. // 打印机中没有或已用完当前打印作业所需的纸张类型。
  30. PaperOut = 16,
  31. //
  32. // 摘要:
  33. // 打印机正在等待用户将打印介质放入手动送纸盒。
  34. ManualFeed = 32,
  35. //
  36. // 摘要:
  37. // 打印机中的纸张导致未指定的错误情况。
  38. PaperProblem = 64,
  39. //
  40. // 摘要:
  41. // 打印机处于脱机状态。
  42. Offline = 128,
  43. //
  44. // 摘要:
  45. // 打印机正在与打印服务器交换数据。
  46. IOActive = 256,
  47. //
  48. // 摘要:
  49. // 打印机正忙。
  50. Busy = 512,
  51. //
  52. // 摘要:
  53. // 设备正在打印。
  54. Printing = 1024,
  55. //
  56. // 摘要:
  57. // 打印机的输出纸盒已满。
  58. OutputBinFull = 2048,
  59. //
  60. // 摘要:
  61. // 状态信息不可用。
  62. NotAvailable = 4096,
  63. //
  64. // 摘要:
  65. // 打印机正在等待打印作业。
  66. Waiting = 8192,
  67. //
  68. // 摘要:
  69. // 设备正在执行某种工作,如果此设备是集打印机、传真机和扫描仪于一体的多功能设备,则不需要打印。
  70. Processing = 16384,
  71. //
  72. // 摘要:
  73. // 打印机正在初始化。
  74. Initializing = 32768,
  75. //
  76. // 摘要:
  77. // 打印机正在预热。
  78. WarmingUp = 65536,
  79. //
  80. // 摘要:
  81. // 打印机中只剩下少量墨粉。
  82. TonerLow = 131072,
  83. //
  84. // 摘要:
  85. // 打印机墨粉用完。
  86. NoToner = 262144,
  87. //
  88. // 摘要:
  89. // 打印机不能打印当前页。
  90. PagePunt = 524288,
  91. //
  92. // 摘要:
  93. // 打印机要求通过用户操作来更正错误情况。
  94. UserIntervention = 1048576,
  95. //
  96. // 摘要:
  97. // 打印机无可用内存。
  98. OutOfMemory = 2097152,
  99. //
  100. // 摘要:
  101. // 打印机上的门已打开。
  102. DoorOpen = 4194304,
  103. //
  104. // 摘要:
  105. // 打印机处于错误状态。
  106. ServerUnknown = 8388608,
  107. //
  108. // 摘要:
  109. // 打印机处于节能模式。
  110. PowerSave = 16777216
  111. }

猜你喜欢

转载自blog.csdn.net/weixin_41653910/article/details/91883521