Skip to Main Content

Monday, November 2, 2020

Create, Read, Fill and Flatten PDF Forms with APEX Office Print 20.3

APEX Office Print (AOP)

In the last three years, we've put a lot of effort into the PDF capabilities of APEX Office Print (AOP).

 
With AOP 20.3 we are releasing an additional sample app focussed just on PDF generation and manipulation. Here's an overview of the main page, highlighting our many features:
 
 
In this blog post, I want to cover PDF Forms. PDF Forms have been around for a long time. My guess is that everybody has had to fill in at least one PDF Form already. An example we as a company have to fill in a lot is the W-8BEN form, another example is Form 941 Federal Tax Return. 
 
Before I go into how you can fill such a PDF Form automatically, let's first look at how you can create a PDF Form yourself with AOP! It looks like COVID increased the requirement to create such forms directly from the database, at least we received many more requests for such a feature lately.
 
 
First, you create a template in Word (docx), and anywhere you want a form item (text box, radio group, checkbox) you specify the tag {?form name}.
 
Next, for every form item you need to specify how it should look in the data you send with the template.
You can specify the item details in AOP by defining the JSON, a SQL, or PL/SQL statement for example. Here's how the definition looks in a SQL Statement and in JSON:
 
 
You define your template and data source in the AOP APEX Plug-in (or PL/SQL API).
 
 
That's it, AOP will do the rest and create your beautiful PDF Form automagically! :)
 
Now let's see what AOP can do with PDF Forms we received? E.g. the W-8BEN Form.
Our dream was to read the PDF Form, identify the fields, and fill it automatically and get a filled-in PDF back... and we nailed it! 😀
 
 
Use the AOP plug-in to tell which PDF you want to read, and set the global variable g_identify_form_fields to true. AOP generates a new PDF that identifies every field and shows what the name is.
 
 
If you want all the fields in a JSON, use the AOP PL/SQL API and specify FORM_FIELDS  as output type:
 
 
You get back a nice JSON with all the different form fields, the type, and the value, in case it's filled in.
 
To fill the items, you call AOP and specify in "aop_pdf_form_data" the data to fill in the PDF Form.
 
 
Finally, in case you filled in the PDF Form and now want to make sure other people can't change the fields anymore, you would flatten the PDF. Again, use the AOP PL/SQL API or APEX Plug-in, set the global variable g_output_lock_form to true and you are done!
 
 
In the AOP PDF Sample App you will see that the PDF on the left you can still edit, while on the right, you can't:
 
 
It's not going to be any easier than this!
 
In case you need to generate PDF Forms, or you need to fill in forms or you want to process and read those filled-in PDF Forms, AOP can really help. It was a tough nut to crack, but I'm super proud the team was able to pull it together.
 
Be on the lookout for APEX Office Print 20.3, it's coming to you very soon!

Author: Dimitri Gielis
View original post here.

Pagination

Comments

No comments yet on this post