From 397b097c469db89a49e5a6c2035a0beee2e4d117 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2018 15:00:00 -0400 Subject: Allow setting a form field's value --- include/qpdf/QPDFAcroFormDocumentHelper.hh | 17 +++++++++++++++++ include/qpdf/QPDFFormFieldObjectHelper.hh | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'include') diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index d786fff4..2aa0d377 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -135,6 +135,23 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper QPDFFormFieldObjectHelper getFieldForAnnotation(QPDFAnnotationObjectHelper); + // Return the current value of /NeedAppearances. If + // /NeedAppearances is missing, return false as that is how PDF + // viewers are supposed to interpret it. + QPDF_DLL + bool getNeedAppearances(); + + // Indicate whether appearance streams must be regenerated. If you + // modify a field value, you should call setNeedAppearances(true) + // unless you also generate an appearance stream for the + // corresponding annotation at the same time. If you generate + // appearance streams for all fields, you can call + // setNeedAppearances(false). If you use + // QPDFFormFieldObjectHelper::setV, it will automatically call + // this method unless you tell it not to. + QPDF_DLL + void setNeedAppearances(bool); + private: void analyze(); void traverseField(QPDFObjectHandle field, diff --git a/include/qpdf/QPDFFormFieldObjectHelper.hh b/include/qpdf/QPDFFormFieldObjectHelper.hh index b45955a3..c22703aa 100644 --- a/include/qpdf/QPDFFormFieldObjectHelper.hh +++ b/include/qpdf/QPDFFormFieldObjectHelper.hh @@ -114,6 +114,29 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper QPDF_DLL int getQuadding(); + // Set an attribute to the given value + QPDF_DLL + void setFieldAttribute(std::string const& key, QPDFObjectHandle value); + + // Set an attribute to the given value as a Unicode string (UTF-16 + // BE encoded). The input string should be UTF-8 encoded. + QPDF_DLL + void setFieldAttribute(std::string const& key, + std::string const& utf8_value); + + // Set /V (field value) to the given value. Optionally set + // /NeedAppearances to true. You can explicitly tell this method + // not to set /NeedAppearances if you are going to explicitly + // generate an appearance stream yourself. + QPDF_DLL + void setV(QPDFObjectHandle value, bool need_appearances = true); + + // Set /V (field value) to the given string value encoded as a + // Unicode string. The input value should be UTF-8 encoded. See + // comments above about /NeedAppearances. + QPDF_DLL + void setV(std::string const& utf8_value, bool need_appearances = true); + private: class Members { -- cgit v1.2.3-54-g00ecf