-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
I want to render a multi-page PDF into a PNG image concurrently, but the output image is always the content of the same page PDF, which does not meet expectations.
Environment: nodejs, pdf files take your demo/node/sample.pdf as an example
Mock code:
import { PDFiumLibrary } from '@hyzyla/pdfium/dist/index.cjs';
let library, document;
try {
library = await PDFiumLibrary.init();
document = await library.loadDocument(buffer);
await Promise.all(
Array.from(document.pages()).map(async page => {
const image = await page.render({
scale,
render,
});
if (image?.data) {
require('fs').writeFileSync(`./test_${page.number}.png`, Buffer.from(image.data));
}
})
);
} catch (error) {
} finally {
document?.destroy();
library?.destroy();
}
function render(options: PDFiumPageRenderOptions) {
return sharp(options.data, {
raw: {
width: options.width,
height: options.height,
channels: 4,
},
})
.png({
effort: 1,
compressionLevel: 9,
})
.toBuffer();
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels