Closed
Description
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?