Giter VIP home page Giter VIP logo

node-printer's Introduction

node-printer

Native bind printers on POSIX and Windows OS from Node.js, electron and node-webkit.

Linux Windows Dependencies

If you have a problem, ask question to Gitter or find/create a new Github issue

Reason:

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.

Features:

  • no dependecies;
  • native method wrappers from Windows and POSIX (which uses CUPS 1.4/MAC OS X 10.6) APIs;
  • compatible with node v0.8.x, 0.9.x and v0.11.x (with 0.11.9 and 0.11.13);
  • compatible with node-webkit v0.8.x and 0.9.2;
  • getPrinters() to enumerate all installed printers with current jobs and statuses;
  • getPrinter(printerName) to get a specific/default printer info with current jobs and statuses;
  • getPrinterDriverOptions(printerName) (POSIX only) to get a specific/default printer driver options such as supported paper size and other info
  • getSelectedPaperSize(printerName) (POSIX only) to get a specific/default printer default paper size from its driver options
  • getDefaultPrinterName() return the default printer name;
  • printDirect(options) to send a job to a specific/default printer, now supports CUPS options 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 to convert a PDF format into EMF and after to send to printer as EMF;
  • printFile(options) (POSIX only) to print a file;
  • getSupportedPrintFormats() to get all possible print formats for printDirect method which depends on OS. RAW and TEXT are supported from all OS-es;
  • getJob(printerName, jobId) to get a specific job info including job status;
  • setJob(printerName, jobId, command) to send a command to a job (e.g. 'CANCEL' to cancel the job);
  • getSupportedJobCommands() to get supported job commands for setJob() depends on OS. 'CANCEL' command is supported from all OS-es.

How to install:

npm install printer

How to use:

See examples

Author(s):

Contibutors:

  • Thiago Lugli, @thiagoelg
  • Eko Eryanto, @ekoeryanto

Feel free to download, test and propose new futures

License:

The MIT License (MIT)

node-printer's People

Contributors

alexeyst avatar antoinepairet avatar chieffancypants avatar demiand avatar dependabot[bot] avatar duncanhall avatar ekoeryanto avatar ericz avatar george-g avatar gitawego avatar gitter-badger avatar goooseman avatar kjlaw89 avatar klawrence-fs avatar kpitn avatar oozzal avatar peterjuras avatar rootedsoftware avatar rvanzon avatar sametcodes avatar steinmetz85 avatar tauu avatar thiagoelg avatar tojocky avatar vasumahesh1 avatar whitef0x0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-printer's Issues

no license

I couldn't find a license for this project. I'm hoping for something like bsd or mit since I would like to copy parts of it.

getPrinters(); TypeError: wrong job status

Thanks for this package, am running into some trouble getting the list of printers.

Here is my code

var printer = require("./node_modules/printer/lib"),
    util = require('util');
console.log("installed printers:\n"+util.inspect(printer.getPrinters(), {colors:true, depth:10}));

The error message

pi@pi-rasp /var/www/nodejs $ node printc

/var/www/nodejs/node_modules/printer/lib/printer.js:57
    var printers = printer_helper.getPrinters();
                                  ^
TypeError: wrong job status:
    at Object.getPrinters (/var/www/nodejs/node_modules/printer/lib/printer.js:57:35)
    at Object.<anonymous> (/var/www/nodejs/printc.js:3:58)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3

Package version: 0.0.5
NodeJS: v0.10.35
CUPS version: 1.5.3
System: Linux pi-rasp 3.18.5+ #748 PREEMPT Wed Feb 4 21:24:41 GMT 2015 armv6l GNU/Linux

ESC/POS commands

Hi,

Is it possible to send esc/pos commands to a printer with your module? If yes, could you please provide an example?

best,

Create a gitter room

Is it possible to create a gitter room in order to discuss, have a advice from each other ?

Thank you
Thomas

node-webkit install error

