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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
GbyAI
GbyAI
T
Threatpost
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
The Hacker News
The Hacker News
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
I
Intezer
美团技术团队
S
Schneier on Security
I
InfoQ
Project Zero
Project Zero
S
SegmentFault 最新的问题
IT之家
IT之家
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
博客园 - 司徒正美
Security Latest
Security Latest
G
Google Developers Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
V
V2EX
The Register - Security
The Register - Security
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Spread Privacy
Spread Privacy
H
Help Net Security
H
Heimdal Security 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
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