vbuch / node-signpdf

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

Signature not visible in adobe reader #107

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi everyone I'm using this library in an angular application to sign a pdf. The signature is not visible in adobe reader DC but it's visible in foxit reader. I tried adobe reader XI but it's not visible either. When I open the document in pdf xchange viewer I get this error: non critical errors detected in the xref table.

Any ideas what the issue could be?

Here is how I do it:

import { Component } from '@angular/core';
import { plainAddPlaceholder} from 'node_modules/node-signpdf/src/helpers';
import signer from 'node_modules/node-signpdf';

@Component({
  selector: 'sign-page',
  template:  '...',
  styles: []
})
export class SignPageComponent {
  file: File;
  p12: File;

  fileChange(event): void {
    this.file = event.target.files[0];
  }

  uploadP12(event): void {
    this.p12 = event.target.files[0];
  }

  sign(): void {
    const fileReader = new FileReader();
    fileReader.addEventListener('loadend', (evt) => {
      if (evt.target.readyState == FileReader.DONE) {
        let pdfBuffer = Buffer.from(fileReader.result);
        pdfBuffer = plainAddPlaceholder({
          pdfBuffer,
          reason: 'I have reviewed it.',
          signatureLength: 31280,
        });
        fileReader.addEventListener('loadend', (evt) => {
          if (evt.target.readyState == FileReader.DONE) {
            let signatureAsBuffer = Buffer.from(fileReader.result);
            const signedPdf = signer.sign(pdfBuffer, signatureAsBuffer);
          }
        });
        fileReader.readAsArrayBuffer(this.p12);
      }
    });
    fileReader.readAsArrayBuffer(this.file);
  }
}
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.