node-signpdf icon indicating copy to clipboard operation
node-signpdf copied to clipboard

Error occured when sign after Adobe Acrobat

Open totalism53 opened this issue 3 years ago • 3 comments

Describe the bug and the expected behaviour I tried to sign the document after the document signed on Adobe Acrobat but I found that after using node-signpdf there is an error which is "SignPdfError: Expected xref at NaN but found other content." but if I use this lib as the starter, it can be sign twice or more without any error.

Is it a bug in signing or in the helpers? I guess it might be in signing.

To Reproduce Here is the code and file that I used.

import { SignPdf } from 'node-signpdf'; import fs from 'fs'; import { Buffer } from 'buffer'; import { plainAddPlaceholder } from 'node-signpdf/dist/helpers/index.js';

const pathSignedPdf = 'resource/pdf_a_signed_signed.pdf' const p12Buffer = fs.readFileSync('resource/certificate.p12'); const pdfBuffer = fs.readFileSync('resource/pdf_a_signed.pdf'); const pdfBufferToSign = plainAddPlaceholder({ pdfBuffer, reason: 'twice', signatureLength: p12Buffer.length }); const signer = new SignPdf() const signedPdf = signer.sign(pdfBufferToSign, p12Buffer); console.log(signedPdf)

const bufferPdf = Buffer.from(signedPdf) fs.createWriteStream(pathSignedPdf).write(bufferPdf);

Here is the log from console.log(prefix.toString().replace(/\s*/g, '')) in readRefTable.js

%PDF-1.7%����1210obj<</Linearized1/L217009/O123/E207511/N1/T216681/H[546239]>>endobj1490obj<</DecodeParms<</Columns5/Predictor12>>/Filter/FlateDecode/ID[<9AFE1C437623C840A385A0AECE1DFA20><DFD110A453DB48F8B75604844F9FE5F1>]/Index[12158]/Info1200R/Length124/Prev216682/Root1220R/Size179/Type/XRef/W[131]>>streamh�bbd```b``f���LN�A$C�d�"o��\O��6�Is0��,&σI�Ȭf��H�P��g��.���`O�"�>�T�E�����t-/�=��������)@����endstreamendobjstart

Is there any suggestion or example?

Thank you for your help.

the original file signed by acrobat signed twice with node-signpdf

totalism53 avatar Aug 29 '22 08:08 totalism53

@totalism53 I'm getting this same issue. But only for one document. Other documents work fine

bretto36 avatar Sep 27 '22 21:09 bretto36

Some features of PDF > 1.3 such as streams and linearization are not supported. Your signed document uses those.

https://github.com/vbuch/node-signpdf/issues?q=+label%3A%22PDF+%3E+1.3%22

vbuch avatar Sep 28 '22 08:09 vbuch

@vbuch Yes this is a PDF version 1.4 document. The code i've written the PDF is generated by using a chrome headless print to pdf, so i have only THIS document not working, but all the other 1000+ documents have worked.

I'm quite confused as to why it's only the one document.

trailer
<</Size 206
/Root 29 0 R
/Info 1 0 R>>
startxref
137505
%%EOF

I don;t know what else to try to debug it. i'm on 1.5.0

It just can't seem to determine the position to add the signature when calling plainAddPlaceholder

bretto36 avatar Sep 29 '22 20:09 bretto36

This issue has been automatically marked as stale because it has not had activity in the past 90 days. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 31 '22 23:12 stale[bot]

Just for other people's awareness. I was using version 1.3.3. I had the word "trailer" in the content i was adding. And it caused the error. What a mission to figure that out.

bretto36 avatar Aug 28 '23 23:08 bretto36