npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-native-printer-mydesq

v1.0.2

Published

Node module to print from nodejs apps

Downloads

5

Readme

node-native-printer

A node module to natively print your files

Requirements

  • Windows:

    • edge, electron-edge (depending on your environment) or any other fork of these. The package you choose should be installed before node-native-printer. During installation you'll be prompted to select which package do you want to use.BE CAREFULLY: it will be listed all packages in node_modules containing the word "edge"; be sure to make the right choice

      If you wish, you can manually specify which fork of edge or electron-edge to use. See installation

  • Unix (Mac and Linux)

    • node-gyp to build native modules
    • cups (Linux only). You need libcups2-dev and libcups2. The first contains source code needed to build native modules, the second contains command-line executables needed in order to print. It may also need libcups2 in production. See API

Imporant notes

Due to important differences in enviroments and ecosystems between Microsoft and Unix-based systems, this module has been written in C++ for Unix and C# for Windows. This can result in different behaviours during the execution of the methods (such as different execution time, returning values, allowed options for printer, etc.).


Installation

npm install node-native-printer --save

You will be prompted for selecting edge backend based on installed packages that contains the word "edge". If you wish to enter manually the name of edge backend package, select Not listed and type it manually.

Flags (Windows only)

  • -p or --production: to be used when packaging with (i.e.) electron-builder. It will skip prompting for edge backend and will take correctly the dll path needed for windows. Note that -p flag require that edge backend has been specified during installation.

Usage

First of all you need to require the module inside your app this way:

const printer = require('node-native-printer');

Then you can set a printer to work on, calling setPrinter(printerName). In this way you don't need to pass else the printer name on each method it's required.

API

listPrinters()

    return an array with all installed printers

defaultPrinterName()

    return the default printer name

setPrinter(printer)

    set the printer to work on

getCurrentPrinter()

    get current printer you are working on

printerInfo(printer)

    return general info about current working printer such jobs and options:

  • printer: printer of which get informations
  • returning value:
    • Windows: return only jobs in printer queue
    • Unix: return jobs in printer queue and CUPS options. Theese last depends on printer

printerOptions(printer)

    return printer-specific options:

  • printer: name of the printer to print on. If not specified it will print on previously setted printer. If printer is not set it will print on default printer.

  • Returning value:

    • Windows: return an object containing main options for printer:
    {
        "Collate": "array containing collation options",
        "Duplexing": "array containing collation options",
        "MaxCopy": "max number of copies you can send to printer",
        "SupportsColor": "boolean indicating whether a print can print with colors",
        "PaperSheets": "available paper formats supported from printer. If custom is present it can be submitted custom width and height",
        "Resolutions": "printer resolutions (i.e.: High, Medium)"
    }
    • Unix: return an object containing printer-specific options and from PPD file.

print(filename[, options, printer])

  • filename: file to print
  • options: a JSON object containing options for printer:
    • Windows: default options:

      {
          "collate": true,
          "color": true,
          "copies": 1,
          "duplex": "Default",
          "landscape": false,
          "paperSize": "",
          "fromPage": 0,
          "toPage": 0
      }

      List of supported extensions can be found here

      Notes: duplex is case sensitive, so be careful to write correctly. "paperSize" refers to size of sheet to print on; if you want to print on a paper with custom dimensions, pass "Custom.WidthxHeight" where Width and Height are integer dimensions in hundredths of inch. "fromPage": 0 means document will be printed from first page; "toPage": 0 means document will be printed from "fromPage" to last page.

    • Unix: you can use command-line options in JSON-style and/or printer-specific options retrieved from printerOptions(); i.e.:

      {
          "landscape": true,
          "n": 2,
          "sides": "two-sided-long-edge"
      }

      For options that doesn't have a value (like landscape or fit-to-page) you can assign a boolean (see above)

      It will be generated and executed a command like lp -d printerName /path/to/filename -o landscape -n 2 -o sides=two-sided-long-edge

  • Returning value (only for Unix): job id of work sent to printer

printText(text[, options, printer])

Same as print() but you can pass directly a string of text on the first parameter.

Electron Packaging (Windows only)

As from electron's docs, there are two methods of packaging your app: with one of the builders or manually making your own an asar archive.

  • Builders (tested with electron-builder): it's enough to add flag -p or --production. Example with electron-builder:
    "build": {
      "npmArgs": "--production"
    }
  • Manually packing: you'll need to copy all lib/windows folder, under <app-root>/resources/app.asar.unpacked/node_modules/node-native-printer/lib/windows. The tree will look like:
    /app folder
    +-- ...
    +-- resources/
        +-- app.asar
        +-- electron.asar
        +-- app.asar.unpacked/
            +-- node_modules/
                +-- node-native-printer/
                    +-- lib/
                        +-- windows/
                            +-- nl/
                            +-- x64/
                            +-- x86/
                            +-- PdfiumViewer.dll
                            +-- PdfiumViewer.xml
                            +-- windows_printer.dll