Trying to install from node-webkit but failing. Unless I overlooked it I couldn’t find the same problem in other issues. Any ideas?

    npm ERR! Failed to parse json
    npm ERR! Unexpected token /
    npm ERR! File: E:\WebstormProjects\innovation-sales-order-entry\www\package.json
    npm ERR! Failed to parse package.json data.
    npm ERR! package.json must be actual JSON, not just JavaScript.
    npm ERR!
    npm ERR! This is not a bug in npm.
    npm ERR! Tell the package author to fix their package.json file. JSON.parse

    npm ERR! System Windows_NT 6.1.7601
    npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "printer"
    npm ERR! cwd E:\WebstormProjects\innovation-sales-order-entry\www
    npm ERR! node -v v0.10.32
    npm ERR! npm -v 1.4.28
    npm ERR! file E:\WebstormProjects\innovation-sales-order-entry\www\package.json
    npm ERR! code EJSONPARSE
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR!     E:\WebstormProjects\innovation-sales-order-entry\www\npm-debug.log
    npm ERR! not ok code 0

License Information

How will you be licensing this thing? I hope I'm not overlooking, but I didn't see anything mentioned yet.

undefined symbol: cupsGetDests

Tried the getPrinters example with linux but the only thing I get when I run it is error undefined symbol: cupsGetDests, do you have any idea what might be causing this?

print chinese text will be garbled

var printer = require("../lib");

printer.printDirect({data:"中文測試" // or simple String: "some text"
, printer:'櫃台' // printer name
, type: 'TEXT' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
, success:function(jobID){
console.log("sent to printer with ID: "+jobID);
}
, error:function(err){console.log(err);}
});

the 中文測試 will print "@$@%?@#$@"
how can i do ???

How Can I get the default printer name?

I have to get the default printer name in a project and show it as user's default choice.
How can I achieve that using node-printer?

If there do have a way to get that, please tell me how. If not, let getPrinter(printerName) method return the default printer when printerName isn't provided maybe a good idea.

Thanks a lot.

Specify size on paper

Hi,
Is there a way to specify the output size?
I've tried printing both a PDF file and text. Printing works fine, but for some reason it doesn't fill the whole page. Instead it just fills a small rectangle on the page (see image).

