0.10.1 • Published 10 months ago
@pixdif/pdf-parser v0.10.1
Pixdif PDF Parser
A PDF parser for pixdif to read PDF files and render each page into an image (PNG format), inspired by pdf.js and node-canvas.
You can install it as a pixdif plugin, or just use it to convert PDF files into images so that any other frameworks can compare or consume them, such as Playwright, WebDriver.IO or Allure Report.
License
Installation
npm install @pixdif/pdf-parser
Example
import { finished } from 'stream/promises';
const parser = new PdfParser('test/sample/shape.pdf');
await parser.open();
const pageNum = await parser.getPageNum();
for (let i = 0; i < pageNum; i++) {
const page = await parser.getPage(0);
console.log(page.getTitle());
const output = fs.createWriteStream(`output/Page ${i + 1} - ${page.getTitle()}.png`);
const image = await page.render();
image.pipe(output);
await finished(output);
}
await parser.close();