Sha256: eb77eaee45299e1e302d24cf79f8b7632f72f0e0d55b552f8a0e366fd10ea24d

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

#!/usr/bin/env node

var stdin = process.stdin,
    stdout = process.stdout,
    inputChunks = [];

stdin.resume();
stdin.setEncoding('utf8');

stdin.on('data', function (chunk) {
    inputChunks.push(chunk);
});

stdin.on('end', function () {
    var options = JSON.parse(inputChunks.join());
    var pdf_options = options['pdf_options'];
    var current_path = options['current_path'];
    var viewport_options = options['viewport_options'];
    var media_type = options['emulate_media'];
    var launch_options = options['launch_options'];
    var wait_for_timeout = options['wait_for_timeout'];

    module.paths.push(current_path + '/node_modules');

    const puppeteer = require('puppeteer');
    const fs = require('fs');
    var html = fs.readFileSync(process.argv[2], 'utf8');

    (async() => {
        const browser = await puppeteer.launch(launch_options);
        const page = await browser.newPage();

        await page.setContent(html);

        if (typeof media_type !== 'undefined' && media_type) {
            await page.emulateMedia(media_type);
        }

        if (typeof viewport_options !== 'undefined' && viewport_options) {
            await page.setViewport(viewport_options);
        }

        if (typeof wait_for_timeout !== 'undefined' && wait_for_timeout) {
            await page.waitFor(wait_for_timeout);
        }

        const pdf_output = await page.pdf(pdf_options);
        stdout.write(pdf_output);
        await browser.close();
    })();
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pdfgen-0.3.1 lib/javascript_bin/make_pdf.js
pdfgen-0.3.0 lib/javascript_bin/make_pdf.js