forked from tojocky/node-printer
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathprintPDFFileInBuffer.js
37 lines (31 loc) · 1.02 KB
/
printPDFFileInBuffer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Windows does not support PDF formats, but you can use imagemagick-native to achieve conversion from PDF to EMF.
var printer = require("../lib"),
fs = require('fs'),
path = require('path'),
filename = process.argv[2],
printername = process.argv[3];
if(process.platform == 'win32') {
throw 'Not yet supported for win32'
}
if(!filename || filename == '-h') {
throw 'PDF file name is missing. Please use the following params: <filename> [printername]'
}
filename = path.resolve(process.cwd(), filename);
console.log('printing file name ' + filename);
fs.readFile(filename, function(err, data){
if(err) {
console.error('err:' + err);
return;
}
console.log('data type is: '+typeof(data) + ', is buffer: ' + Buffer.isBuffer(data));
printer.printDirect({
data: data,
type: 'PDF',
success: function(id) {
console.log('printed with id ' + id);
},
error: function(err) {
console.error('error on printing: ' + err);
}
})
});