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:
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.
I'm currently merging around 1500 PDFs and tried to find the defect one, but I cannot catch errors produced by
this.end()inasBuffer().While errors get caught here:
The node process quits with an unhandled error here:
I'm pretty sure the reason for the uncaught error is this line:
pdfjs/lib/document.js
Line 636 in 3374d1f
It should probably be:
Interesting side fact:
PDFs throwing errors like
Invalid xref object at 54524orName must start with a leading slash, found: 0are 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: 0drives me crazy.