PDF Server
https://hub.docker.com/repository/docker/formio/pdf-server
The Form.io PDF Solution is a powerful tool with two options: PDF Server and PDF Server Plus. Please see the below description of each to see which aligns best with the requirements of the Application being built.
The Form.io PDF server is currently not compatible with Apple M1 chips and ARM64 architecture. The guide below will detail how to run this server on other systems like an Intel Mac or Linux machine.
PDF Basic
The Use Case: PDF print out of the JSON-driven dynamic webform submissions filled out by the end-user within your application.
PDF Plus
The Use Case: Forms are required to be on a pixel-perfect PDF background with a dynamic JSON form overlay on top of the PDF.
A PDF template designer that allows customization of the data and layout for PDF downloads generated from webform submissions made by the end-user
PDF-First forms can also be presented to the user as responsive web forms, but enable the ability to print the Submission to the pixel-perfect PDF background.
Contact sales@form.io for more information on the PDF Plus Server
Deploying the PDF Server in a Private Cloud or On-Premise Environment
Recommended CPU/memory config is 2 CPU cores and 4GB of memory.
A common deployment command for the PDF server looks as follows.
Which uses the following Environment Variables.
Environment Variables for Deployment
Required Environment Variables
The following environment variables are always required.
LICENSE_KEY
A Form.io license key
MONGO
The connection string to your MongoDB-compliant database
DB_SECRET
The database secret. Although not technically required, it must match your Enterprise Server's DB_SECRET environment variable.
File Storage Environment Variables
The following environment variables involve the PDF Plus Server's file storage integration for storing PDF files. The PDF server currently supports minio, Amazon S3, and Azure Blob.
FORMIO_S3_SERVER
Minio hostname or IP address. Required when using minio. If set, the PDF Server will assume a minio configuration. If not set AND other FORMIO_S3_* variables are set (in particular, FORMIO_S3_REGION, FORMIO_S3_KEY, or FORMIO_S3_SECRET), the PDF Server will assume an AWS S3 configuration.
FORMIO_S3_PORT
Minio port. Defaults to 9000.
FORMIO_S3_BUCKET
S3 bucket name. Required when using minio or AWS S3.
FORMIO_S3_KEY
AWS Access Key Id if using AWS S3, accessKey
(the user-like id) if using minio. Required when using minio.
FORMIO_S3_SECRET
AWS Secret Access Key if using AWS S3, secretKey
(the password-like id) if using minio. Required when using minio.
FORMIO_AZURE_CONNECTION_STRING
The connection string to your Azure Blob deployment. Required when using Azure Blob storage.
FORMIO_AZURE_CONTAINER
The Azure Blob container name. Required when using Azure Blob storage.
Optional Environment Variables
The following environment variables are optional.
FORMIO_PDF_ADMINKEY
Set this environment variable to communicate server-to-server with the PDF Server. The value for this environment variable passed as the x-admin-key
header when sending server-to-server API calls to the PDF Server. See https://apidocs.form.io/#8e817291-38df-4338-889f-14cf38de5fbd for more information on how to use this header.
MONGO_DB_NAME
Mongo database name, if using localhost
MONGO_CA
File path to an SSL certificate authority file. This is usually a file with an extension of ".pem". For example, AWS DocumentDB may require this to be like the following value: "/src/certs/rds-combined-ca-bundle.pem"
DOCKER_SECRETS
Whether to enable using docker secrets.
DOCKER_SECRETS_PATH
The path to the docker secrets.
LICENSE_REMOTE
Boolean to indicate if the license key provided is an offline remote license key.
PDF_BROWSER_TIMEOUT
Determines how long (in milliseconds) the browser can run and execute before timing out. Default is 120000 milliseconds or 2 minutes.
DEBUG
Perform debugging within a PDF server. The following debug commands will do the following. This uses the Debug Module for Node.js so documentation can be found @ https://github.com/visionmedia/debug.
- DEBUG=*
: Debug everything
- DEBUG=pdf.*
: Debug all PDF related events
- DEBUG=pdf.create.*
: Debug the PDF upload process
- DEBUG=pdf.get.*
: Debug the PDF fetching process
- DEBUG=pdf.delete.*
: Debug the PDF deleting process
- DEBUG=pdf.download.*
: Debug the PDF submission download process.
Configure Portal for PDF Server
Now that you have the PDF server operational as well as the API Server, the next thing that needs to happen is to configure the Form.io Portal to use the correct DNS URL for the PDF Server URL. This is necessary because the "internal" DNS URL is used within the Enterprise Server configurations, and we now need to let the Portal know how to directly communicate with the PDF Server. To set this up, you will first need to navigate to your Project Settings and then click on PDF Server configuration page. Here you will then need to provide the Public DNS URL to the pdf server as follows.
The PDF Server URL field shown in Project Settings was deprecated in 8.0.1 and removed from the interface. It is now fully managed by the PDF_SERVER environment variable that is set on the API server.
Once you have done this, you should now be able to upload an existing PDF form, where it will then convert that PDF document into a Form.io webform overlay on top of that PDF form.
PDF Server Fine Tuning
This section covers some aspects of fine tuning a PDF server. If you want to speed up your deployment or you want to configure your deployment for large PDF handling, you might want to give a look at this section.
Mounting /tmp directory to RAM
If you have a virtual machine with large amount of RAM available, you can benefit from it by mounting container's /tmp
directory to RAM. You can to this by adding --tmpfs /tmp:rw
parameter to your docker run
command. This will allow PDF Server to speed up IO processes by storing files in RAM instead of disk.
Configuring file cache time
File cache is a disk cache for HTML files used for PDF downloads. Default cache time is one hour. If you have a lot of PDF first forms with different PDFs in the background and you expect that all that forms will be printed to PDF very often, you might want to configure file cache time to eliminate disk memory limit reach. To do this you need to add FILE_CACHE_TIME
environment variable to PDF Server config. The value should be number of milliseconds. The smaller cache time will result to less disk space usage and lower performance. The bigger cache time will result to more disk space usage and increased performance.
Configuring default viewer
If you prefer to use custom viewer rather that default viewer for PDF downloads, you can increase PDF download performance by adding PAGE_POOL_DEFAULT_VIEWER
an environment variable to PDF server config. Its value should be the URL of your custom viewer.
Configuring timeouts
Here is the list of all configurable timeouts and their purposes:
PDF_BROWSER_TIMEOUT
Used for PDF downloads. If you are printing large PDF files or your custom viewer has a lot of contents, you might want to increase this value.
120000
PDF_PRINTING_TIMEOUT
Used for PDF downloads. If you are printing large submissions and/or large PDF files, consider increasing this value.
30000
HTML_GENERATION_TIMEOUT
Primary timeout for html generation. It's used for PDF uploads. If you are going to upload large PDF files, consider increasing this value.
7000
HTML_GENERATION_BACKOFF
Backoff timeout for html generation. Its sum with primary timeout will be used for second try after postscript optimisation in case when first try failed. If you are going to upload large PDF files, consider increasing this value as well.
23000
PDF Server Plus Auto-Conversion
The PDF Server Plus includes Auto-Conversion of existing fillable and non-fillable PDF Forms. Using AWS Textract for PDF First Forms that do not have any metadata that can be read for conversion, the PDF Server will auto-detect Field Input Types, Labels and more and convert the PDF to a dynamic Form.io Form!
AWS Textract Integration
Please note that the Textract feature is exclusively compatible with AWS S3 bucket storage infrastructure. Unfortunately, it is NOT compatible with Minio or other object storage providers. It is imperative to utilize AWS S3 for object storage in order to leverage the functionalities of Textract effectively.
After setting up PDF Server it is possible to integrate with AWS Textract to enable Formfields Recognition feature.
Steps to integrate:
Create IAM role with AmazonTextractServiceRole & AmazonSNSFullAccess policies
Create a Custom trust policy with the following JSON structure.
Next add your AmazonTextractServiceRole & AmazonSNSFullAccess permissions.
Add a Role name and then press Create Role in the bottom right corner.
Verify that the AWS User has permissions for textract:StartDocumentAnalysis & textract:GetDocumentAnalysis
This can be done with a similar inline policy like outlined above but for the security credentials belonging the security credentials being utilized.
Create AWS Simple Notification Service topic and save its ARN
Add the following environment variables to the configuration:
FORMIO_S3_BUCKET
Name of the S3 bucket where files are stored
-
FORMIO_S3_KEY
AWS public access key
-
FORMIO_S3_SECRET
AWS secret access key
-
FORMIO_S3_REGION
AWS bucket region
us-east-1
TEXTRACT_ROLE_ARN
ARN of IAM role for Textract.
-
TEXTRACT_SNS_TOPIC_ARN
ARN of SNS topic.
-
TEXTRACT_OUTPUT_FOLDER
S3 bucket folder where Textract will store its output.
textract-output
TEXTRACT_MAX_SYNC_COUNT
Allows for configure the timeout for Textract processing to finish. Increase for larger non-fillable documents. (Optional)
90
4. After starting the PDF environment with new environment variables, go to the previously created SNS topic page and create a subscription:
Leave Topic ARN as-is
In Protocol field choose HTTPS
In Endpoint field type *public URL of your environment. Example: https://my.formioapi.com/pdf/pdf/sns
After configuration you can check the status of formfields recognition by visiting URL
{{apiServerUrl}}/pdf/pdf/sns/recognizeFormfieldsStatus
Validate that PDF Plus upload works with a Non-fillable PDF and has Textract perform field recognition on the non-fillable pdf form. An example non-fillable pdf form has been provided below.
In the case of misconfiguration, you will not be able to upload a PDF file.
Last updated