-
Notifications
You must be signed in to change notification settings - Fork 143
Description
I'm currently merging around 1500 PDFs and tried to find the defect one, but I cannot catch errors produced by this.end()
in asBuffer()
.
While errors get caught here:
try {
doc.pipe(fs.createWriteStream(fullPdfPath));
await doc.end();
} catch (err) { console.error(err); }
The node process quits with an unhandled error here:
try {
const buf = await doc.asBuffer();
fs.writeFileSync(fullPdfPath, buf, { encoding: 'binary' });
} catch (err) { console.error(err); }
I'm pretty sure the reason for the uncaught error is this line:
Line 636 in 3374d1f
this.end() |
It should probably be:
if (shouldEnd) {
this.end().catch(reject)
}
Interesting side fact:
PDFs throwing errors like Invalid xref object at 54524
or Name must start with a leading slash, found: 0
are single-page PDFs previously extracted by pdfjs from other multi-page PDFs. Extracting worked, but merging again failed.
I could get rid of the Invalid xref object error by extracting with asBuffer() writeFileSync and encoding binary instead of pipe and stream but the one PDF with Name must start with a leading slash, found: 0
drives me crazy.