I have a beautiful page with a long html-table, and I want to download a zip file with that table converted in png. The table is very long, so I need to split it in multiple images.
For the moment I'm able to download a single png image from the page with the table, and I'm using Puppeteer. Is it possible to download multiple images from a webpage with Puppeteer?
This is the code that I use to download the png image.
import Router from 'express';
import PDF from 'pdf-image';
const PDFImage = PDF.PDFImage;
import puppeteer from 'puppeteer';
const router = Router();
router.get('/list', async (req, res) => {
const browser = await puppeteer.launch({
headless: true,
executablePath: process.env.CHROMIUM_PATH,
args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.goto('http://localhost/list');
await page.pdf({
path: 'list.pdf',
width: 1920,
height: 1080
});
await browser.close();
//convert pdf to png
try {
let img = new PDFImage("list.pdf");
img.convertPage(0).then(imgPath => {
res.sendFile(imgPath, {root: '.'});
})
} catch(err) {res.send(503);}
});
Thank you all!
question from:
https://stackoverflow.com/questions/65922064/how-to-use-puppeteer-to-download-a-zip-file-with-images 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…