Commit de8929a41ce093a0c21ca48b2342a73cf67a51f0

Authored by Jay Berkenbilt
1 parent 5cec6b4c

Add QPDFAcroFormDocumentHelper::addFormField

ChangeLog
1 1 2021-02-18 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Add QPDFAcroFormDocumentHelper::addFormField, which adds a new
  4 + form field, initializing the AcroForm dictionary if needed.
  5 +
3 6 * Add QPDFPageObjectHelper::getMatrixForFormXObjectPlacement,
4 7 which returns the transformation matrix required to map from a
5 8 form field's coordinate system into a specific rectangle within
... ...
include/qpdf/QPDFAcroFormDocumentHelper.hh
... ... @@ -106,6 +106,13 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
106 106 bool
107 107 hasAcroForm();
108 108  
  109 + // Add a form field, initializing the document's AcroForm
  110 + // dictionary if needed. Calling this method invalidates the
  111 + // cache, which makes it possible to add a field that is not yet
  112 + // associated with an annotation or page.
  113 + QPDF_DLL
  114 + void addFormField(QPDFFormFieldObjectHelper);
  115 +
109 116 // Return a vector of all terminal fields in a document. Terminal
110 117 // fields are fields that have no children that are also fields.
111 118 // Terminal fields may still have children that are annotations.
... ...
libqpdf/QPDFAcroFormDocumentHelper.cc
... ... @@ -32,6 +32,26 @@ QPDFAcroFormDocumentHelper::hasAcroForm()
32 32 return this->qpdf.getRoot().hasKey("/AcroForm");
33 33 }
34 34  
  35 +void
  36 +QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff)
  37 +{
  38 + invalidateCache();
  39 + auto acroform = this->qpdf.getRoot().getKey("/AcroForm");
  40 + if (! acroform.isDictionary())
  41 + {
  42 + acroform = this->qpdf.makeIndirectObject(
  43 + QPDFObjectHandle::newDictionary());
  44 + this->qpdf.getRoot().replaceKey("/AcroForm", acroform);
  45 + }
  46 + auto fields = acroform.getKey("/Fields");
  47 + if (! fields.isArray())
  48 + {
  49 + fields = QPDFObjectHandle::newArray();
  50 + acroform.replaceKey("/Fields", fields);
  51 + }
  52 + fields.appendItem(ff.getObjectHandle());
  53 +}
  54 +
35 55 std::vector<QPDFFormFieldObjectHelper>
36 56 QPDFAcroFormDocumentHelper::getFormFields()
37 57 {
... ...
manual/qpdf-manual.xml
... ... @@ -5286,7 +5286,7 @@ print &quot;\n&quot;;
5286 5286 <listitem>
5287 5287 <para>
5288 5288 Add
5289   - <function>QPDFPageObjectHelper::getMatrixForFormXObjectPlacement</function>
  5289 + <function>QPDFPageObjectHelper::getMatrixForFormXObjectPlacement</function>,
5290 5290 which returns the transformation matrix required to map from
5291 5291 a form field's coordinate system into a specific rectangle
5292 5292 within the page.
... ... @@ -5294,6 +5294,14 @@ print &quot;\n&quot;;
5294 5294 </listitem>
5295 5295 <listitem>
5296 5296 <para>
  5297 + Add method
  5298 + <function>QPDFAcroFormDocumentHelper::addFormField</function>,
  5299 + which adds a new form field, initializing the AcroForm
  5300 + dictionary if needed.
  5301 + </para>
  5302 + </listitem>
  5303 + <listitem>
  5304 + <para>
5297 5305 Add <function>QUtil::path_basename</function> to return the
5298 5306 last element of a path.
5299 5307 </para>
... ...