Skip to content

Instantly share code, notes, and snippets.

@KGZM
Forked from anonymous/print.js
Last active December 5, 2015 03:06
Show Gist options
  • Save KGZM/74fe7b751392c144d9dc to your computer and use it in GitHub Desktop.
Save KGZM/74fe7b751392c144d9dc to your computer and use it in GitHub Desktop.
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