From 81510829f126c6c050b414f9992b9c8cb24dc832 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 30 Aug 2025 12:10:35 +0100 Subject: [PATCH] Enhance `QPDFAcroFormDocumentHelper` with `get()` for shared access and `validate()` for re-validation and repair of AcroForm structure. --- include/qpdf/QPDFAcroFormDocumentHelper.hh | 15 +++++++++++++++ libqpdf/QPDFAcroFormDocumentHelper.cc | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index db75226..6094ed7 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -68,6 +68,21 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper { public: + // Get a shared document helper for a given QPDF object. + // + // Retrieving a document helper for a QPDF object rather than creating a new one avoids repeated + // validation of the Acroform structure, which can be expensive. + QPDF_DLL + static QPDFAcroFormDocumentHelper& get(QPDF& qpdf); + + // Re-validate the AcroForm structure. This is useful if you have modified the structure of the + // AcroForm dictionary in a way that would invalidate the cache. + // + // If repair is true, the document will be repaired if possible if the validation encounters + // errors. + QPDF_DLL + void validate(bool repair = true); + QPDF_DLL QPDFAcroFormDocumentHelper(QPDF&); diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 9ed850b..6974133 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,19 @@ QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : analyze(); } +QPDFAcroFormDocumentHelper& +QPDFAcroFormDocumentHelper::get(QPDF& qpdf) +{ + return qpdf.acroform(); +} + +void +QPDFAcroFormDocumentHelper::validate(bool repair) +{ + invalidateCache(); + analyze(); +} + void QPDFAcroFormDocumentHelper::invalidateCache() { -- libgit2 0.21.4