惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tor Project blog
B
Blog RSS Feed
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
GbyAI
GbyAI
N
Netflix TechBlog - Medium
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Register - Security
The Register - Security
Cisco Talos Blog
Cisco Talos Blog
Martin Fowler
Martin Fowler
A
About on SuperTechFans
S
Security @ Cisco Blogs
T
Tenable Blog
C
Check Point Blog
N
News and Events Feed by Topic
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
P
Palo Alto Networks Blog
V
V2EX
博客园 - 聂微东
Project Zero
Project Zero
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
N
News | PayPal Newsroom
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
Application and Cybersecurity Blog
Application and Cybersecurity Blog
人人都是产品经理
人人都是产品经理
V2EX - 技术
V2EX - 技术
I
Intezer
L
LINUX DO - 最新话题

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2019-03-23 · via 轶哥博客

解决方案

在Windows平台,使用Node.js实现原生打印PDF通常需要借助C++。例如node-printer,需要安装Python、Visual Studio,同时还需要使用node-pdfium进行PDF转EMF。

也有一些二进制(exe)命令行打印解决方案,但是都有一些缺陷。

例如:

  • 借助 Adobe Reader 或 Acrobat 实现打印,则Windows XP、7、10需要安装不同版本的 DPF 软件,并且在打印时会打开该软件。
  • Sumatra PDF可以静默进行命令行打印,但是在80mm热敏纸打印机中的打印效果较差(不清晰)。

理论上这些方案支持所有能在Windows中安装驱动的打印机,包括非串口的热敏纸打印机。大多数方案都是基于PDFium的实现,如果您有足够的时间精力,可以深入研究PDFium

安装方法

为了方便大家使用Node.js实现PDF文件的打印,特意整理最佳方案上传为NPM模块:

npm i node-pdf-printer

使用方法

const NodePdfPrinter = require('node-pdf-printer')

NodePdfPrinter.listPrinter() // 列出所有打印机名称

const array = ['C:\\abc\\a.pdf', 'D:\\abd\\b.pdf'] // 待打印文件地址列表

NodePdfPrinter.printFiles(array) // 打印文件到Windows默认打印机

NodePdfPrinter.printFiles(array, printerName) // 打印文件到指定打印机

仅需Node.js环境,借助PDFtoPrinter.exe实现。

开源仓库

https://github.com/yi-ge/node-pdf-printer

支持Electron。如果您使用Electron,请参考:https://github.com/sindresorhus/electron-util#fixpathforasarunpackpath

如需支持双面打印,需要事先修改打印机默认配置。

LinuxAndroid平台的打印

可以参考:CUPSGhostScriptFoo2系列工具(foo2zjs、arm2hpdl等)HPijs