mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
27 lines
695 B
TypeScript
27 lines
695 B
TypeScript
import type { PDFDocument } from 'pdf-lib';
|
|
import { PDFSignature, rectangle } from 'pdf-lib';
|
|
|
|
export const normalizeSignatureAppearances = (document: PDFDocument) => {
|
|
const form = document.getForm();
|
|
|
|
for (const field of form.getFields()) {
|
|
if (field instanceof PDFSignature) {
|
|
field.acroField.getWidgets().forEach((widget) => {
|
|
widget.ensureAP();
|
|
|
|
try {
|
|
widget.getNormalAppearance();
|
|
} catch {
|
|
const { context } = widget.dict;
|
|
|
|
const xobj = context.formXObject([rectangle(0, 0, 0, 0)]);
|
|
|
|
const streamRef = context.register(xobj);
|
|
|
|
widget.setNormalAppearance(streamRef);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|