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() {