MCPcopy Index your code
hub / github.com/artiebits/unix-print

github.com/artiebits/unix-print @v1.3.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.2 ↗ · + Follow
12 symbols 31 edges 13 files 0 documented · 0% updated 2y agov1.3.2 · 2023-11-24★ 1051 open issues

Browse by type

Functions 10 Types & classes 2
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

Argument Type Optional Description
file string Required A file to print.
printer string Optional Print a file to the specific printer.
options string[] Optional Any 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

Argument Type Optional Description
printResponse {stdout: string | null} Required Resolved 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.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 10
Interface 2

Languages

TypeScript100%

Modules by API surface

src/utils/parse-response.ts3 symbols
src/get-default-printer/get-default-printer.ts3 symbols
src/types.ts2 symbols
src/utils/parse-printer-attribute.ts1 symbols
src/utils/exec-async.ts1 symbols
src/print/print.ts1 symbols
src/get-printers/get-printers.ts1 symbols

For agents

$ claude mcp add unix-print \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page