Is this something I need to set in the printer settings in my OS?
(I'm on Mac OSX Yosemite)

install problems

I tried install from npm but it was an old version. Then I tried
npm install https://github.com/tojocky/node-printer.git -g�
and I got the error below. I'm on windows 8.0 with node 10.25 Do you think it would help if I tried updating node?

C:\apps>npm install https://github.com/tojocky/node-printer.git -g
npm http GET https://github.com/tojocky/node-printer.git
npm http 200 https://github.com/tojocky/node-printer.git
npm ERR! not a package C:\Users\ADMINI~1\AppData\Local\Temp\npm-12852-yo89SyBA\1405565019139-0.45655751368030906\tmp.tgz
npm ERR! Error: ENOENT, open 'C:\Users\ADMINI~1\AppData\Local\Temp\npm-12852-yo89SyBA\1405565019139-0.45655751368030906\package\pa
ckage.json'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.j
s" "install" "https://github.com/tojocky/node-printer.git" "-g"
npm ERR! cwd C:\apps
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! path C:\Users\ADMINI~1\AppData\Local\Temp\npm-12852-yo89SyBA\1405565019139-0.45655751368030906\package\package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\apps\npm-debug.log
npm ERR! not ok code 0

Nothing gets printed

Hi When i try to print a raw data am getting the script does not show any error, and the print queue shows the print job. But nothing gets printed.

Code

var printer = require("printer");
var printerName = "HP LaserJet P1007" ;

console.log("---------------------")
console.log(printer.getSupportedPrintFormats(printerName))
console.log("---------------------")
console.log(printer.getSupportedJobCommands(printerName))
console.log("---------------------")
printer.printDirect({
data:new Buffer("I will be written"),
printer: printerName,
type: "RAW" ,
success:function(jobID){
console.log("Job sent with ID: " + jobID)
var jobInfo = printer.getJob(printerName, jobID)
console.log("Job info:" + JSON.stringify(jobInfo, null, 2))
},
error:function(err){console.log(err)}
})

Console output

D:\ProjectITCS\bin>node printer.js

[ 'RAW', 'TEXT' ]

[ 'CANCEL',
'DELETE',
'LAST-PAGE-EJECTED',
'PAUSE',
'RESTART',
'RESUME',

'SENT-TO-PRINTER' ]

Job sent with ID: 18
Job info:{
"id": 18,
"name": "HP LaserJet P1007",
"printerName": "HP LaserJet P1007",
"user": "ram",
"format": "RAW",
"priority": 1,
"size": 17,
"status": [
"PRINTING"
],
"machineName": "\RAMKISHORE",
"document": "node print job",
"notifyName": "ram",
"printProcessor": "HP1006PrintProc",
"driverName": "HP LaserJet P1007",
"position": 1,
"startTime": 0,
"untilTime": 0,
"totalPages": 1,
"time": 221645312,
"pagesPrinted": 0
}

Fail to build on OSX Yosemite

When I try to build node-printer, this is the error I get:

$ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/hanxue/Github/node-printer/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/hanxue/.node-gyp/0.10.28/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/hanxue/.node-gyp/0.10.28',
gyp info spawn args   '-Dmodule_root_dir=/Users/hanxue/Github/node-printer',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/node_printer/src/node_printer.o
  CXX(target) Release/obj.target/node_printer/src/node_printer_posix.o
  SOLINK_MODULE(target) Release/node_printer.node
c++: error: Kerberos: No such file or directory
c++: error: GSS: No such file or directory
c++: error: unrecognized command line option '-weak_framework'
c++: error: unrecognized command line option '-weak_framework'
make: *** [Release/node_printer.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:807:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/hanxue/Github/node-printer
gyp ERR! node -v v0.10.28
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok 

Not sure why the C++ linking step fails, and I cannot find any further information.

It actualy depend on libcups2-dev, isn't it?

The README.md said:

* no dependecies;

BUT! when I try to install it:

$ npm install printer --save
info attempt registry request try #1 at 09:56:27
http request GET https://registry.npmjs.org/printer
http 304 https://registry.npmjs.org/printer

> [email protected] install /path/to/my/project
> node-gyp rebuild

/bin/sh: 1: cups-config: not found
gyp: Call to 'cups-config --libs' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error 
...

I'd try to run:

$ cups-config --libs
The program 'cups-config' is currently not installed. You can install it by typing:
sudo apt-get install libcups2-dev

so??

Build on Windows passes but module not build completely

I'm getting only the printDirect function exposed when requiring the module.

This is the output of the module when installing:

c:\Users\dev\Code\node-printer>npm i printer
npm WARN engine [email protected]: wanted: {"node":">= 0.8.0 && < 0.9.0"} (current: {"node":"v0.10.29","npm":"1.4.14"})
|


> [email protected] install c:\Users\dev\Code\node_modules\printer
> node-gyp rebuild


c:\Users\dev\Code\node_modules\printer>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modul
es\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  node_printer.cc
C:\Users\dev\.node-gyp\0.10.29\deps\v8\include\v8.h(179): warning C4506: no definition for inline function 'v8::Persist
ent<v8::Object> v8::Persistent<v8::Object>::New(v8::Handle<v8::Object>)' [c:\Users\dev\Code\node_modules\printer\build\
node_printer.vcxproj]
     Creating library c:\Users\dev\Code\node_modules\printer\build\Release\node_printer.lib and object c:\Users\dev\Cod
  e\node_modules\printer\build\Release\node_printer.exp
  Generating code
  Finished generating code
  node_printer.vcxproj -> c:\Users\dev\Code\node_modules\printer\build\Release\\node_printer.node
[email protected] ..\node_modules\printer

c:\Users\dev\Code\node-printer>

Info of machine:

  • Building on Windows 7 64-bits
  • Visual Studio 2013
  • NodeJS @ 0.10.28
  • npm @ 1.4.14

Example:

var printer = require('printer');
console.log(printer);

returns: { printDirect: [Function: printDirect] }

Any ideas? Please advise :)

cupsGetDefault2 can return NULL

If CUPS server has no default printer defined, cupsGetDefault2 return NULL instead of empty string.

Workaround: in node_printer_posix.cc

MY_NODE_MODULE_CALLBACK(getDefaultPrinterName)
{
MY_NODE_MODULE_HANDLESCOPE;
const char * defaultDest = cupsGetDefault2(CUPS_HTTP_DEFAULT);
if( defaultDest == NULL ) {
defaultDest = "";
}
MY_NODE_MODULE_RETURN_VALUE(V8_STRING_NEW_UTF8(defaultDest));
}

this can npm install in raspberry pi ??

i use npm install printer is not work

and

i download all file and use npm install also not work .....

how can i do ???

ps. i use in windows8 is ok ~~~but now i want use in raspberry pi (arm)
i use RASPBIAN Debian Wheezy os

Print PDF from Windows

Here's the link to the PDF:

https://drive.google.com/file/d/0B4xBPiAxQ7h5STZPWjlGREJKd0k/view?usp=sharing

We used MS Word to create a PDF and that printed fine. The above PDF was generated using a PHP library called FPDF:

I'm using this code to print it. When we attempt to print the above PDF, the printer will get the data, but it will not print it.

printer.printDirect({
    data:  fs.readFileSync('./doc.pdf')
    , printer: 'Ricoh Aficio MP C2500 PCL5c' // printer name, that does exist
    , type: 'RAW'
    , success: function (jobID)  {
        console.log("sent to printer with ID: " + jobID);
    }
    , error: function (err) {
        throw new Error(err);
    }
});

install from git ERR!

npm install https://github.com/tojocky/node-printer.git

npm ERR! not a package /tmp/npm-7537-MVNlAfXT/github.com/tojocky/node-printer.git
npm ERR! Error: ENOENT, open '/tmp/npm-7537-MVNlAfXT/github.com/tojocky/node-printer.git-unpack/package.json'
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/npm/npm/issues

npm ERR! System Linux 3.13.0-37-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/tojocky/node-printer.git"
npm ERR! cwd /home/ming/node_webkit_projects/godzilla/node_modules/printer/examples
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! path /tmp/npm-7537-MVNlAfXT/github.com/tojocky/node-printer.git-unpack/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ming/node_webkit_projects/godzilla/node_modules/printer/examples/npm-debug.log
npm ERR! not ok code 0

Error: no error in node-webkit. Windows 8

Hi, I installed node-Printer with npm install printer

npm install printer --save

npm WARN package.json nw-demo@ No repository field.
npm http GET https://registry.npmjs.org/printer
npm http 200 https://registry.npmjs.org/printer
npm http GET https://registry.npmjs.org/printer/-/printer-0.0.2.tgz
npm http 200 https://registry.npmjs.org/printer/-/printer-0.0.2.tgz

[email protected] install C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_mod
ules\printer
node-gyp rebuild

C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_modules\printer>node "C:\Pr
ogram Files\nodejs\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gy
p\bin\node-gyp.js" rebuild
Los proyectos de esta solución se van a compilar de uno en uno. Para habilitar l
a compilación en paralelo, agregue el modificador "/m".
node_printer.cc
node_printer_win.cc
C:\Users\Eduardo.node-gyp\0.10.17\deps\v8\include\v8.h(218): warning C4506: no
definition for inline function 'v8::Persistent v8::Persistent::New(v8::H
andle)' [C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_modules\printe
r\build\node_printer.vcxproj]
with

