this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 35 lines 1.1 kB view raw
1import puppeteer from 'puppeteer'; 2import { fileURLToPath } from 'url'; 3import { dirname, join } from 'path'; 4 5const __dirname = dirname(fileURLToPath(import.meta.url)); 6const htmlPath = join(__dirname, 'web-commons.html'); 7 8const browser = await puppeteer.launch(); 9 10// Full version 11const fullPage = await browser.newPage(); 12await fullPage.goto('file://' + htmlPath, { waitUntil: 'networkidle0' }); 13const fullPdf = join(__dirname, 'web-commons-full.pdf'); 14await fullPage.pdf({ 15 path: fullPdf, 16 format: 'A4', 17 printBackground: true, 18 margin: { top: 0, right: 0, bottom: 0, left: 0 }, 19}); 20console.log('PDF written to', fullPdf); 21 22// One-pager version (adds class to toggle visibility) 23const onePage = await browser.newPage(); 24await onePage.goto('file://' + htmlPath, { waitUntil: 'networkidle0' }); 25await onePage.evaluate(() => document.body.classList.add('one-pager')); 26const onePagerPdf = join(__dirname, 'web-commons-one-pager.pdf'); 27await onePage.pdf({ 28 path: onePagerPdf, 29 format: 'A4', 30 printBackground: true, 31 margin: { top: 0, right: 0, bottom: 0, left: 0 }, 32}); 33console.log('PDF written to', onePagerPdf); 34 35await browser.close();