2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Add QPDFAcroFormDocumentHelper::disableDigitalSignatures

This commit is contained in:
Jay Berkenbilt 2023-12-23 08:30:37 -05:00
parent 2c14be264b
commit 3d33a3a1e3
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -415,6 +415,28 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
setNeedAppearances(false);
}
void
QPDFAcroFormDocumentHelper::disableDigitalSignatures()
{
std::set<QPDFObjGen> 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,