T=v8::Object

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xlocale(336): wa
rning C4530: C++ exception handler used, but unwind semantics are not enabled.
Specify /EHsc (..\src\node_printer_win.cc) [C:\Users\Eduardo\dev\Inventory-with
-node-webkit\node_modules\printer\build\node_printer.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0(627): w
arning C4506: no definition for inline function 'v8::Persistent v8::Persiste
nt::New(v8::Handle)' [C:\Users\Eduardo\dev\Inventory-with-node-webkit\nod
e_modules\printer\build\node_printer.vcxproj]
with

T=v8::Object

Creating library C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_modu
les\printer\build\Release\node_printer.lib and object C:\Users\Eduardo\dev\In
ventory-with-node-webkit\node_modules\printer\build\Release\node_printer.exp
Generating code
Finished generating code
node_printer.vcxproj -> C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_
modules\printer\build\Release\node_printer.node
[email protected] node_modules\printer

Then i tried this code

  var printer = require("./node_modules/printer/lib/"),
        util = require('util');
      console.log("supported formats are:\n"+util.inspect(printer.getSupportedPrintFormats(), {colors:true, depth:10}));

and this code

  var printer = require("printer"),
        util = require('util');
      console.log("supported formats are:\n"+util.inspect(printer.getSupportedPrintFormats(), {colors:true, depth:10}));

