百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

electron-pos-printer

> 编程语言
开源

Electron-pos-printer 是一个插件,用于简化对热敏打印机的纸张格式化和打印。目前它支持 80mm、78mm、76mm、58mm、57mm 和 44mm 等尺寸。

398 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Electron-pos-printer 是一个插件,用于简化对热敏打印机的纸张格式化和打印。目前它支持 80mm、78mm、76mm、58mm、57mm 和 44mm 等尺寸。

Electron-pos-printer

A customizable electron.js printing plugin specifically designed for thermal receipt printers. It supports 80mm, 78mm, 76mm, 58mm, 57mm, 44mm printers. It currently supports versions of electron >= 6.x.x

Installation

bash
$ npm install electron-pos-printer
$ yarn add electron-pos-printer

Demo

Check out this Demo by fssonca

Usage

In main process

javascript
const {PosPrinter} = require("electron-pos-printer");

In render process

javascript
const {PosPrinter} = require('electron').remote.require("electron-pos-printer");

Electron >= v10.x.x

javascript
const {PosPrinter} = require('@electron/remote').remote.require("electron-pos-printer");

Example code

…

Typescript

Usage

…

Printing options

Options Required Type Description
printerName No string The printer's name. If not set, the system's default printer will be used.
copies No number The number of copies to print
preview No boolean Preview print job in a window. Default is false
width No string Width of a page's content
margin No string Margin of a page's content. CSS margin values can be used Ex. 0 10px
timeOutPerLine No number Timeout per line in milliseconds. Default value is 400
silent No boolean To print silently without the system displaying the printer selection window. Default value is true
pageSize No PaperSize, SizeOptions Configure the paper size which is supported by your printer. values are are 80mm, 78mm, 76mm, 58mm, 57mm, 44mm or object with width and height properties in pixels.
pathTemplate No string Path to custom html template. Can be used for custom print styles.
header No string Text to be printed as page header.
footer No string Text to be printed as page footer.
margins No object Page margins. See electron docs
landscape No boolean Whether the page should be printed in landscape mode. Default is false.
scaleFactor No number The scale factor of the web page.
pagesPerSheet No number The number of pages to print per page sheet.
collate No boolean Whether the page should be collated.
pageRanges No object[] The page range to print. See electron docs
duplexMode No string Set the duplex mode of the printed web page. See electron docs
dpi No object See electron docs

The Print data object

Important!!

The css property is no longer supported, use the style property instead of css.

Example: style: {fontWeight: "700", textAlign: 'center', fontSize: "24px"}

Property Type Description
type string text, qrCode, barCode, image, table // type text can be an html string
value string Value of the current row
height number Applicable to type barCode and qrCode
width number Applicable to type barCode and qrCode
style PrintDataStyle Add css styles to line (jsx syntax)
ex: {fontSize: 12, backgroundColor: '#2196f3}
displayValue boolean Display value of barcode below barcode
position string left, center, right applicable to types qrCode and image
path string Path or url to the image asset
url string Url to image or a base 64 encoding of image
tableHeader PosPrintTableField[] or string[] The columns to be rendered in the header of the table. Works with type table
tableBody PosPrintTableField[][] or string[][] The columns to be rendered in the body of the table. Works with type table
tableFooter PosPrintTableField[] or string[] The columns to rendered it the footer of the table. Works with type table
tableHeaderStyle string Set a custom style to the table header
tableBodyStyle string Set a custom style to the table body
tableFooterStyle string Set a custom style to the table footer

Cash Drawer

Use PosPrinter.openCashDrawer(printerName) to send an ESC/POS cash-drawer kick command to the printer that the drawer is connected to.

javascript
const { PosPrinter } = require("electron-pos-printer");

// Open drawer on pin 2 (default)
PosPrinter.openCashDrawer("XP-80C")
  .then(() => console.log("Cash drawer opened"))
  .catch(console.error);

// Open drawer on pin 5 with custom pulse timing
PosPrinter.openCashDrawer("XP-80C", { pin: 5, onTime: 50, offTime: 300 })
  .then(() => console.log("Cash drawer opened"))
  .catch(console.error);

Cash drawer options

Option Type Default Description
pin 2 or 5 2 Drawer kick pin
onTime number 25 Pulse on-time in milliseconds
offTime number 250 Pulse off-time in milliseconds

You can also send arbitrary ESC/POS raw bytes with PosPrinter.sendRawCommand(printerName, buffer):

javascript
// Send a manual paper cut command (ESC/POS full cut: GS V 0)
PosPrinter.sendRawCommand("XP-80C", Buffer.from([0x1d, 0x56, 0x00]))
  .then(() => console.log("Paper cut sent"))
  .catch(console.error);

Platform notes

  • macOS / Linux: uses lp -d -o raw
  • Windows: uses PowerShell System.Printing.LocalPrintServer.GetPrintQueue() — pass the printer display name exactly as shown in Devices and Printers (e.g. "XP-80C")

FAQ

Cannot find module 'electron-pos-printer' or dist/index.js has no valid main entry

This happens when installing directly from a git URL instead of npm, because the compiled dist/ is not committed to the repo. As of v1.4.0 a prepare script runs npm run build automatically on npm install, so this should resolve itself. If you still hit it:

bash
cd node_modules/electron-pos-printer && npm run build

Webpack / vue-cli bundler errors

When bundling your Electron app with webpack or vue-cli, mark electron-pos-printer as an external so it is not bundled (it must run in the Electron main process and uses native Node APIs):

javascript
// webpack.config.js
module.exports = {
  externals: {
    'electron-pos-printer': 'commonjs electron-pos-printer',
  },
};

For vue-cli, add to vue.config.js:

javascript
module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ['electron-pos-printer'],
    },
  },
};

Contributors

Thanks to our contributors

  • Hubert Formin
  • Sidnei Pacheco
  • Ulisses Constantini
  • Famous Ketoma

Issues· 14 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptelectron-printerelectronjsnodejspos-printers

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言