Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: CI & Prebuilds

on:
push:
branches:
- main
pull_request:

jobs:
prebuild:
name: Prebuild on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 30

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'

- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo dpkg --add-architecture i386
sudo apt-get update -y -qq
sudo apt-get install -y g++-multilib gcc-multilib libcups2-dev libcups2-dev:i386 libc6-dev-i386 linux-libc-dev linux-libc-dev:i386

- name: Set up QEMU for ARM builds
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: arm,arm64

- name: Determine Architectures
id: archs
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
echo "arch_list=ia32 x64 arm arm64" >> $GITHUB_OUTPUT
elif [[ "${{ runner.os }}" == "macOS" ]]; then
echo "arch_list=x64 arm64" >> $GITHUB_OUTPUT
elif [[ "${{ runner.os }}" == "Windows" ]]; then
echo "arch_list=ia32 x64 arm64" >> $GITHUB_OUTPUT
fi

- name: Install dependencies
run: npm install

- name: Build Prebuilds
run: |
for arch in ${{ steps.archs.outputs.arch_list }}; do
npm run prebuild -- --strip --arch "$arch"
done
shell: bash

- name: Upload prebuilds artifact
uses: actions/upload-artifact@v4
with:
name: prebuilds-${{ matrix.os }}
path: prebuilds/

publish:
name: Publish Prebuilds
needs: prebuild
runs-on: ubuntu-latest
# The job-level `if` is removed. The job will now run on pull requests,
# but the steps inside will be skipped. This allows the job to report a
# "success" status, which is useful if it's a required check for merging.
steps:
- name: Checkout code
uses: actions/checkout@v4
if: github.ref == 'refs/heads/main'
- name: Setup Node.js
uses: actions/setup-node@v4
if: github.ref == 'refs/heads/main'
with:
node-version: '18.x'
- name: Install dependencies
if: github.ref == 'refs/heads/main'
run: npm install
- name: Download all artifacts
uses: actions/download-artifact@v4
if: github.ref == 'refs/heads/main'
with:
path: prebuilds/
pattern: prebuilds-*
merge-multiple: true
- name: Publish to GitHub Releases
if: github.ref == 'refs/heads/main'
env:
NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.PREBUILD_TOKEN }}
run: npm run release
57 changes: 0 additions & 57 deletions .github/workflows/prebuild-main.yml

This file was deleted.

55 changes: 0 additions & 55 deletions .github/workflows/prebuild-pr.yml

This file was deleted.

80 changes: 0 additions & 80 deletions Gruntfile.js

This file was deleted.

53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
# @thesusheer/electron-printer
# @addble/node-printer

**No recompilation required when upgrading Node.js versions, thanks to N-API!** 🎉

Native bind printers on POSIX and Windows OS from Node.js, Electron, and node-webkit.
Native bind printers on Windows, Mac OS, and Linux from Node.js, Electron, and node-webkit.
Supports following architectures:
* Windows - ia32, x64, arm64
* Mac - x64 & arm64 (Apple Silicon)
* Linux - ia32, x64, arm7l, arm64

!npm version !Prebuild Binaries and Publish

[![npm version](https://badge.fury.io/js/%40addble%2Fnode-printer.svg)](https://badge.fury.io/js/%40addble%2Fnode-printer)
[![CI & Prebuilds](https://github.com/addble/electron-printer/actions/workflows/ci.yml/badge.svg)](https://github.com/addble/electron-printer/actions/workflows/ci.yml)

> Supports Node.js versions from 8.0.0 onwards, including the latest versions, thanks to the transition to N-API.

> Prebuild and CI integration courtesy of @ekoeryanto in his FORK
> Prebuild and CI integration courtesy of @ekoeryanto in his [FORK](https://github.com/ekoeryanto/node-printer)

If you have a problem, please find or create a new [GitHub issue](https://github.com/addble/electron-printer/issues).

### Supported Features

* No dependencies on NAN or V8;
* Native method wrappers for Windows and POSIX (which uses CUPS 1.4/MAC OS X 10.6) APIs;
* Compatible with Node.js versions that support N-API, ensuring long-term stability and compatibility;
* Compatible with Electron versions that support N-API, reducing the need for frequent recompilation;
* `getPrinters()` to enumerate all installed printers with current jobs and statuses;
* `getPrinter(printerName)` to get info for a specific printer;
* `getDefaultPrinterName()` returns the default printer name;
* `printDirect(options)` to send raw data to a printer. Returns a Promise.
* `printFile(options)` to print a file (POSIX only, e.g., macOS, Linux). Returns a Promise.
* `getSupportedPrintFormats()` to get supported data formats like 'RAW' and 'TEXT'.

### Pre-compiled Binaries

If you have a problem, ask a question on !Gitter or find/create a new Github issue
This package ships with pre-compiled binaries for a wide range of Node.js and Electron versions on Windows, macOS, and Linux for various architectures.

While N-API provides forward compatibility (meaning a binary built for an older version may work on a newer one), we provide pre-builds for these major versions to ensure a smooth installation experience without requiring a local compiler toolchain:

* **Node.js**: 16, 18, 20, 22
* **Electron**: 15, 19, 22, 25, 27, 28, 29, 30, 31

If you are using a version not covered by our pre-compiled binaries, the installer will attempt to build the addon from source. This requires a proper C/C++ compiler toolchain to be installed on your system.

### How to install:
```
npm install @addble/electron-printer

___
### **Below is the original README**
Expand All @@ -29,18 +63,13 @@ I was involved in a project where I needed to print from Node.js. This is the re
* `getPrinter(printerName)` to get a specific/default printer info with current jobs and statuses;
* `getPrinterDriverOptions(printerName)` (POSIX only) to get a specific/default printer driver options such as supported paper size and other info;
* `getSelectedPaperSize(printerName)` (POSIX only) to get a specific/default printer default paper size from its driver options;
* `getDefaultPrinterName()` returns the default printer name;
* `printDirect(options)` to send a job to a specific/default printer, now supports CUPS options passed in the form of a JS object (see `cancelJob.js` example). To print a PDF from Windows, it is possible by using node-pdfium module to convert a PDF format into EMF and then send it to the printer as EMF;
* `printFile(options)` (POSIX only) to print a file;
* `getSupportedPrintFormats()` to get all possible print formats for the `printDirect` method, which depends on the OS. `RAW` and `TEXT` are supported on all OSes;
* `getJob(printerName, jobId)` to get specific job info including job status;
* `setJob(printerName, jobId, command)` to send a command to a job (e.g., `'CANCEL'` to cancel the job);
* `getSupportedJobCommands()` to get supported job commands for `setJob()`, depending on the OS. The `'CANCEL'` command is supported on all OSes.

### How to install:
```
npm install @thesusheer/electron-printer
```

### How to use:

Expand Down Expand Up @@ -80,6 +109,7 @@ This project is licensed under the MIT License.
### Keywords:

* node-printer
* nodejs-printer
* printer
* electron-printer
* node-addon-api
Expand All @@ -88,5 +118,8 @@ This project is licensed under the MIT License.
* CUPS printer
* print job
* printer driver
* Mac OS printer
* Raspberry PI printer


---
Loading
Loading