diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | include/qpdf/QPDFAcroFormDocumentHelper.hh | 7 | ||||
-rw-r--r-- | libqpdf/QPDFAcroFormDocumentHelper.cc | 20 | ||||
-rw-r--r-- | manual/qpdf-manual.xml | 10 |
4 files changed, 39 insertions, 1 deletions
@@ -1,5 +1,8 @@ 2021-02-18 Jay Berkenbilt <ejb@ql.org> + * Add QPDFAcroFormDocumentHelper::addFormField, which adds a new + form field, initializing the AcroForm dictionary if needed. + * Add QPDFPageObjectHelper::getMatrixForFormXObjectPlacement, which returns the transformation matrix required to map from a form field's coordinate system into a specific rectangle within diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index 2c22a5da..d417fc08 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -106,6 +106,13 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper bool hasAcroForm(); + // Add a form field, initializing the document's AcroForm + // dictionary if needed. Calling this method invalidates the + // cache, which makes it possible to add a field that is not yet + // associated with an annotation or page. + QPDF_DLL + void addFormField(QPDFFormFieldObjectHelper); + // Return a vector of all terminal fields in a document. Terminal // fields are fields that have no children that are also fields. // Terminal fields may still have children that are annotations. diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 0fcc81f6..9f800a8e 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -32,6 +32,26 @@ QPDFAcroFormDocumentHelper::hasAcroForm() return this->qpdf.getRoot().hasKey("/AcroForm"); } +void +QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff) +{ + invalidateCache(); + auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); + if (! acroform.isDictionary()) + { + acroform = this->qpdf.makeIndirectObject( + QPDFObjectHandle::newDictionary()); + this->qpdf.getRoot().replaceKey("/AcroForm", acroform); + } + auto fields = acroform.getKey("/Fields"); + if (! fields.isArray()) + { + fields = QPDFObjectHandle::newArray(); + acroform.replaceKey("/Fields", fields); + } + fields.appendItem(ff.getObjectHandle()); +} + std::vector<QPDFFormFieldObjectHelper> QPDFAcroFormDocumentHelper::getFormFields() { diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 83d178a7..dd03f8d8 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -5286,7 +5286,7 @@ print "\n"; <listitem> <para> Add - <function>QPDFPageObjectHelper::getMatrixForFormXObjectPlacement</function> + <function>QPDFPageObjectHelper::getMatrixForFormXObjectPlacement</function>, which returns the transformation matrix required to map from a form field's coordinate system into a specific rectangle within the page. @@ -5294,6 +5294,14 @@ print "\n"; </listitem> <listitem> <para> + Add method + <function>QPDFAcroFormDocumentHelper::addFormField</function>, + which adds a new form field, initializing the AcroForm + dictionary if needed. + </para> + </listitem> + <listitem> + <para> Add <function>QUtil::path_basename</function> to return the last element of a path. </para> |