PDF Document Generation

The Past, Now and the Future

PDF Generation

One of the core utilities that Jotform provides

It's used in various places:

  • Attachment on submission notification and autoresponders
  • Jotform Sign - Preview, Downloading the document
  • Jotform Approvals - Approval Report, PDF Attachment on emails
  • Integrations - Send document to Google Drive, Dropbox, Onedrive, etc..
  • Thank you Pages - Providing the document version of the submission
  • Inbox, Tables, PDF Editor - Downloading submission document when needed
  • Product List - Invoice for Purchase orders & Payments
  • Fillable PDF - As the base of the PDF to be decorated with PDF Input elements

 

The Past

It was a kind of mode of the PDF Editor. Document rendering logic is living in the PDF Editor (WYSIWYG), PDF generation was leveraging this.

 

With Puppeteer (an automated browser manager) we were opening the PDF Editor with special flags and user's API key, printing onto a PDF simulating browser's native print function, uploading the file to S3 to obtain a URL and returning URL to the PHP backend

 

The Problem

  • Fragile: it was being affected by potential mistakes made on the daily development activities.
  • Unpredictable: there are too much moving parts: PDF Editor needs to be loaded over the internet, submission and document data should be accessible by the app. Hard to debug when something go wrong.
  • Vulnerable: API keys and passwords (for pw protected documents) was passing around within requests between different parts of the backend

The Solution

  • Separation of concerns: PDF Generation shouldn't be a part of the PDF Editor. It should be an independent service
  • It shouldn't rely on loading the PDF Editor (a massive app).
  • Form, Document and Submission data + PDF Rendering logic should be sufficient.

React component Level

  • A react component that has the PDF Rendering logic: @jotforminc/pdf-ground

App Level

  • A Jotform App to render pdf-ground component and make  accessible through a URL: pre-pdf

PHP Backend Part

  • Backend side: A method to distinguish old & new PDF Generation mechanism within the generatePDF function: generatePDFWithPrePDF

Node Backend Part

  • A new repo which is responsible for PDF Document Generation: pdf-engine

Development Tool Part

  • A very simple tool on pages repo in order to utilize these parts in order to preview and debug how a document would appear: display-pdf

Logging

  • Dashboards on Kibana in order to see overall succes/fails and durations for successful generation

The Future

On pdf-engine, we upload the produced documents to S3. This takes time, resource, cost on AWS and possible failures retrieving this file in order to attach onto email or send via integration. We'll be trying to remove S3 operations and will be returning the produced file itself to PHP backend side. 

This way we won't have any problem regarding accessing our own document, won't be waiting for uploading and downlading time and achieve more robust and sound operation on overall.

PDF Generation

By Burak Koksal

PDF Generation

  • 12