GithubHelp home page GithubHelp logo

katherdx / electron-pos-printer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hubertformin/electron-pos-printer

0.0 1.0 0.0 220 KB

Electron thermal printer

License: Apache License 2.0

TypeScript 80.72% JavaScript 19.28%

electron-pos-printer's Introduction

License Version Issues

Electron-pos-printer

An electron printer plugin, currently supports 58mm, requires electron >= 4.x.x.

Installation

$ npm install electron-pos-printer

Usage

In main process

const {PosPrinter} = require("electron-pos-printer");

In render process

const {PosPrinter} = require('electron').remote.require("electron-pos-printer");

Demo

const {PosPrinter} = require("electron-pos-printer");
const path = require("path");

const options = {
   preview: false,               // Preview in window or print
   width: '170px',               //  width of content body
   margin: '0 0 0 0',            // margin of content body
   copies: 1,                    // Number of copies to print
   printerName: 'XP-80C',        // printerName: string, check it at webContent.getPrinters()
   timeOutPerLine: 400
}

const data = [
   {
     type: 'image',                                       
     path: path.join(__dirname, 'assets/banner.png'),     // file path
     position: 'center',                                  // position of image: 'left' | 'center' | 'right'
     width: 60,                                           // width of image in px; default: auto
     height: 60,                                          // width of image in px; default: 50 or '50px'
   },{
      type: 'text',                                       // 'text' | 'barCode' | 'qrCode' | 'image'
      value: 'SAMPLE HEADING',
      style: `text-align:center;`,
      css: {"font-weight": "700", "font-size": "18px"}
   },{
      type: 'text',                       // 'text' | 'barCode' | 'qrCode' | 'image'
      value: 'Secondary text',
      style: `text-align:left;color: red;`,
      css: {"text-decoration": "underline", "font-size": "10px"}
   },{
      type: 'barCode',
      value: 'HB4587896',
      height: 12,                     // height of barcode, applicable only to bar and QR codes
      width: 1,                       // width of barcode, applicable only to bar and QR codes
      displayValue: true,             // Display value below barcode
      fontsize: 8,
   },{
     type: 'qrCode',
      value: 'https://github.com/Hubertformin/electron-pos-printer',
      height: 55,
      width: 55,
      style: 'margin: 10 20px 20 20px'
    }
]

PosPrinter.print(data, options)
 .then(() => {})
 .catch((error) => {
    console.error(error);
  });

Typescript

Usage

import {PosPrinter, PosPrintData, PosPrintOptions} from "electron-pos-printer";
import * as path from "path";

const options: PosPrintOptions = {
   preview: false,
   width: '170px',       
   margin: '0 0 0 0',    
   copies: 1,
   printerName: 'XP-80C',
   timeOutPerLine: 400
}

const data: PosPrintData[] = [
   {
     type: 'image',                               
     path: path.join(__dirname, 'assets/banner.png'),
     position: 'center',
     width: 60,
     height: 60
   },{
      type: 'text',
      value: 'SAMPLE HEADING',
      style: `text-align:center;`,
      css: {"font-weight": "700", "font-size": "18px"}
   },{
      type: 'barCode',
      value: 'HB4587896',
      height: 12,
      width: 1,
      displayValue: true,
      fontsize: 8,
    },{
     type: 'qrCode',
      value: 'https://github.com/Hubertformin/electron-pos-printer',
      height: 55,
      width: 55,
      style: 'text-align:center;width:55px;margin: 10 20px 20 20px'
    }
]

PosPrinter.print(data, options)
 .then(() => {})
 .catch((error) => {
    console.error(error);
  });

Printing options

Options
copies (number) number of copies to print
preview (boolean) preview in a window, default is false
width (string) width of a page
margin (string) margin of a page, css values can be used
printerName (string) the printer's name
timeOutPerLine (number) timeout per line, default is 200

Print data object

type (string) 'text', 'qrCode', 'barCode', 'image' // type 'text' can contain html
value (string) value of the current row
height (number) applicable to type barCode and qrCode
width (number) applicable to type barCode and qrCode
style (string) styles, css rules can be used
css (string) css rules ex: {"font-size": "12px"}
displayValue (boolean) display value of barcode below barcode
position (string) 'left', 'center', 'right' applicable to type qrCode, barCode and image
path (string) Path to the image asset

Author

Credits

This package was inspired by electron-thermal-printer

electron-pos-printer's People

Contributors

hubertformin avatar jfamousket avatar

Watchers

James Cloos 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.