Open CristiCh opened 7 months ago
I also came across this problem, did you find any solution?
I'm having the same issue with PDF version 1.7 exported from sql reporting services.
Seems that the issue comes from how the trailer information is interpreted
1.4 from the contributing.pdf example :
trailer
<</Size 25
/Root 12 0 R
/Info 1 0 R>>
startxref
72203
%%EOF
1.7 example from my pdf
<< /Type /XRef
/Index [0 50]
/W [1 4 3]
/Filter /FlateDecode /Size 50 /Length 195 /Root 47 0 R /Info 48 0 R >>
stream
X c`
endstream
endobj
startxref
444002
%%EOF
SignPdfError: Expected xref at NaN but found other content. at getXref (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\readRefTable.js:26:13) at getFullXref (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\readRefTable.js:75:25) at getFullXrefTable (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\readRefTable.js:90:10) at readRefTable (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\readRefTable.js:106:25) at readPdf (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\readPdf.js:56:46) at plainAddPlaceholder (C:\Users\ionel\Desktop\code\reges\reges-process\node_modules\@signpdf\placeholder-plain\dist\plainAddPlaceholder.js:70:37) at work (C:\Users\ionel\Desktop\code\reges\reges-process\scripts\test.js:32:28) {
My typescript code:
async signPdf(pdfBuffer: Buffer, pdfId: string): Promise<Buffer> {
// Step 3: Add a signature placeholder using pdfkitAddPlaceholder
try {
const normalized = await this.addXrefTable(pdfBuffer);
console.log(normalized.lastIndexOf('startxref'));
const pdfWithPlaceholder = plainAddPlaceholder({
pdfBuffer: normalized,
reason: 'Document digitally signed',
location: 'Location',
contactInfo: 'contact@example.com',
name: 'Signature',
widgetRect: [100, 100, 300, 200], // Adjust coordinates as needed
// signatureLength: 8192,
});
// Step 4: Generate signature hash from the external signing service
const signatureHash = await this.generateSignature(pdfBuffer, pdfId);
const signPdf = new SignPdf();
const signedPdf = signPdf.sign(pdfWithPlaceholder, signatureHash);
return signedPdf;
} catch (error) {
console.error('Error adding signature placeholder:', error);
console.error(error);
}
}
I am using pdf-lib in a node JS project and I get the same error when trying to modify the pdf. Does anyone know why this is happening? Thanks!
The error is:
Expected xref at NaN but found other content
Thanks!