Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unix-print

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unix-print

Utility for Unix-like operating systems to print PDF files from Node.js and Electron

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Unix-print

A utility for Unix-like operating systems to print files from Node.js and Electron.

  • Understands different types of files, such as PDF, text, PostScript, and image files.
  • Supports label printers such as Rollo and Zebra.

Table of Contents

Basic Usage

Print a PDF file to the default printer:

import { print } from "unix-print";

print("assets/file.pdf").then(console.log);

Installation

Install using Yarn:

yarn add unix-print

Or using npm:

npm install --save unix-print

API

print(pdf, printer, options) => Promise<void>

A function to print a file to a printer.

Arguments

ArgumentTypeOptionalDescription
filestringRequiredA file to print.
printerstringOptionalPrint a file to the specific printer.
optionsstring[]OptionalAny option from this list.

Returns

Promise<{stdout: string | null, stderr: string | null}>.

To print a file to the default printer:

import { print } from "unix-print";

print("assets/file.pdf").then(console.log);

To print a file to a specific printer:

import { print } from "unix-print";

const fileToPrint = "assets/file.pdf";
const printer = "Zebra";

print(fileToPrint, printer).then(console.log);

With some printer-specific options:

import { print } from "unix-print";

const fileToPrint = "assets/file.jpg";
const printer = undefined;
const options = ["-o landscape", "-o fit-to-page", "-o media=A4"];

print("assets/file.jpg", printer, options).then(console.log);

isPrintComplete(printResponse) => Promise<boolean>

Arguments

ArgumentTypeOptionalDescription
printResponse{stdout: string | null}RequiredResolved promise returned from print.

Returns

Promise<boolean>: False if the job is on the queue or stdout is null, true otherwise.

Examples

import { isPrintComplete } from 'unix-print';

const fileToPrint = 'assets/file.pdf';
const printJob = await print(fileToPrint);

async function waitForPrintCompletion(printJob) {
  while (!await isPrintComplete(printJob)) {
    // Wait a bit before checking again (to avoid constant checks)
    await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second
  }
  console.log('Job complete');
}

await waitForPrintCompletion(printJob);

getPrinters() => Promise<Printer[]>

Returns

Promise<Printer[]>: List of available printers.

Examples

import { getPrinters } from "unix-print";

getPrinters().then(console.log);

getDefaultPrinter() => Promise<Printer | null>

Returns

Promise<Printer | null>: System default printer or null.

Examples

import { getPrinters } from "unix-print";

getDefaultPrinter().then(console.log);

License

This project is licensed under the MIT License - see the LICENSE.md for details.

Keywords

FAQs

Package last updated on 24 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc