'use strict';

const puppeteer = require('puppeteer');

const createPdf = async() => {
  let browser;
  try {
    browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
    const page = await browser.newPage();
    //await page.setViewport({width: 794, height: 1122, deviceScaleFactor: 1});
    await page.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
    await page.waitFor(300);
    await page.pdf({
      path: process.argv[3],
      format: 'A4',
      landscape: true,
      margin: { top: "0.8cm", right:  "0.8cm", bottom:  "0.7cm", left:  "0.8cm" },
      printBackground: true
    });
  } catch (err) {
      console.log(err.message);
  } finally {
    if (browser) {
      browser.close();
    }
    process.exit();
  }
};
createPdf();