Commit 3d33a3a1e3eed4e09a625f81aaa8fcdc67d642e9
1 parent
2c14be26
Add QPDFAcroFormDocumentHelper::disableDigitalSignatures
Showing
2 changed files
with
27 additions
and
0 deletions
include/qpdf/QPDFAcroFormDocumentHelper.hh
| ... | ... | @@ -163,6 +163,11 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper |
| 163 | 163 | QPDF_DLL |
| 164 | 164 | void generateAppearancesIfNeeded(); |
| 165 | 165 | |
| 166 | + // Disable Digital Signature Fields. Remove all digital signature fields from the document, | |
| 167 | + // leaving any annotation showing the content of the field intact. | |
| 168 | + QPDF_DLL | |
| 169 | + void disableDigitalSignatures(); | |
| 170 | + | |
| 166 | 171 | // Note: this method works on all annotations, not just ones with associated fields. For each |
| 167 | 172 | // annotation in old_annots, apply the given transformation matrix to create a new annotation. |
| 168 | 173 | // New annotations are appended to new_annots. If the annotation is associated with a form | ... | ... |
libqpdf/QPDFAcroFormDocumentHelper.cc
| ... | ... | @@ -416,6 +416,28 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | void |
| 419 | +QPDFAcroFormDocumentHelper::disableDigitalSignatures() | |
| 420 | +{ | |
| 421 | + std::set<QPDFObjGen> to_remove; | |
| 422 | + auto fields = getFormFields(); | |
| 423 | + for (auto& f: fields) { | |
| 424 | + auto ft = f.getFieldType(); | |
| 425 | + if (ft == "/Sig") { | |
| 426 | + auto oh = f.getObjectHandle(); | |
| 427 | + to_remove.insert(oh.getObjGen()); | |
| 428 | + // Make this no longer a form field. If it's also an annotation, the annotation will | |
| 429 | + // survive. If it's only a field and is no longer referenced, it will disappear. | |
| 430 | + oh.removeKey("/FT"); | |
| 431 | + // Remove fields that are specific to signature fields. | |
| 432 | + oh.removeKey("/V"); | |
| 433 | + oh.removeKey("/SV"); | |
| 434 | + oh.removeKey("/Lock"); | |
| 435 | + } | |
| 436 | + } | |
| 437 | + removeFormFields(to_remove); | |
| 438 | +} | |
| 439 | + | |
| 440 | +void | |
| 419 | 441 | QPDFAcroFormDocumentHelper::adjustInheritedFields( |
| 420 | 442 | QPDFObjectHandle obj, |
| 421 | 443 | bool override_da, | ... | ... |