As part of the PDFManager Module creation, a method was required that would allow the manipultaion of fillable (form) PDF's.
The requirement was to:
Complete a form PDF inserting data into the fields (rather than just stamping un-editable text on the form), and
Add a barcode and text to an existing PDF form, and output the resultant PDF as a form (the v1 PDFManager using a PHP solution always output a flat non-form PDF, even if a form PDF is used as the input).
This could not be achieved (in 2022) using an opensource PHP module, but there is a well established and proven Linux CLI app which can be utilized, and provided a couple of additional features to the requirement.
The main Drupal site (served by an Acquia webserver), while running on Linux is not managed by City of Boston and the pdftk libraries are not loaded on that server. Given the short time constraints, the pdftk was deployed within the same container as the DBConnector, leveraging the existing endpoint services (node/javascript/express) and some shellscripting.
The dbconnector service was extended to provide the following endpoints:
GET
/v1/pdf/heartbeat
GET
/v1/pdf/test
Internally calls the pdftk and captures the version of the cli.
POST
/v1/pdf/fill
A PDF and data file must be provided. The PDF must be a fillable form PDF and the data file must be a file in an FDF format.
The /v1/pdf/generate_fdf endpoint can be used to generate a blank FDF data file.
POST
/v1/pdf/overlay
POST
/v1/pdf/metadata
GET
/v1/pdf/decompress
This is a useful utility to use the PDFManager cannot manipulate a PDF because its compression is later than PDF1.5.
The endpoint first checks to see if it already has a file with the filename specified in the pdf_file
query parameter. If it does, then it just returns that file.
NOTE: restarting the dbconnector task(s) on AWS will empty this cache.
If the del
parameter is "true" then the file is deleted after decompression and downloading. To reduce load on the endpoint, set to "false" if the pdf_file
does not change often and if you expect to call the function frequently.
Returns the decompressed document as an attachment.
The expected headers are:
GET
/v1/pdf/fetch
Returns the document as an attachment.
When show=D, expected headers are:
The when show=I, expected headers are:
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
formfile*
String
Url to a form PDF
datafile*
String
Url to a form data file in FDF format
basefile*
String
A PDF document - can be a URL or a file-reference returned from another endpoint.
overlayfile*
String
URL to a PDF document
overwrite
String
Defaults to "true"
pdf_file*
String
A PDF document - can be a URL or a file-reference returned from another endpoint.
meta_data*
String
A file in a the following format:
InfoBegin
InfoKey: <one of title, author, subject, creator, producer>
InfoValue: <the value to set>
InfoKey: ..
InfoValue: ...
...
pdf_file*
String
Url to a PDF document
del
String
Should the file be deleted after it is downloaded. Defaults to "true".
file*
String
A file-reference from one of the endpoints
del
String
Delete the file after downloading. defaults to false
show
String
Download method: D (default) downloads attachment, I download and display in browser (if supported)
This page contains information for developers wishing to update or maintain the pdf endpoint on the dbconnector service.
Also see SQLProxy setup notes
Also see SQLProxy testing notes
Also see SQLProxy deployment notes
The PDF Chain tool for Ubuntu has a nice interface which utilizes the features of the PDF Toolkit which is used by the DBConnector. This is particularly useful for extracting fdf data files from fillable forms, which can then be manually edited and fed back into the form for in-dev-testing.
The non-fillable PDF generator has a maximum PDF version of 1.5. Many PDF generators, including fillable PDF forms save in version 1.6.
Version 1.6 works fine for the fillable PDF processes but using a v1.6 PDF docs cause the non-fillable PDF process to fail for the PDF generator.
To downgrade a PDF from v1.6 to v1.5, use the following gostscript command on Ubuntu:
You can determine the version using this command: