generate pdfs from html 26 css with node js using puppeteer

Solutions on MaxInterview for generate pdfs from html 26 css with node js using puppeteer by the best coders in the world

showing results for - "generate pdfs from html 26 css with node js using puppeteer"
Mía
29 Sep 2019
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=wQEeFaqVQgw
4*/
5
6// Import dependencies
7const puppeteer = require("puppeteer");
8const fs = require("fs");
9
10(async () => {
11
12    // The location / URL
13    const url = "http://aqicn.org/city/beijing/";
14
15    // Create the browser
16    const browser = await puppeteer.launch({
17        headless: true
18    });
19
20    // Navigate to the website
21    const page = await browser.newPage();
22    await page.goto(url, { waitUntil: "load" });
23
24    // Modified colors
25    // await page.emulateMedia("screen");
26
27    // const pdfBuffer = await page.pdf();
28    // fs.writeFileSync("page.pdf", pdfBuffer);
29
30    // Generate the PDF
31    await page.pdf({ path: "page.pdf" });
32
33    // The width, height, and margin options accept values labeled with units. Unlabeled values are treated as pixels.
34
35    // width: "100px"
36    // px - pixel
37    // in - inch
38    // cm - centimeter
39    // mm - millimeter
40
41    // height: "100px"
42    // px - pixel
43    // in - inch
44    // cm - centimeter
45    // mm - millimeter
46
47    // format: "A0"
48    // Letter: 8.5in x 11in
49    // Legal: 8.5in x 14in
50    // Tabloid: 11in x 17in
51    // Ledger: 17in x 11in
52    // A0: 33.1in x 46.8in
53    // A1: 23.4in x 33.1in
54    // A2: 16.54in x 23.4in
55    // A3: 11.7in x 16.54in
56    // A4: 8.27in x 11.7in
57    // A5: 5.83in x 8.27in
58    // A6: 4.13in x 5.83in
59
60    // Close the browser
61    await browser.close();
62
63})();