我正在使用Jimp、 puppeteer -full-page-screenshot和 puppeteer 生成整页屏幕截图,但是我从 Jimp 和 puppeteer-full-page-screenshot 获得的 BUFFER 数据在我的情况下不起作用(我得到的缓冲区数据来自 puppeteer 即png2我的代码工作正常,但png 正在生成错误。)
const browser = await puppeteer.launch({ headless: true, timeout: 100000,
ignoreHTTPSErrors: true, args: ['--no-sandbox', '--disable-setuid-sandbox']});
const page = await browser.newPage();
await page.setViewport({ width: 1780, height: 2180 });
await page.goto(current.url, { waitUntil: 'networkidle2' });
await page.waitFor(7000);
const png = await fullPageScreenshot(page);
console.log(png);
req.current.image = image.bitmap.data;
// const png2 = await page.screenshot({ fullpage: true });
// console.log(png2);
// req.current.image = png2;
为了生成 pdf 我有以下
doc.image(req.current.image, {
fit: [595.28, 841.89],
align: 'center',
valign: 'center'
})
.fillColor('blue')
.text('Date Created: ' + dt, 100, 30)
.underline(100, 22, 300, 27, { color: '#0000FF' });
doc.addPage();
}
png的控制台.log
Jimp {
_background: 0,
bitmap:
{ data:
<Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ...
63816510 more bytes>,
width: 1780,
height: 8963 } }
png2的Console.log
<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 06 f4 00 00 08 84 08 06 00 00 00 7c 57 82 1b 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... 1457642 more bytes>
如果我使用png2它工作正常,但使用png我会收到以下错误:-
Error handler: Error: Unknown image format.
at Function.open(/media/root/EC783AF8783AC15E/node_modules/pdfkit/js/pdfkit.js:3820:13)
at PDFDocument.openImage
(/media/root/EC783AF8783AC15E/node_modules/pdfkit/js/pdfkit.js:3936:24)
at PDFDocument.image
(/media/root/EC783AF8783AC15E/node_modules/pdfkit/js/pdfkit.js:3852:22)