diff options
Diffstat (limited to 'examples/pdf-set-form-values.cc')
-rw-r--r-- | examples/pdf-set-form-values.cc | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/examples/pdf-set-form-values.cc b/examples/pdf-set-form-values.cc index c2793142..a1a19db1 100644 --- a/examples/pdf-set-form-values.cc +++ b/examples/pdf-set-form-values.cc @@ -29,41 +29,33 @@ main(int argc, char* argv[]) char const* outfilename = argv[2]; char const* value = argv[3]; - // This is a contrived example that just goes through a file page - // by page and sets the value of any text fields it finds to a - // fixed value as given on the command line. The purpose here is - // to illustrate use of the helper classes around interactive - // forms. + // This is a contrived example that just goes through a file page by page and sets the value of + // any text fields it finds to a fixed value as given on the command line. The purpose here is + // to illustrate use of the helper classes around interactive forms. try { QPDF qpdf; qpdf.processFile(infilename); - // We will iterate through form fields by starting at the page - // level and looking at each field for each page. We could - // also called QPDFAcroFormDocumentHelper::getFormFields to - // iterate at the field level, but doing it as below - // illustrates how we can map from annotations to fields. + // We will iterate through form fields by starting at the page level and looking at each + // field for each page. We could also called QPDFAcroFormDocumentHelper::getFormFields to + // iterate at the field level, but doing it as below illustrates how we can map from + // annotations to fields. QPDFAcroFormDocumentHelper afdh(qpdf); for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { - // Get all widget annotations for each page. Widget - // annotations are the ones that contain the details of - // what's in a form field. + // Get all widget annotations for each page. Widget annotations are the ones that + // contain the details of what's in a form field. for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) { - // For each annotation, find its associated field. If - // it's a text field, set its value. + // For each annotation, find its associated field. If it's a text field, set its + // value. QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(annot); if (ffh.getFieldType() == "/Tx") { - // Set the value. Passing false as the second - // value prevents qpdf from setting - // /NeedAppearances to true (but will not turn it - // off if it's already on), so we call - // generateAppearance after setting the value. You - // may or may not want to do this depending on - // whether the appearance streams generated by - // qpdf are good enough for your purposes. For - // additional details, please see comments in + // Set the value. Passing false as the second value prevents qpdf from setting + // /NeedAppearances to true (but will not turn it off if it's already on), so we + // call generateAppearance after setting the value. You may or may not want to + // do this depending on whether the appearance streams generated by qpdf are + // good enough for your purposes. For additional details, please see comments in // QPDFFormFieldObjectHelper.hh for this method. ffh.setV(value, false); ffh.generateAppearance(annot); |