#!/usr/bin/env node /** * Script to print a pdf from a html snippet, as input to stdin */ const htmlPdf = require('html-pdf-chrome'); const options = { port: 9222, // port Chrome is listening on printOptions: { printBackground: true, paperWidth: 8.267717, paperHeight: 11.69291, marginTop: .5, marginRight: .5, marginBottom: .5, marginLeft: .5 }, }; const print = (data, options) => { htmlPdf.create(data, options).then((pdf) => { const pdfStream = pdf.toStream(); pdfStream.pipe(process.stdout); }); } 'Read from stdin...' console.log("Reading data from stdin"); const stdin = process.stdin; // stdin.setEncoding('utf-8'); stdin.resume(); stdin.once('data', data => { console.log(data.toString()); print("" + data.toString().replace(/\n/g, '
') + "", options); });