@luckykiet/node-printer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog ADDED
@@ -0,0 +1,36 @@
1
+ 2016.09.10, version 0.2.2
2
+ * correct memory leak (thanks to @kjlaw89)
3
+
4
+ 2015.10.22, version 0.2.1
5
+ * corrected printDirect with buffer data for node v4.X (#95)
6
+ * corrected segmentation fault from get default printer for node v0.10.X
7
+
8
+ 2015.09, version 0.2.0
9
+ * added possibility to compile with node v4.X
10
+ * various bug/core dumps fix
11
+
12
+ 2015.04, version 0.1.2
13
+ * posix: new method getPrinterDriverOptions(printerName) to retrieve PPD options
14
+ * posix: new method getSelectedPaperSize(printerName) to retrieve the current paper size name
15
+ * posix: new parameter `options` added to `printDirect` to set printer options (ex. `fit-to-page`, `media`, etc)
16
+ * posix: new function printFile() to print a file
17
+
18
+ 2015.03.03, version 0.1.1
19
+ * possibility to build for node-webkit with grunt
20
+
21
+ 2015.02.26, version 0.1.0
22
+ * possibility to load native module for platform/arch: node_module_{platform}_{arch}.node
23
+
24
+ 2015.02.24, Version 0.0.5
25
+ * added getDefaultPrinterName() method by returning the default printer name
26
+ * make printer argument optional in getPrinter() and printDirect. If is missing, will try to print to default printer
27
+ * resolve charest of getPrinter() #38
28
+ * posix/win32: added more explicit errors
29
+ * posix: do not throw error if job status code is not supported
30
+
31
+ 2015.01.30, Version 0.0.4
32
+ * win: added RPC installed printers in getPrinters #40
33
+ * posix: on some devices not all formats are supported, issue #23
34
+ * posix: added link settings on build #28
35
+ * corrected README.md
36
+ * corrected examples
package/Gruntfile.js ADDED
@@ -0,0 +1,75 @@
1
+ module.exports = function(grunt) {
2
+ grunt.initConfig({
3
+ gyp: {
4
+ ia32: {
5
+ command: 'rebuild',
6
+ options: {
7
+ arch: 'ia32'
8
+ }
9
+ },
10
+ x64: {
11
+ command: 'rebuild',
12
+ options: {
13
+ arch: 'x64'
14
+ }
15
+ }
16
+ },
17
+ "nw-gyp": {
18
+ ia32: {
19
+ command: 'rebuild',
20
+ options: {
21
+ arch: 'ia32'
22
+ }
23
+ },
24
+ x64: {
25
+ command: 'rebuild',
26
+ options: {
27
+ arch: 'x64'
28
+ }
29
+ }
30
+ },
31
+ copy: {
32
+ ia32: {
33
+ files: [{src: 'build/Release/node_printer.node', dest: 'lib/node_printer_' + process.platform + '_ia32.node'}]
34
+ },
35
+ x64: {
36
+ files: [{src: 'build/Release/node_printer.node', dest: 'lib/node_printer_' + process.platform + '_x64.node'}]
37
+ }
38
+ }
39
+ });
40
+
41
+ grunt.loadNpmTasks('grunt-contrib-jshint');
42
+ grunt.loadNpmTasks('grunt-node-gyp');
43
+ grunt.loadNpmTasks('grunt-nw-gyp');
44
+ grunt.loadNpmTasks('grunt-contrib-copy');
45
+
46
+ grunt.registerTask('build-nw-ia32', [
47
+ 'nw-gyp:ia32',
48
+ 'copy:ia32'
49
+ ]);
50
+
51
+ grunt.registerTask('build-ia32', [
52
+ 'gyp:ia32',
53
+ 'copy:ia32'
54
+ ]);
55
+
56
+ grunt.registerTask('build-x64', [
57
+ 'gyp:x64',
58
+ 'copy:x64'
59
+ ]);
60
+
61
+ grunt.registerTask('build-nw-x64', [
62
+ 'nw-gyp:x64',
63
+ 'copy:x64'
64
+ ]);
65
+
66
+ grunt.registerTask('build', [
67
+ 'build-ia32',
68
+ 'build-x64'
69
+ ]);
70
+
71
+ grunt.registerTask('build-nw', [
72
+ 'build-nw-ia32',
73
+ 'build-nw-x64'
74
+ ]);
75
+ }
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ Node Printer Prebuild
2
+ ============
3
+ Native bind printers on POSIX and Windows OS from Node.js, electron and node-webkit.
4
+
5
+ [![npm version](https://badge.fury.io/js/@thiagoelg%2Fnode-printer.svg)](https://www.npmjs.com/package/@thiagoelg/node-printer) [![Prebuild Binaries and Publish](https://github.com/thiagoelg/node-printer/actions/workflows/prebuild-main.yml/badge.svg)](https://github.com/thiagoelg/node-printer/actions/workflows/prebuild-main.yml)
6
+
7
+ > It just works with Node 12 because of @thiagoelg in his [PR](https://github.com/tojocky/node-printer/pull/261)
8
+
9
+ > Prebuild and CI integration courtesy of @ekoeryanto in his [FORK](https://github.com/ekoeryanto/node-printer)
10
+
11
+ If you have a problem, ask question to [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tojocky/node-printer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) or find/create a new [Github issue](https://github.com/thiagoelg/node-printer/issues)
12
+
13
+ ___
14
+ ### **Below is the original README**
15
+ ___
16
+ ### Reason:
17
+
18
+ I was involved in a project where I need to print from Node.JS. This is the reason why I created this project and I want to share my code with others.
19
+
20
+
21
+ ### Features:
22
+
23
+ * no dependecies;
24
+ * native method wrappers from Windows and POSIX (which uses [CUPS 1.4/MAC OS X 10.6](http://cups.org/)) APIs;
25
+ * compatible with node v0.8.x, 0.9.x and v0.11.x (with 0.11.9 and 0.11.13);
26
+ * compatible with node-webkit v0.8.x and 0.9.2;
27
+ * `getPrinters()` to enumerate all installed printers with current jobs and statuses;
28
+ * `getPrinter(printerName)` to get a specific/default printer info with current jobs and statuses;
29
+ * `getPrinterDriverOptions(printerName)` ([POSIX](http://en.wikipedia.org/wiki/POSIX) only) to get a specific/default printer driver options such as supported paper size and other info
30
+ * `getSelectedPaperSize(printerName)` ([POSIX](http://en.wikipedia.org/wiki/POSIX) only) to get a specific/default printer default paper size from its driver options
31
+ * `getDefaultPrinterName()` return the default printer name;
32
+ * `printDirect(options)` to send a job to a specific/default printer, now supports [CUPS options](http://www.cups.org/documentation.php/options.html) passed in the form of a JS object (see `cancelJob.js` example). To print a PDF from windows it is possible by using [node-pdfium module](https://github.com/tojocky/node-pdfium) to convert a PDF format into EMF and after to send to printer as EMF;
33
+ * `printFile(options)` ([POSIX](http://en.wikipedia.org/wiki/POSIX) only) to print a file;
34
+ * `getSupportedPrintFormats()` to get all possible print formats for printDirect method which depends on OS. `RAW` and `TEXT` are supported from all OS-es;
35
+ * `getJob(printerName, jobId)` to get a specific job info including job status;
36
+ * `setJob(printerName, jobId, command)` to send a command to a job (e.g. `'CANCEL'` to cancel the job);
37
+ * `getSupportedJobCommands()` to get supported job commands for setJob() depends on OS. `'CANCEL'` command is supported from all OS-es.
38
+
39
+
40
+ ### How to install:
41
+ ```
42
+ npm install @thiagoelg/node-printer
43
+ ```
44
+
45
+ ### How to use:
46
+
47
+ See [examples](https://github.com/thiagoelg/node-printer/tree/main/examples)
48
+
49
+ ### Author(s):
50
+
51
+ * Ion Lupascu, ionlupascu@gmail.com
52
+
53
+ ### Contibutors:
54
+
55
+ * Thiago Lugli, @thiagoelg
56
+ * Eko Eryanto, @ekoeryanto
57
+
58
+ Feel free to download, test and propose new futures
59
+
60
+ ### License:
61
+ [The MIT License (MIT)](http://opensource.org/licenses/MIT)
package/binding.gyp ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "variables": {
3
+ "module_name%": "node_printer",
4
+ "module_path%": "lib"
5
+ },
6
+ 'targets': [
7
+ {
8
+ "target_name": "action_after_build",
9
+ "type": "none",
10
+ "dependencies": [ "<(module_name)" ],
11
+ "copies": [
12
+ {
13
+ "files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
14
+ "destination": "<(module_path)"
15
+ }
16
+ ]
17
+ },
18
+ {
19
+ 'target_name': 'node_printer',
20
+ 'sources': [
21
+ '<!@(["python3", "tools/getSourceFiles.py", "src", "cc"])'
22
+ ],
23
+ 'include_dirs' : [
24
+ "<!(node -e \"require('nan')\")"
25
+ ],
26
+ 'cflags_cc+': [
27
+ "-std=c++20",
28
+ "-Wno-deprecated-declarations"
29
+ ],
30
+ 'conditions': [
31
+ # common exclusions
32
+ ['OS!="linux"', {'sources/': [['exclude', '_linux\\.cc$']]}],
33
+ ['OS!="mac"', {'sources/': [['exclude', '_mac\\.cc|mm?$']]}],
34
+ ['OS!="win"', {
35
+ 'sources/': [['exclude', '_win\\.cc$']]}, {
36
+ # else if OS==win, exclude also posix files
37
+ 'sources/': [['exclude', '_posix\\.cc$']]
38
+ }],
39
+ # specific settings
40
+ ['OS!="win"', {
41
+ 'cflags':[
42
+ '<!(cups-config --cflags)'
43
+ ],
44
+ 'ldflags':[
45
+ '<!(cups-config --libs)'
46
+ ],
47
+ 'libraries':[
48
+ '<!(cups-config --libs)'
49
+ ],
50
+ 'link_settings': {
51
+ 'libraries': [
52
+ '<!(cups-config --libs)'
53
+ ]
54
+ }
55
+ }],
56
+ ['OS=="mac"', {
57
+ 'cflags':[
58
+ "-stdlib=libc++"
59
+ ],
60
+ 'xcode_settings': {
61
+ "OTHER_CPLUSPLUSFLAGS":["-std=c++20", "-stdlib=libc++"],
62
+ "OTHER_LDFLAGS": ["-stdlib=libc++"],
63
+ "MACOSX_DEPLOYMENT_TARGET": "10.15",
64
+ "CLANG_CXX_LANGUAGE_STANDARD": "c++20",
65
+ },
66
+ }],
67
+ ['OS=="win"', {
68
+ 'msvs_settings': {
69
+ 'VCCLCompilerTool': {
70
+ 'AdditionalOptions': ['/std:c++20'],
71
+ },
72
+ },
73
+ }],
74
+ ]
75
+ }
76
+ ]
77
+ }
@@ -0,0 +1,34 @@
1
+ var printer = require("../lib"),
2
+ util = require('util'),
3
+ printerName = 'Foxit Reader PDF Printer',
4
+ printerFormat = 'TEXT';
5
+
6
+ printer.printDirect({
7
+ data:"print from Node.JS buffer", // or simple String: "some text"
8
+ printer:printerName, // printer name
9
+ type: printerFormat, // type: RAW, TEXT, PDF, JPEG, .. depends on platform
10
+ options: // supported page sizes may be retrieved using getPrinterDriverOptions, supports CUPS printing options
11
+ {
12
+ media: 'Letter',
13
+ 'fit-to-page': true
14
+ },
15
+ success:function(jobID){
16
+ console.log("sent to printer with ID: "+jobID);
17
+ var jobInfo = printer.getJob(printerName, jobID);
18
+ console.log("current job info:"+util.inspect(jobInfo, {depth: 10, colors:true}));
19
+ if(jobInfo.status.indexOf('PRINTED') !== -1)
20
+ {
21
+ console.log('too late, already printed');
22
+ return;
23
+ }
24
+ console.log('cancelling...');
25
+ var is_ok = printer.setJob(printerName, jobID, 'CANCEL');
26
+ console.log("cancelled: "+is_ok);
27
+ try{
28
+ console.log("current job info:"+util.inspect(printer.getJob(printerName, jobID), {depth: 10, colors:true}));
29
+ }catch(err){
30
+ console.log('job deleted. err:'+err);
31
+ }
32
+ },
33
+ error:function(err){console.log(err);}
34
+ });
@@ -0,0 +1,15 @@
1
+ var printer = require("../lib")
2
+ , template = "N\nS4\nD15\nq400\nR\nB20,10,0,1,2,30,173,B,\"barcode\"\nP0\n";
3
+
4
+ function printZebra(barcode_text, printer_name){
5
+ printer.printDirect({data:template.replace(/barcode/, barcode_text)
6
+ , printer:printer_name
7
+ , type: "RAW"
8
+ , success:function(){
9
+ console.log("printed: "+barcode_text);
10
+ }
11
+ , error:function(err){console.log(err);}
12
+ });
13
+ }
14
+
15
+ printZebra("123", "ZEBRA");
@@ -0,0 +1,4 @@
1
+ var printer = require("../lib");
2
+
3
+ console.log('default printer name: ' + (printer.getDefaultPrinterName() || 'is not defined on your computer'));
4
+
@@ -0,0 +1,9 @@
1
+ var printer = require("../lib"),
2
+ util = require('util'),
3
+ printers = printer.getPrinters();
4
+
5
+ printers.forEach(function(iPrinter, i){
6
+ console.log('' + i + 'ppd for printer "' + iPrinter.name + '":' + util.inspect(printer.getPrinterDriverOptions(iPrinter.name), {colors:true, depth:10} ));
7
+ console.log('\tselected page size:'+ printer.getSelectedPaperSize(iPrinter.name) + '\n');
8
+ });
9
+
@@ -0,0 +1,3 @@
1
+ var printer = require("../lib"),
2
+ util = require('util');
3
+ console.log("installed printers:\n"+util.inspect(printer.getPrinters(), {colors:true, depth:10}));
@@ -0,0 +1,3 @@
1
+ var printer = require("../lib"),
2
+ util = require('util');
3
+ console.log("supported formats are:\n"+util.inspect(printer.getSupportedPrintFormats(), {colors:true, depth:10}));
@@ -0,0 +1,3 @@
1
+ var printer = require("../lib"), //=require('pritner')
2
+ util = require('util');
3
+ console.log("supported job commands:\n"+util.inspect(printer.getSupportedJobCommands(), {colors:true, depth:10}));
@@ -0,0 +1,30 @@
1
+ // use: node printFile.js [filePath printerName]
2
+ var printer = require("../lib"),
3
+ filename = process.argv[2] || __filename;
4
+
5
+ console.log('platform:', process.platform);
6
+ console.log('try to print file: ' + filename);
7
+
8
+ if( process.platform != 'win32') {
9
+ printer.printFile({filename:filename,
10
+ printer: process.env[3], // printer name, if missing then will print to default printer
11
+ success:function(jobID){
12
+ console.log("sent to printer with ID: "+jobID);
13
+ },
14
+ error:function(err){
15
+ console.log(err);
16
+ }
17
+ });
18
+ } else {
19
+ // not yet implemented, use printDirect and text
20
+ var fs = require('fs');
21
+ printer.printDirect({data:fs.readFileSync(filename),
22
+ printer: process.env[3], // printer name, if missing then will print to default printer
23
+ success:function(jobID){
24
+ console.log("sent to printer with ID: "+jobID);
25
+ },
26
+ error:function(err){
27
+ console.log(err);
28
+ }
29
+ });
30
+ }
@@ -0,0 +1,37 @@
1
+ // Windows does not support PDF formats, but you can use imagemagick-native to achieve conversion from PDF to EMF.
2
+
3
+ var printer = require("../lib"),
4
+ fs = require('fs'),
5
+ path = require('path'),
6
+ filename = process.argv[2],
7
+ printername = process.argv[3];
8
+
9
+ if(process.platform == 'win32') {
10
+ throw 'Not yet supported for win32'
11
+ }
12
+
13
+ if(!filename || filename == '-h') {
14
+ throw 'PDF file name is missing. Please use the following params: <filename> [printername]'
15
+ }
16
+
17
+ filename = path.resolve(process.cwd(), filename);
18
+ console.log('printing file name ' + filename);
19
+
20
+ fs.readFile(filename, function(err, data){
21
+ if(err) {
22
+ console.error('err:' + err);
23
+ return;
24
+ }
25
+ console.log('data type is: '+typeof(data) + ', is buffer: ' + Buffer.isBuffer(data));
26
+ printer.printDirect({
27
+ data: data,
28
+ type: 'PDF',
29
+ success: function(id) {
30
+ console.log('printed with id ' + id);
31
+ },
32
+ error: function(err) {
33
+ console.error('error on printing: ' + err);
34
+ }
35
+ })
36
+ });
37
+
@@ -0,0 +1,52 @@
1
+ // Windows does not support PDF formats, but you can use imagemagick-native to achieve conversion from PDF to EMF.
2
+
3
+ var printer = require("../lib"),
4
+ imagemagick, // will be loaded later with proper error.
5
+ fs = require('fs'),
6
+ filename = process.argv[2],
7
+ printername = process.argv[2];
8
+
9
+ if(process.platform !== 'win32') {
10
+ throw 'This application can be run only on win32 as a demo of print PDF image'
11
+ }
12
+
13
+ if(!filename) {
14
+ throw 'PDF file name is missing. Please use the following params: <filename> [printername]'
15
+ }
16
+
17
+ try {
18
+ imagemagick = require('imagemagick-native');
19
+ } catch(e) {
20
+ throw 'please install imagemagick-native: `npm install imagemagick-native`'
21
+ }
22
+
23
+ var data = fs.readFileSync(filename);
24
+
25
+ console.log('data: ' + data.toString().substr(0, 20));
26
+
27
+ //console.log(imagemagick.identify({srcData: data}));
28
+
29
+ // First convert PDF into
30
+ imagemagick.convert({
31
+ srcData: data,
32
+ srcFormat: 'PDF',
33
+ format: 'EMF',
34
+ }, function(err, buffer) {
35
+ if (err) {
36
+ throw 'something went wrong on converting to EMF: ' + err;
37
+ }
38
+
39
+ // Now we have EMF file, send it to printer as EMF format
40
+ printer.printDirect({
41
+ data: buffer,
42
+ type: 'EMF',
43
+ success: function(id) {
44
+ console.log('printed with id ' + id);
45
+ },
46
+ error: function(err) {
47
+ console.error('error on printing: ' + err);
48
+ }
49
+ })
50
+ })
51
+
52
+
@@ -0,0 +1,10 @@
1
+ var printer = require("../lib");
2
+
3
+ printer.printDirect({data:"print from Node.JS buffer" // or simple String: "some text"
4
+ //, printer:'Foxit Reader PDF Printer' // printer name, if missing then will print to default printer
5
+ , type: 'RAW' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
6
+ , success:function(jobID){
7
+ console.log("sent to printer with ID: "+jobID);
8
+ }
9
+ , error:function(err){console.log(err);}
10
+ });
Binary file
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./printer');
Binary file