Coder Social home page Coder Social logo

node-cups's Introduction

CUPS JavaScript API

The CUPS JavaScript API is a library that provides a convenient way to interact with the CUPS (Common UNIX Printing System) command line tool on Linux distributions. With the provided functions and type definitions, you can easily retrieve print job details, get printer options, print files or buffers, and cancel print jobs. This API enables seamless integration of printing capabilities into your JavaScript applications on Linux distributions.

Getting Started

To use the CUPS JavaScript API in your project, follow these steps:

  1. Install the necessary dependencies:
npm install node-cups
  1. Import the required functions and types into your JavaScript file:
import {
  getCompletedQueue,
  getNotCompletedQueue,
  getPrinterNames,
  getPrinterOptions,
  getAllPrinterOptions,
  printBuffer,
  printFile,
  cancelAllJobs,
  cancelJob,
} from "node-cups";
  1. Start using the API functions in your application as shown in the examples below.

API Summary

The CUPS JavaScript API exposes several functions for interacting with print jobs and printers:

1. Type Definitions

The API also provides the following type definitions to assist in type checking:

type JobQueue = Array<{
  id: string;
  printerName: string;
  user: string;
  size: string;
  date: string;
}>

type QueueOptions = {
  printers?: string[];
}

type PrinterOptions = {
  name: string;
  values: string[];
  defaultValue?: string;
}

type PrintParams = {
  printer?: string;
  copies?: number;
  priority?: number;
  pages?: string;
  fitToPage?: boolean;
  printerOptions: Record<string, string>;
}

type PrintResult = {
  stdout: string;
  requestId?: string;
}

2. Print Job Functions

  • getCompletedQueue(options?: QueueOptions): Promise<JobQueue> Retrieves a list of completed print jobs.

    Example:

    const completedJobs = await getCompletedQueue();
    console.log(completedJobs);
  • getNotCompletedQueue(options?: QueueOptions): Promise<JobQueue> Retrieves a list of print jobs that are not yet completed.

    Example:

    const notCompletedJobs = await getNotCompletedQueue();
    console.log(notCompletedJobs);
  • getPrinterNames(): Promise<string[]> Retrieves a list of printer names available on the system.

    Example:

    const printerNames = await getPrinterNames();
    console.log(printerNames);
  • getPrinterOptions(printerName: string): Promise<Array<PrinterOptions>> Retrieves the available options for a specific printer.

    Example:

    const printerOptions = await getPrinterOptions("printer-1");
    console.log(printerOptions);
  • getAllPrinterOptions(): Promise<Array<{ printerName: string; options: PrinterOptions[] }>> Retrieves all printer options for each printer on the system.

    Example:

    const allPrinterOptions = await getAllPrinterOptions();
    console.log(allPrinterOptions);
  • printBuffer(data: Buffer, params: PrintParams): Promise<PrintResult> Prints a buffer of data using the specified print parameters.

    Example:

    const data = Buffer.from("Hello, World!", "utf8");
    const params = {
      printer: "printer-1",
      copies: 2,
      printerOptions: {
        orientation: "landscape",
      },
    };
    const result = await printBuffer(data, params);
    console.log(result);
  • printFile(file: string, params: PrintParams): Promise<PrintResult> Prints a file using the specified print parameters.

    Example:

    const file = "/path/to/file.pdf";
    const params = {
      printer: "printer-1",
      copies: 1,
      printerOptions: {
        media: "A4",
      },
    };
    const result = await printFile(file, params);
    console.log(result);
  • cancelAllJobs(printer?: string): Promise<void> Cancels all print jobs on the system.

    Example:

    await cancelAllJobs();
  • cancelJob(requestId: string): Promise<void> Cancels a specific print job identified by the requestId.

    Example:

    const requestId = "job-123";
    await cancelJob(requestId);

node-cups's People

Contributors

nikohadouken avatar rebound-software avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.