25 lines
626 B
JavaScript
25 lines
626 B
JavaScript
const { exec } = require('child_process');
|
|
|
|
function printFile(filePath, printOption, pages, callback) {
|
|
let command = `lp ${filePath}`;
|
|
|
|
if (printOption === 'odd') {
|
|
command += ' -o page-set=odd';
|
|
} else if (printOption === 'even') {
|
|
command += ' -o page-set=even';
|
|
} else if (printOption === 'specific' && pages) {
|
|
command += ` -P ${pages}`;
|
|
}
|
|
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
callback(new Error(`Error printing file: ${stderr}`));
|
|
return;
|
|
}
|
|
callback(null);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
printFile
|
|
}; |