Skip to content

Commit

Permalink
do not overwrite page annotations when there already were some
Browse files Browse the repository at this point in the history
refs #198
  • Loading branch information
vbuch committed Nov 14, 2023
1 parent 0f0fb63 commit 78c1b3d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/placeholder-pdf-lib/src/pdflibAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const pdflibAddPlaceholder = ({
subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED,
widgetRect = [0, 0, 0, 0],
}) => {
const pages = pdfDoc.getPages();
const page = pdfDoc.getPage(0);

// Create a placeholder where the the last 3 parameters of the
// actual range will be replaced when signing is done.
Expand Down Expand Up @@ -85,15 +85,17 @@ export const pdflibAddPlaceholder = ({
V: signatureDictRef,
T: PDFString.of('Signature1'),
F: ANNOTATION_FLAGS.PRINT,
P: pages[0].ref,
P: page.ref,
}, pdfDoc.index);
const widgetDictRef = pdfDoc.context.register(widgetDict);

// Annotate the widget on the first page
pages[0].node.set(
PDFName.of('Annots'),
pdfDoc.context.obj([widgetDictRef]),
);
let annotations = page.node.lookupMaybe(PDFName.of('Annots'), PDFArray);
if (typeof annotations === 'undefined') {
annotations = pdfDoc.context.obj([]);
}
annotations.push(widgetDictRef);
page.node.set(PDFName.of('Annots'), annotations);

// Add an AcroForm or update the existing one
let acroForm = pdfDoc.catalog.lookupMaybe(PDFName.of('AcroForm'), PDFDict);
Expand Down

0 comments on commit 78c1b3d

Please sign in to comment.