Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

javascript - How to use Puppeteer to download a zip file with images?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...