When I open node-webkit I have this error.

Error: no errorC:\Users\Eduardo\dev\Inventory-with-node-webkit\node_modules\printer\build\Release\node_printer.node
at Module.load (module.js:359:32)
at Function.Module._load (module.js:315:12)
at Module.require (module.js:367:17)
at require (module.js:383:17)
at Object.eval (C:\Users\Eduardo\dev\Inventory-with-node-webkit\node_modules\printer\lib\printer.js:7:18)
at Module._compile (module.js:459:26)
at Object.Module._extensions..js (module.js:477:10)
at Module.load (module.js:359:32)
at Function.Module._load (module.js:315:12)
at Module.require (module.js:367:17)

what's wrong?

How can I customize the output?

How can I make bold text, change font, increase font-size, etc? If it's done using the "raw" type, is there a guide for that?

Thank you!

Add new Printer

Is there any possibility to add a new printer? I really need this functionality, but before I start implementing C++ stuff, I better ask.

-- Trixt0r

configure cutter

there is a way to configure the automatic cutter? i use node printer with a mini printer

Image print from windows

Hello,

I am getting a blank page when doing:

var printer = require("printer");
var fs = require('fs')
printer.printDirect({data:fs.readFileSync('myimage.png')
    , printer:'PDFCreator'
    , type: 'RAW'
    , success:function(jobID){
        console.log("sent to printer with ID: "+jobID);
    }
    , error:function(err){console.log(err);}
});

i am on win7 x64.

any idea?

Installing (last version downloaded from github) node-printer in Node 0.11.13 doesn't work

[email protected] install /home/q2dg/node_modules/printer
node-gyp rebuild

