Skip to content

Signature Image Not Displayed in ng2-pdf-viewer #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SeriousSeal opened this issue Jan 31, 2025 · 1 comment
Open

Signature Image Not Displayed in ng2-pdf-viewer #1174

SeriousSeal opened this issue Jan 31, 2025 · 1 comment
Labels

Comments

@SeriousSeal
Copy link

SeriousSeal commented Jan 31, 2025

Versions
Angular: 15.1.3
ng2-pdf-viewer: 9.1.0

Context
We are adding signatures to our PDFs by embedding a signed image into a text field using pdf-lib.

Problem Description
Although we successfully set the image in the text field, ng2-pdf-viewer does not display it. However, when we retrieve the PDF data using:

this.pdfViewer.pdfViewer.pdfDocument.getData()

and download it as a blob, the signature image appears correctly when opened in an external viewer.
code to signthe pdf:

  async signPdf(signUrl: string, pdfDoc: PDFDocument): Promise<Uint8Array> {
    const signImageBytes = await fetch(signUrl).then(res => res.arrayBuffer());
    const form = pdfDoc.getForm();
    const signImage = await pdfDoc.embedPng(signImageBytes);
    const fields = form.getFields();
    fields
      .filter(field => field.getName().startsWith('signature'))
      .forEach(field => {
        const signField = form.getTextField(field.getName());
        signField.setImage(signImage);
      }
      );
    return await pdfDoc.save();
  }

<-- this returns a Promise of Uint8Array

gets called like this:
this.reportDataUInt8 = await this.careSignService.signPdf(event.dataUrl, this.pdfDoc);

the correct file gets created like this:

   const data = await this.pdfViewer.pdfViewer.pdfDocument.getData();
    return { attachment: this.model, content: new Blob([data], { type: 'application/pdf' }) } as DocumentAttachmentWithContent;

Are we doing something wrong or is this a bug of ng2-pdf-viewer?

Copy link

stale bot commented Apr 26, 2025

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

@stale stale bot added the stale label Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant