Digital Team
About UsEdit in Gitbook
  • Welcome
  • Getting started
    • Life on the Digital team
      • Meetings
      • Communication
      • Software engineering working agreement
    • Contributing to Boston.gov
    • Using GitBook
  • Standards & best practices
    • Digital Team Release Notes
    • Working with Partners
    • Accessibility at COB
      • Developers
      • Content Editors
        • How to guide
      • Resources
      • Working with Iterators
    • Analytics and Metrics
    • Code of Conduct
    • General
    • Code reviews
    • Project Management
    • Git / GitHub
      • Contacts at Github
      • Git Command Tips
      • GitHub Service Accounts
    • Code quality
      • Automated tests & static analysis
      • Code comments
      • Style guides
        • Drupal/PHP
          • D8 Dependency Injection (DI)
        • React/TypeScript
    • Technical documentation
    • Hosting and monitoring
    • Deployment
  • Guides
    • Technology stack and technologies used
      • Web applications
    • Drupal - boston.gov
      • Custom Development & Configuration
        • On Demand Instances
          • Acquia Environment setup checklist
        • Continuous Deployment Process
        • Developer Onboarding
          • Step 1: Local Dev Environments
          • Step 2: Version control
          • Step 3: Introduction to Drupal
          • (to be sorted)
            • Development environment
              • PHP CodeSniffer
              • VSCode IDE Setup
              • AWS for Developers
              • Using Windows
            • Installation instructions
              • Typical build output
              • Lando 101
              • Verify Installation
                • Local Patterns installation
              • Windows install
              • PhpStorm settings configurations
          • Step 4: Site Building in Drupal 8
        • Site Development Notes
          • Git Best Practices - Drupal
          • Drupal Cache
          • Drupal Config
          • Custom Modules
            • Custom Themes
              • Front-end Theme (bos_theme)
                • Site Breadcrumbs
              • Back-end Theme (bos_admin)
            • Adding Templates to Custom Modules
            • Custom Content Types
              • D7 -> D8 Conversion
              • Content Editor UX
                • Content Moderation
              • In-page Navigation Menu
            • Custom Paragraphs
              • D7 -> D8 Conversion
            • Custom Taxonomies
            • WebApps
          • Drupal UX-specific
            • Image Styles & UX
            • Example Content Pages
          • PHPStorm IDE
        • CKEditor
      • Drupal Apps/Content Types
        • Budget Website
        • Building Housing
          • BH Drupal Entities
          • BH Map Webpage
          • BH Property Webpage
            • BH Project Timeline
          • BH Salesforce Sync
            • Salesforce Contributed Module
        • Contact Form
        • Election results
        • Google reCAPTCHA
        • My Neighborhood Lookup
        • Metrolist
        • Metrolist (Drupal)
        • Project Tracker
          • Content Types (& Paragraphs)
          • Taxonomies
          • Views
          • Developer Notes
      • Drupal Features & Components
        • Single Sign On (SSO)
          • Drupal SAML Knowledgebase
          • SamlAuth
        • Maps on boston.gov
        • Charts on boston.gov
          • Quick Overview
          • Chart Data
          • Chart Configuration
          • Advanced Concepts and Techniques
          • Charts on boston.gov (legacy)
          • Useful Resources
      • Drupal micro-services (API end-points)
        • Integrating with Boston.gov
        • Assessing Forms Endpoint
        • Bos311 API
        • Cityscore
          • Knowledge Base
        • PDF Manager Module
        • PostMark Email Services
          • Postmark Knowledgebase
        • Upaknee Email List Services
        • Public Notices
        • Site Alerts
          • CodeRed Subscription
      • Drupal - Weekly Maintenance
      • Drupal - Periodic Maintenance
    • Digital Webapps
      • Libraries and Tools
        • Emotion
        • Storybook
        • Rollbar
      • Services
        • AWS-hosted Microservices
          • SQL Proxy API (DBConnector)
            • Developer Notes
          • PDFToolkit API (DB Connector)
            • Developer Notes
      • Webapps - Maintenance
      • Webapps
        • Boston Family Days
        • Property Tax Calculator
        • Access-Boston
          • Updating IAMDIR/Group Management/LDAP certificates
          • Node Server
          • Portal App Tile Configurations
          • Ownership of Concerns
          • Updating SAML Certificates
          • Applications/Services
            • Group Management
            • Confirm ID/ID Verification
            • Preferred Name
        • Sanitation Scheduling
        • Registry-Certs
          • Marriage Intention
      • DevOps
        • New service setup
          • Non-Monorepo Service Setup
        • Service Configuration
          • Editing a project’s configuration using Cyberduck
        • Managing AWS
          • Production Overview
          • AWS Bastion Access
          • Terraform
            • Updating the ECS cluster AMI
          • Restarting an ECS service
          • Encrypting service configuration for S3
          • Mounting AWS SFTP as a Drive (Mac)
        • Webapp Deployment
          • Deploy to AWS 2021
            • Deploy Tool (cob_ecrDeploy)
    • Fleet - Pattern Library
      • Patterns Library Architecture
      • Icon Library Architecture
      • Developers
        • Local Development for Drupal Developers
      • Patterns Library Maintenance
    • Legacy Website - cityofboston.gov
      • Animal Control
        • Dog Licenses
      • No Tow
        • Street Sweeping Reminders
        • Street Occupancy Alerts
        • Towing Alerts
        • Towing Search
        • Subscription Search
        • Proposed Restructure
          • Backend
        • Reillys Notes
      • Workers' Compensation Inquiry Form
      • Streetbook
      • Legacy Website - Maintenance
        • Animal Control Maintenance
        • Assessing Online (AOL) Maintenance
          • Knowledge-base
          • Disclosure Period
          • Annual PDF Initialization
          • Database Tables
        • No-Tow Maintenance
    • AgilePoint
      • AgilePoint: Adding Users
      • Migrating AGP Applications from one platform to another
    • The Hub - hub.boston.gov
      • The Hub - Maintenance
    • Maintenance
      • Updating SSL Certificates
    • Redirects
      • Redirecting from cityofboston.gov
      • URL redirects versus URL aliases - Drupal
      • DNS Redirects
    • Decommissioned Apps or Services
      • Archived Forms Information
      • CodeRed
      • Drupal 7
        • Deployment (2019)
          • Why do we peer-review pull-requests ?
      • Rentsmart
      • SnowStats
      • Ruby
    • Weglot translation
      • What to do in Weglot
      • What to do on the website or page
        • Softr
        • Drupal Powered Pages
        • Custom Pages
  • Projects
    • Project: Patterns Library Cleanup
      • Project: Refactoring Legacy CSS
        • Strategy
        • Regression Testing
        • Maintenance
    • Project: Upaknee
    • Project: Everbridge API + UI
    • Project: 311 CRM Upgrade
      • Project: City Worker Upgrade to City Worker 5
      • Project: Lagan 311 CRM upgrade to 15r4
    • Project: Fleet (Pattern Library Design System)
    • Project: Monorepo Decoupling
    • Inactive projects
      • Project: 311 (Salesforce Upgrade)
      • Project: Access Boston
        • General/Historical Documentation
          • Edit Config and Upload Icons
        • Processes
          • Process: Adding New Icon to Access Boston Website
          • Process: Non-icon Access Boston Feature or Bug Requests
          • Self-Service
      • Project: Alexa Skill
      • Project: Assessing Online
        • 2022 Notes
      • Project: Boards and commissions
      • Project: City Hall Appointment Scheduler
      • Project: CityScore
      • Project: Mobile Apps
      • Project: Permit Finder
      • Project: Public Notice Signage
      • Project: Registry Suite
        • Birth certificates
        • Marriage Certificates
        • Marriage Intention
        • Death Certificates
      • Project: Work With U.S. Digital Response Team
      • Project: TDM Points App
      • Project: Translation on boston.gov
  • External resources
    • Learning resources
    • Reference links
    • Applications and extensions
Powered by GitBook
On this page
  • Requirement
  • AWS Microservice
  • Administration Functions
  • Ping to test service is available.
  • Runs an internal test to verify that pdftk is installed properly.
  • PDF File Operations
  • Adds data to fields of a PDF form, and outputs a reference to the completed PDF form.
  • Stamps a PDF on to another PDF, and outputs a reference to the merged PDF.
  • Updates the PDF document properties and outputs a reference to the updated PDF.
  • Removes compression on a PDF, and returns the decompressed file as an attachment.
  • PDF Retrieval
  • Returns the requested PDF document from its reference.

Was this helpful?

Export as PDF
  1. Guides
  2. Digital Webapps
  3. Services
  4. AWS-hosted Microservices

PDFToolkit API (DB Connector)

PreviousDeveloper NotesNextDeveloper Notes

Last updated 2 years ago

Was this helpful?

Requirement

As part of the creation, a method was required that would allow the manipultaion of fillable (form) PDF's.

The requirement was to:

  1. Complete a form PDF inserting data into the fields (rather than just stamping un-editable text on the form), and

  2. 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.

AWS Microservice

The dbconnector service was extended to provide the following endpoints:

Administration Functions

Ping to test service is available.

GET /v1/pdf/heartbeat

{
    "health": "ok"
}

