vbuch / node-signpdf

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

First page of pdf is changed to potrait and generates blank page with no placeholder #125

Closed kiranbangar5946 closed 2 years ago

kiranbangar5946 commented 3 years ago

hi @vbuch thanks for building such a library firstly apart from these i need some suggestion as am not generating pdf using pdfkit so am using plainAddPlaceholder function which in turn creates digital signature but my first page of pdf is blank and is in potrait mode my placeholder isnt visible please help :(

vbuch commented 3 years ago

@kiranbangar5946 this is known issue but noone ever tackled it. See #108 Somone needs to read the specs and check where the info is lost.

kiranbangar5946 commented 3 years ago

@vbuch ok understood so i changed it to potrait as i too had same doubt and tried but placeholder is invisble and in adobe reader it shows Field:Signature1 is invisible.Is this not implemented ? and i see a tilt rectangle with watermark view copy.Your suggestions might lead me in right direction am struggling on it .Thank you sir!

vbuch commented 3 years ago

An e-signature doesn't need to be visible. We only have the implementation of invisible ones. See #26 and #39. They both refer to the same topic. This is where asignature is made invisible. plainAddPlaceholder uses pdfkitAddPlaceholder internally so it's the same code that creates the widget.

gleneslincaro commented 3 years ago

Hi. I am also having the same problem. I used to generate pdf using html-pdf library and sign the generated pdf with node-signpdf

const pdfBufferWithPlaceholder = plainAddPlaceholder({pdfBuffer, reason: 'reason'}); const signedPdfBuffer = Signer.sign(pdfBufferWithPlaceholder, p12Cert, {passphrase});

The file is successfully signed but the first page becomes blank when it is viewed in Adobe Acrobat.

When I use pdfkit to generate pdf instead of html-pdf, it works fine. It's not making the first page blank after signing. But I really need the generated pdf from html-pdf to work.

Thanks in advance

stale[bot] commented 3 years ago

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.

dotob commented 2 years ago

hi @vbuch we would be able to fund this issue if it would help you to resolve it. it would be really great.

cassiobt commented 2 years ago

I was using https://github.com/marcbachmann/node-html-pdf to generate the PDF. So I change tohttps://github.com/mrafiqk/html-pdf-node and now it works like a charm

vbuch commented 2 years ago

@kiranbangar5946 , @dotob , I would love to help here, but could you please provide a file that you have issues with? Of course, I'm interested in the version before trying to sign it.

dotob commented 2 years ago

hi @vbuch,

thanks for having a look at this.

here are the two files: original and signed

what we do in code:

let pdfBuffer = plainAddPlaceholder({
  pdfBuffer: await fs.readFile("original.pdf"),
  reason: 'reasons',
  signatureLength: 1612,
});

const signedPdf = signer.sign(pdfBuffer, await fs.readFile(PATH_TO_P12_CERTIFICATE), {
  passphrase: 'xxxxxxx',
});

regards sebastian

vbuch commented 2 years ago

OK. Looking at the original I see a couple of things:

  1. This is a PDF 1.7. Historically, we are not dealing well with streams (see here: https://github.com/vbuch/node-signpdf/issues?q=label%3A%22PDF+%3E+1.3%22)
  2. The second thing that I noticed is the form of the xref. I think that is where we are failing. There is a way to test this so I will give you an update.

Note: If you can save your document without the use of streams, you will probably succeed in signing it (just as a quick fix).

niklas-dahl commented 2 years ago

Hey, colleague of @dotob here, we are using https://github.com/Hopding/pdf-lib to edit an existing pdf.

When first trying to sign our pdf we ran into this issue https://github.com/vbuch/node-signpdf/issues/79. We solved it by using await pdfDoc.save({ useObjectStreams: false, });

So I think we already save the document without the use of streams. Thanks for taking a look.

vbuch commented 2 years ago

@niklas-dahl , the document shared by @dotob as original does contain streams. Also, there is a better way to place the signature placeholder than our plainAddPlaceholder if you are already using pdf-lib. See https://github.com/Hopding/pdf-lib/issues/112#issuecomment-569085380

stale[bot] commented 2 years ago

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.