{"size": 1433, "ext": "js", "max_stars_repo_path": "lib/js/pdfgenerator.js", "max_stars_repo_name": "boletia/Dhalang", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/js/pdfgenerator.js", "max_issues_repo_name": "boletia/Dhalang", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/js/pdfgenerator.js", "max_forks_repo_name": "boletia/Dhalang", "max_forks_repo_forks_event_min_datetime": "2019-08-06T07:33:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-06T07:33:00.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 29.2448979592, "max_line_length": 95, "alphanum_fraction": 0.5554780181}
'use strict';

const createPdf = async() => {
    module.paths.push(process.argv[4]);
    const puppeteer = require('puppeteer');
    const qr = require('qr-image');
    let browser;
    try {
        browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
        const page = await browser.newPage();
        await page.goto(process.argv[2], {timeout: 10000, waitUntil: 'networkidle2'});
        await page.waitFor(2500);
        let qrcodes = await generateQR(qr, process.argv[5]);
        await page.evaluate((qrcodes) => {
          let imgs_bars = document.querySelectorAll('.qrcode-img');
          for (i = 0; i < imgs_bars.length; i++) {
            imgs_bars[i].src = qrcodes[i];
          }
        },qrcodes);
        await page.pdf({
            path: process.argv[3],
            width: '1356px',
            height: '852px',
            printBackground: true
        });
    } catch (err) {
        console.log(err.message);
    } finally {
        if (browser) {
            browser.close();
        }
        process.exit();
    }
};
createPdf();

async function generateQR(qr, numbers) {
 let arrayQR = [];
 let ticketsNumber = numbers.split(',');
 for(let number of ticketsNumber) {
   try {
       let qr_svg = qr.imageSync(number,{ ec_level: 'L', type: 'svg' });
       arrayQR.push("data:image/svg+xml;charset=utf-8," + qr_svg);
     } catch (error) {
   }
 }
 return arrayQR;
}
