-
-
Save KGZM/74fe7b751392c144d9dc to your computer and use it in GitHub Desktop.
This file contains 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
var PDFDocument = require('pdfkit'); | |
var fs=require('fs'); | |
var process = require('process') | |
var captureText = function(cb) { | |
var text = "" | |
process.stdin.on('readable', () => { | |
chunk = process.stdin.read(); | |
if(chunk) text = text + chunk; | |
}); | |
process.stdin.on('end', () => { | |
cb(text); | |
}); | |
} | |
var makepdf = function (text) { | |
doc = new PDFDocument({compress:false, sizes:[526,525],autoFirstPage: false}); | |
doc.pipe(fs.createWriteStream('out.pdf')); | |
doc.addPage({margin:0}); | |
doc.image('logo3.png'); | |
doc.moveDown(); | |
doc.text("TOGO ORDER", { | |
paragraphGap: 0, | |
indent: 0, | |
align: 'center', | |
columns: 1, | |
width: 135 | |
}); | |
doc.moveDown(); | |
var lines = text.split('\n'); | |
lines.forEach(str => { | |
doc.text(str, { | |
paragraphGap: 0, | |
indent: 0, | |
align: 'center', | |
columns: 1, | |
width: 135 | |
}); | |
doc.moveDown(); | |
console.log(str); | |
}); | |
doc.text("DONE", { | |
paragraphGap: 0, | |
indent: 0, | |
align: 'center', | |
columns: 1, | |
width: 135 | |
}); | |
doc.end(); | |
} | |
captureText(makepdf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment