Sidebar

Can QIE fill a PDF form from message content

0 votes
329 views
asked May 1, 2019 by ben-s-7515 (12,320 points)
We have a fillable PDF that we need to fill with information from an inbound message.  Is it possible to use QIE to get these forms filled and saved into an alternate location?

1 Answer

0 votes

Yes, QIE is able to take a message and fill a PDF form, then save the new form to a new location.

NOTE: This example uses PDFBox found here.  You will need to download the following jar files:
1) pdfbox-2.0.15.jar
2) pdfbox-tools-2.0.15.jar
3) fontbox-2.0.15.jar
4) preflight-2.0.15.jar
5) xmpbox-2.0.15.jar

// read the PDF document
var pdfDocument = org.apache.pdfbox.pdmodel.PDDocument.load(new java.io.File("{full_path_to_pdf_document}"));
try {
   // using PDFBox read the form from the PDF document
   var acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
   
   // we first check to make sure that the PDF document did have a form
   if (acroForm !== null) {
      // get a list of the available fields in this form
      var fields = acroForm.getFields();
      
      // this will log out the field names from the form
      var iterator = fields.iterator();
      while (iterator.hasNext()) {
         // get the individual field
         var field = iterator.next();
         qie.debug(field.getFullyQualifiedName());
         qie.debug(field.getPartialName());
      }
      
      // we will now get a field by name and update the value
      var field2 = acroForm.getField("{field_name}");
      // set the value of this field
      field2.setValue(source.getNode('{node_path}'));
   }
   
   // save the updated form to a desired location
   pdfDocument.save("{full_path_to_new_file}");
} finally {
   pdfDocument.close();
}

Using this as a sample starting point, you will be able to find all of the fields, and then populate any fields in the form that need to be populated from data in a message.

answered May 1, 2019 by ben-s-7515 (12,320 points)
...