What would be the best way to capture user entries and selections in an established PDF form?

I’m working on an app in Workshop that takes user inputs and selections and uses them to generate a few outputs. One of the first things it does is record user selections. I did this by having the user trigger a “create object” action by clicking a button and routing the entries to the appropriate fields of an object type.

Having that record will be great for future data adventures, but the powers that be also need those values captured in an existing standardized PDF form. For example, first name, last name, etc. on a Form 1040..

Ideally, I’d be able to auto-fill the different fields with the values that were recorded. Is that possible or would I have to put together some code to replicate the form entirely and then route the values in that??

1 Like

I don’t know how to do that directly in Workshop. You’ll need to write code that fills in the PDF (and generates a new copy of the PDF form each time). You could use a TypeScript package to do that. Or you could use a Python library to do that. Either way, you’ll need to first write the data to the object and then save the new PDF. If TypeScript, then this can happen in the context of an Action. If Python, you’ll need to materialize the edits dataset for that object type (look in Ontology Manager app under the Datasources tab for that object type). And you’d want to create an incremental transform that fills in the PDF.

1 Like

Thanks for this, @taylor is there a way you can expand on this or give an example?

@Ngundrum I don’t have enough time at the moment to build a full example, but I’ve added this to our content production queue. That said, I think I was a bit too pessimistic in my initial reply. After thinking about it a little more here’s what I would do:

  1. Let the user upload the PDF as an attachment. Or maybe you only care about a single PDF form template, in which case you should make it available as an attachment on some single-purpose object dedicated to this workflow. You might be able to add a PDF template directly to your repo as a file, but I haven’t tested that (clone the repo locally, add the file, commit, and then push that back up).
  2. Load the PDF attachment into your Function (see the docs).
  3. Use a package like PDF-LIB to fill the form.
  4. Write the filled PDF as an attachment to a new object that the user can then access. While you can’t return an object from an Action directly, the Workshop button widget will let you get an equivalent behavior. Or you could generate the PK for the new object prior to running the Action and then query the object when the Action submission completes successfully.
1 Like

This sounds very promising! I will give it a go tomorrow ! Thanks for the quick reply! Always great advice