Skip to content

Commit

Permalink
Return false for PDFSignature.needsAppearancesUpdate (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopding authored Oct 9, 2020
1 parent 193e48f commit b1891d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Binary file added assets/pdfs/with_signature.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions src/api/form/PDFSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export default class PDFSignature extends PDFField {

this.acroField = acroSignature;
}

needsAppearancesUpdate() {
return false;
}
}
16 changes: 16 additions & 0 deletions tests/api/form/PDFForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const fancyFieldsPdfBytes = fs.readFileSync('assets/pdfs/fancy_fields.pdf');
// const combedPdfBytes = fs.readFileSync('assets/pdfs/with_combed_fields.pdf');
// const dodPdfBytes = fs.readFileSync('assets/pdfs/dod_character.pdf');
const xfaPdfBytes = fs.readFileSync('assets/pdfs/with_xfa_fields.pdf');
const signaturePdfBytes = fs.readFileSync('assets/pdfs/with_signature.pdf');

describe(`PDFForm`, () => {
const origConsoleWarn = console.warn;
Expand Down Expand Up @@ -275,6 +276,21 @@ describe(`PDFForm`, () => {
expect(aps()).toBe(20);
});

it.only(`does not throw errors for PDFSignature fields`, async () => {
const pdfDoc = await PDFDocument.load(signaturePdfBytes);

const widgets = getWidgets(pdfDoc);
expect(widgets.length).toBe(1);

const form = pdfDoc.getForm();

expect(() => form.updateFieldAppearances()).not.toThrow();

expect(
pdfDoc.save({ updateFieldAppearances: true }),
).resolves.toBeInstanceOf(Uint8Array);
});

// TODO: Add method to remove APs and use `NeedsAppearances`? How would this
// work with RadioGroups? Just set the APs to `null`but keep the keys?
});

0 comments on commit b1891d4

Please sign in to comment.