├── .gitignore ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules/ 3 | 4 | npm-debug\.log 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # electron-print 2 | 3 | > Allows printing from an Electron App in silent mode using the default printer of the system. 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install --save electron-print 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | const printer = require('electron-print'); 15 | 16 | app.on('ready', function() { 17 | printer.print("Text sent to printer.") 18 | }); 19 | 20 | ``` 21 | 22 | ## Version 23 | 24 | 1.0.3 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-print", 3 | "version": "1.0.2", 4 | "description": "Library to print from electron app.", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "electron ." 8 | }, 9 | "repository": "meerkat999/electron-print", 10 | "keywords": [ 11 | "electron", 12 | "print", 13 | "printer" 14 | ], 15 | "author": "Crisman Carmona ", 16 | "license": "ISC", 17 | "dependencies": { 18 | "file-system": "^2.2.2", 19 | "path": "^0.12.7", 20 | "electron": "^1.8.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const electron = require('electron'); 3 | const BrowserWindow = electron.BrowserWindow; 4 | const fs = require('fs') 5 | const path = require('path') 6 | 7 | module.exports = { 8 | print : print 9 | } 10 | 11 | function print(text){ 12 | let win = new BrowserWindow({show: false}) 13 | fs.writeFile(path.join(__dirname,'print.txt'), text) 14 | win.loadURL('file://'+__dirname+'/print.txt') 15 | win.webContents.on('did-finish-load', () => { 16 | win.webContents.print({silent:true}) 17 | setTimeout(function(){ 18 | win.close(); 19 | }, 1000); 20 | }) 21 | } 22 | --------------------------------------------------------------------------------