fix: rewrite form flattening handler
Previously we used the form flattening method from PDF-Lib but unfortunately when it encountered orphaned form items or other PDF oddities it would throw an error. Because of this certain documents would fail to seal and be stuck in a pending state with no recourse available. This change rewrites the form flattening handler to be more lenient when coming across the unknown opting to skip items it can't handle rather than abort.
This commit is contained in:
@@ -17,6 +17,7 @@ import { getFile } from '../../universal/upload/get-file';
|
||||
import { putPdfFile } from '../../universal/upload/put-file';
|
||||
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
|
||||
import { flattenAnnotations } from '../pdf/flatten-annotations';
|
||||
import { flattenForm } from '../pdf/flatten-form';
|
||||
import { insertFieldInPDF } from '../pdf/insert-field-in-pdf';
|
||||
import { normalizeSignatureAppearances } from '../pdf/normalize-signature-appearances';
|
||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||
@@ -101,8 +102,11 @@ export const sealDocument = async ({
|
||||
|
||||
// Normalize and flatten layers that could cause issues with the signature
|
||||
normalizeSignatureAppearances(doc);
|
||||
doc.getForm().flatten();
|
||||
console.log('normalized');
|
||||
flattenForm(doc);
|
||||
console.log('flattened');
|
||||
flattenAnnotations(doc);
|
||||
console.log('annotations');
|
||||
|
||||
if (certificate) {
|
||||
const certificatePages = await doc.copyPages(certificate, certificate.getPageIndices());
|
||||
|
||||
Reference in New Issue
Block a user