vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
700 stars 175 forks source link

Blank pdf after signing #56

Closed zhd4n closed 4 years ago

zhd4n commented 4 years ago

I investigated this bug and found that after signing the PDF file will be empty if it contained any link to website. Also, if the link href contain # instead of address (like http://google.com) everything will be fine.

 try {
            output = plainAddPlaceholder({
                pdfBuffer: fs.readFileSync(filename),
                reason: reason || 'my signature',
                signatureLength: 8192
            });
        } catch (e) {
            console.log('Error during adding placeholder');
            console.log(e.message);
            return response
                .status(500)
                .send({
                    message: 'Error during adding placeholder',
                    fn: plainAddPlaceholder ? plainAddPlaceholder.toString() : '-',
                    error: e.message,
                    trace: JSON.stringify(e.trace)
                });
        }
        try {
            const signedPdf = signer.sign(output, fs.readFileSync(cert));
            fs.writeFileSync(__dirname + '/last.pdf', signedPdf);
            fs.writeFileSync(filename, signedPdf);
            const {signature, signedData} = extractSignature(signedPdf);
            console.log(`Successfully signed ${filename}`);
            return response
                .send({ message: 'ok' });
        } catch (e) {
            console.log('Error during singing PDF');
            console.log(e.message);
            return response
                .status(500)
                .send({
                    message: 'Error during singing PDF',
                    error: e.message,
                    trace: JSON.stringify(e.trace)
                });
        }
vbuch commented 4 years ago

Is it blank after signing or after adding a placeholder? Can you add an example PDF here? @z-h-z-h

zhd4n commented 4 years ago

test.pdf @vbuch

vbuch commented 4 years ago

Confirmed. Just checked it. plainAddPlaceholder messes it up. Haven't found the reason yet.

Update: image This is the obvious reason. The /Annots list is broken.

Update 2: This is a lesson for me. I didn't insist on having a function tested when it was altered. Now this same function is producing a bug. It's about createBufferPageWithAnnotation.

vbuch commented 4 years ago

@z-h-z-h I have created a working version of the buggy function but need to cover it with tests so can't merge yet.

vbuch commented 4 years ago

57 is now in 1.2.2. Please confirm if the issue is resolved.

AuspeXeu commented 4 years ago

I am on 1.2.2 and have the same issue. Signing my PDF spits out only blank pages.

vbuch commented 4 years ago

Can you, @AuspeXeu, attach a source PDF and any intermediates you may. This would assist in finding the issue.

AuspeXeu commented 4 years ago

The content of my PDFs is sensitive, cannot disclose. Sorry :/

vemundeldegard commented 4 years ago

Having the same issue. The first page is blank, the second one is not.

vbuch commented 4 years ago

@vemundeldegard can you attach an example PDF? Also if you could try what's in #59 ... @AuspeXeu you as well.

vbuch commented 4 years ago

1.2.3 is out in npm. Hope it fixes this issue.

AuspeXeu commented 4 years ago

Happy to confirm that this is resolved for me with the latest version :)

erickximenes commented 4 years ago

Could you share the code used in the question?

parceadl commented 2 years ago

@AuspeXeu Hi, what version works for you? our first page is blank only in acrobat but we are in 1.5.0. thanks

AuspeXeu commented 2 years ago

I am on the latest version and that's working fine for me.