Created
August 13, 2020 04:31
-
-
Save Alan-Liang/e529d14b2b8c9f6bdacd158d1967d0b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const readline = require('readline') | |
const printer = require('node-native-printer') | |
const [ ,, filePath, pageCount, printerName ] = process.argv | |
if (!filePath || !pageCount) process.exit(-1) | |
const print = function (options) { | |
const res = printer.print(filePath, options, printerName || 'HP_LaserJet_Professional_M1136_MFP') | |
if (!res) throw 'No result from CUPS' | |
return res | |
} | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}) | |
;(async () => { | |
const allPages = [ ...Array(parseInt(pageCount)).keys() ].map(p => p + 1) | |
const pageRanges = [allPages.filter(n => n % 2 === 0), allPages.filter(n => n % 2 === 1)].map(r => r.join(',')) | |
print({ | |
'page-ranges': pageRanges[0], | |
outputorder: 'reverse', | |
'fit-to-page': true, | |
}) | |
await new Promise(r => rl.question('second side', r)) | |
print({ | |
'page-ranges': pageRanges[1], | |
'orientation-requested': 6, | |
'fit-to-page': true, | |
}) | |
await new Promise(r => rl.question('done', r)) | |
process.exit(0) | |
})().catch(e => { | |
console.error(e) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment