aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-18 17:18:24 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-18 18:25:48 +0100
commitde8929a41ce093a0c21ca48b2342a73cf67a51f0 (patch)
tree929a3aa71f51d032e8ad898ab71440c81a0f3bf5
parent5cec6b4c3df09b59464c9a492b60b86ffd0d5311 (diff)
downloadqpdf-de8929a41ce093a0c21ca48b2342a73cf67a51f0.tar.zst
Add QPDFAcroFormDocumentHelper::addFormField
-rw-r--r--ChangeLog3
-rw-r--r--include/qpdf/QPDFAcroFormDocumentHelper.hh7
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc20
-rw-r--r--manual/qpdf-manual.xml10
4 files changed, 39 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 76340fb1..baf568c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>