Runs an internal test to verify that pdftk is installed properly.

GET /v1/pdf/test

Internally calls the pdftk and captures the version of the cli.

{
    "test": "success"
}
{
    "error": "My Error is .. <error message>"
}

PDF File Operations

Adds data to fields of a PDF form, and outputs a reference to the completed PDF form.

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.

Request Body

Name
Type
Description

formfile*

String

Url to a form PDF

datafile*

String

Url to a form data file in FDF format

{
    "output": "<file-reference>"
}
{
    "error": 'Error fetching form data file <additional info>'
}
{
    // If nothing is provided in payload.
    "error": "Missing body payload"
}
{
    // formfile not provided.
    "error": "Missing PDF file path in payload."
}
{
    // datafile not provided.
    "error": "Missing PDF file path in payload."
}
{
    "error": 'Error fetching form data file <additional info>'
}

Stamps a PDF on to another PDF, and outputs a reference to the merged PDF.

POST /v1/pdf/overlay

Request Body

Name
Type
Description

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"

{
    "output": "<file-reference>"
}
{
    // If nothing is provided in payload.
    "error": "Missing body payload"
}
{
    // basefile not provided.
    "error": "Missing base PDF file path."
}
{
    // overlayfile not provided.
    "error": "Missing overlay PDF file path."
}
{
    // General failure
    "error": '<reason>'
}
{
    // basefile url did not resolve to a file
    "error": "Error fetching base PDF file <reason>."
}
{
    // overlayfile url did not resolve to a file
    "error": "Error fetching overlay PDF file <reason>."
}

Updates the PDF document properties and outputs a reference to the updated PDF.

POST /v1/pdf/metadata

Request Body

Name
Type
Description

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: ...

...

{
    "output": "<file-reference>"
}
{
    // If nothing is provided in payload.
    "error": "Missing body payload"
}
{
    // basefile not provided.
    "error": "Missing base PDF path."
}
{
    // overlayfile not provided.
    "error": "Missing document properties path."
}
{
    // General failure
    "error": '<reason>'
}
{
    "error": "Error fetching document properties data file <reason>."
}

Removes compression on a PDF, and returns the decompressed file as an attachment.

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.

Query Parameters

Name
Type
Description

pdf_file*

String

Url to a PDF document

del

String

Should the file be deleted after it is downloaded. Defaults to "true".

Returns the decompressed document as an attachment.

The expected headers are:

Content-Disposition:attachment;filename=<pdf_file>
Content-Type:application/pdf
{
    // If nothing is provided in querystring.
    "error": "Missing body payload"
}
{
    // pdf_file not provided.
    "error": "Missing PDF file/path."
}
{
    // General failure
    "error": '<reason>'
}
{
    // pdf_file url did not resolve to a file
    "error": "Error fetching compressed data file <reason>."
}

PDF Retrieval

Returns the requested PDF document from its reference.

GET /v1/pdf/fetch

Query Parameters

Name
Type
Description

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)

Returns the document as an attachment.

When show=D, expected headers are:

Content-Disposition:attachment;filename=<pdf_file>
Content-Type:application/pdf

The when show=I, expected headers are:

Content-Disposition:filename=<pdf_file>
Content-Type:application/pdf
{
    // Response
}
PDFManager Module