make: Entering directory /home/q2dg/node_modules/printer/build' CXX(target) Release/obj.target/node_printer/src/node_printer.o In file included from ../src/node_printer.cc:1:0: ../src/node_printer.hpp:19:41: error: ‘Arguments’ in namespace ‘v8’ does not name a type v8::Handle<v8::Value> PrintDirect(const v8::Arguments& iArgs); ^ ../src/node_printer.hpp:19:56: error: ISO C++ forbids declaration of ‘iArgs’ with no type [-fpermissive] v8::Handle<v8::Value> PrintDirect(const v8::Arguments& iArgs); ^ ../src/node_printer.hpp:24:41: error: ‘Arguments’ in namespace ‘v8’ does not name a type v8::Handle<v8::Value> getPrinters(const v8::Arguments& iArgs); ^ ../src/node_printer.hpp:24:56: error: ISO C++ forbids declaration of ‘iArgs’ with no type [-fpermissive] v8::Handle<v8::Value> getPrinters(const v8::Arguments& iArgs); ^ ../src/node_printer.hpp:28:49: error: ‘Arguments’ in namespace ‘v8’ does not name a type v8::Handle<v8::Value> getSupportedFormats(const v8::Arguments& iArgs); ^ ../src/node_printer.hpp:28:64: error: ISO C++ forbids declaration of ‘iArgs’ with no type [-fpermissive] v8::Handle<v8::Value> getSupportedFormats(const v8::Arguments& iArgs); ^ ../src/node_printer.cc: In function ‘void initNode(v8::Handle<v8::Object>)’: ../src/node_printer.cc:5:54: error: no matching function for call to ‘NODE_SET_METHOD(v8::Handle<v8::Object>&, const char [12], v8::Handle<v8::Value> (&)(const int&))’ NODE_SET_METHOD(exports, "getPrinters", getPrinters); ^ ../src/node_printer.cc:5:54: note: candidate is: In file included from ../src/node_printer.hpp:4:0, from ../src/node_printer.cc:1: /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template<class TypeName> void node::NODE_SET_METHOD(const TypeName&, const char*, v8::FunctionCallback) inline void NODE_SET_METHOD(const TypeName& recv, ^ /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template argument deduction/substitution failed: ../src/node_printer.cc:5:54: note: cannot convert ‘getPrinters’ (type ‘v8::Handle<v8::Value>(const int&)’) to type ‘v8::FunctionCallback {aka void (*)(const v8::FunctionCallbackInfo<v8::Value>&)}’ NODE_SET_METHOD(exports, "getPrinters", getPrinters); ^ ../src/node_printer.cc:6:54: error: no matching function for call to ‘NODE_SET_METHOD(v8::Handle<v8::Object>&, const char [12], v8::Handle<v8::Value> (&)(const int&))’ NODE_SET_METHOD(exports, "printDirect", PrintDirect); ^ ../src/node_printer.cc:6:54: note: candidate is: In file included from ../src/node_printer.hpp:4:0, from ../src/node_printer.cc:1: /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template<class TypeName> void node::NODE_SET_METHOD(const TypeName&, const char*, v8::FunctionCallback) inline void NODE_SET_METHOD(const TypeName& recv, ^ /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template argument deduction/substitution failed: ../src/node_printer.cc:6:54: note: cannot convert ‘PrintDirect’ (type ‘v8::Handle<v8::Value>(const int&)’) to type ‘v8::FunctionCallback {aka void (*)(const v8::FunctionCallbackInfo<v8::Value>&)}’ NODE_SET_METHOD(exports, "printDirect", PrintDirect); ^ ../src/node_printer.cc:7:70: error: no matching function for call to ‘NODE_SET_METHOD(v8::Handle<v8::Object>&, const char [20], v8::Handle<v8::Value> (&)(const int&))’ NODE_SET_METHOD(exports, "getSupportedFormats", getSupportedFormats); ^ ../src/node_printer.cc:7:70: note: candidate is: In file included from ../src/node_printer.hpp:4:0, from ../src/node_printer.cc:1: /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template<class TypeName> void node::NODE_SET_METHOD(const TypeName&, const char*, v8::FunctionCallback) inline void NODE_SET_METHOD(const TypeName& recv, ^ /home/q2dg/.node-gyp/0.11.13/src/node.h:194:13: note: template argument deduction/substitution failed: ../src/node_printer.cc:7:70: note: cannot convert ‘getSupportedFormats’ (type ‘v8::Handle<v8::Value>(const int&)’) to type ‘v8::FunctionCallback {aka void (*)(const v8::FunctionCallbackInfo<v8::Value>&)}’ NODE_SET_METHOD(exports, "getSupportedFormats", getSupportedFormats); ^ make: *** [Release/obj.target/node_printer/src/node_printer.o] Error 1 make: Leaving directory/home/q2dg/node_modules/printer/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/q2dg/node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1046:12)
gyp ERR! System Linux 3.14.6-200.fc20.x86_64
gyp ERR! command "node" "/home/q2dg/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/q2dg/node_modules/printer
gyp ERR! node -v v0.11.13
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the printer package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls printer
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.14.6-200.fc20.x86_64
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "Escriptori/node-printer-master"
npm ERR! cwd /home/q2dg
npm ERR! node -v v0.11.13
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/q2dg/npm-debug.log
npm ERR! not ok code 0

