printserver/print.js

25 lines
626 B
JavaScript
Raw Permalink Normal View History

2025-02-16 23:19:52 +08:00
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
};