From 3d33a3a1e3eed4e09a625f81aaa8fcdc67d642e9 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 23 Dec 2023 08:30:37 -0500 Subject: [PATCH] Add QPDFAcroFormDocumentHelper::disableDigitalSignatures --- include/qpdf/QPDFAcroFormDocumentHelper.hh | 5 +++++ libqpdf/QPDFAcroFormDocumentHelper.cc | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index 8be4d06..f9ad009 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -163,6 +163,11 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper QPDF_DLL void generateAppearancesIfNeeded(); + // Disable Digital Signature Fields. Remove all digital signature fields from the document, + // leaving any annotation showing the content of the field intact. + QPDF_DLL + void disableDigitalSignatures(); + // Note: this method works on all annotations, not just ones with associated fields. For each // annotation in old_annots, apply the given transformation matrix to create a new annotation. // New annotations are appended to new_annots. If the annotation is associated with a form diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index f2daa0c..5fdd20b 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -416,6 +416,28 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() } void +QPDFAcroFormDocumentHelper::disableDigitalSignatures() +{ + std::set to_remove; + auto fields = getFormFields(); + for (auto& f: fields) { + auto ft = f.getFieldType(); + if (ft == "/Sig") { + auto oh = f.getObjectHandle(); + to_remove.insert(oh.getObjGen()); + // Make this no longer a form field. If it's also an annotation, the annotation will + // survive. If it's only a field and is no longer referenced, it will disappear. + oh.removeKey("/FT"); + // Remove fields that are specific to signature fields. + oh.removeKey("/V"); + oh.removeKey("/SV"); + oh.removeKey("/Lock"); + } + } + removeFormFields(to_remove); +} + +void QPDFAcroFormDocumentHelper::adjustInheritedFields( QPDFObjectHandle obj, bool override_da, -- libgit2 0.21.4