getPrinters does not return all printers

HI
I have got some troubles on trying to get printers list, the method getPrinters does not return all the printers available on my computer.
After some investigations i found that the problem was related to the value of flags parameter passed in EnumPrintersW(flags, .......) see at line 407 in node_printer_win.cc file.
Indeed when i test getPrinters method on specifying the flags parameter like :
DWORD flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
It works perfectly.
Could you make this change please ?
Thank you

Image Print from MAC

I try to print a jpeg image and i get a error.
The node are sending the data to printer, but the printer get a error about "Filter".

The "text" printing is working.

My code:
var printer = require('printer'),
util = require('util');

printer.printDirect({data:"teste.jpeg" // or simple String: "some text"
  , printer:'EPSON_PictureMate_PM_225' // printer name
  , type: 'JPEG' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
  , success:function(jobID){
    console.log("sent to printer with ID: "+jobID);
  }
  , error:function(err){console.log(err);}
});

cups error

I keep getting this error:
node_modules/printer/build/Release/node_printer.node: undefined symbol: cupsCreateJob

I do have the lastest libcups-dev installed, tho?

Potential for command injection in printer/package/lib/printer.js

Overview

Untrusted input passed in to the printer attribute of the first argument to printDirect module can allow for command injection. This may be unexpected behavior for the caller.

Confirmed on version 0.0.1

Confirmed vulnerable. Examples:

var printer = require("printer");
printer.printDirect({data:"print from Node.JS"
, printer:"`ping google.com`"
, type: "TEXT"
, success:function(){
console.log("ok");
}
, error:function(err){console.log(err);}
});

Recommendation

  • If you do not need to execute within a subshell, it's recommended to
    usechild_process.execFile and pass in the arguments array.

Credit: Node Security Auditor

Adam Baldwin

Questions? Hit us up in #nodesecurity on freenode or email [email protected] and reference this issue.

The Node Security Project
nodesecurity.io
@nodesecurity

how do use esc/pos command print??

ex: ESC @

ESC @
Name Initialize printer
Code ASCII ESC @
Hex. 1B 40
Decimal 27 64
Function Clears data from the print buffer and sets the printer to its default settings.
Details ï DIP switch settings are not reload.
ï Data in the reception buffer is maintained.
ï Macro definition information is maintained.
ï NV bit image definition information is maintained.
ï User NV memory data is maintained.
ï When page mode is selected, this recovers to standard mode.
STAR The printer is initialized by this command under the following conditions.
ï Selection of an effective paper out detector for paper out signal output (ESC c 3n)
ï Select an effective paper out detector for printing stop (ESC c 4n)

buffer write \x1B\x40 ??

Error when using with node-webkit

If I hop into the node console, and just do a simple

var printer = require('printer');
printer.getPrinters();

I get the array of all the printers, but when I do the exact same thing inside of node-webkit I get this error:

screen shot 2015-01-06 at 10 48 22 am

I'm on OSX 10.9.5. Any ideas on what I should look into?

POSIX compile error: HTTP_STATUS_CONTINUE not declared

Hey there,

The latest commit (0b0b881) / 0.0.5 has introduced a bug where I am unable to compile on (ARM/Raspbian) Nodejs 0.12.0. Node-gyp reports that HTTP_STATUS_CONTINUE is not declared.

0.0.4 on NPM works fine.

Not an advanced Linux/Nodejs guy (yet) so apologies for any oversight on my part.

PS: great work. Your work saved me a lot of time and effort. Thank you for doing this!

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.