Uploading New PDFs
This guide shows you how to add a new PDF to the Namesake repository along with metadata.
Download the original file
Section titled “Download the original file”First, download the original PDF file. If the PDF you found is from an unofficial source, find the canonical latest version from a .gov website.
Start the PDF Manager
Section titled “Start the PDF Manager”From the namesake directory, run:
pnpm dev:pdfThis will open the PDF Manager at http://localhost:3456.
Upload the PDF
Section titled “Upload the PDF”Once the PDF Manager is running, click Add PDF and upload your file.
You will be prompted for:
- Form title — e.g. “Petition to Change Name of Adult”
- Form code (optional) — e.g. “CJP-27”
- Canonical URL — the URL for the original file, e.g. https://www.mass.gov/doc/petition-to-change-name-of-adult-cjp-27/download
- Jurisdiction — e.g. “MA”
Complete the fields and click Create.
On success, you will see your new PDF appear in the PDF Manager alongside a list of form fields.
Behind the scenes, the PDF has been copied into a new folder inside web/src/pdfs alongside new index.ts, index.test.ts, and schema.ts files. Take a look inside these files to see what’s inside them.
Now it’s time to clean up the form fields.
Exclude unused fields
Section titled “Exclude unused fields”Some fields, like internal bureaucratic coding, will never be filled in by a Namesake user.
Any field that will never take user input should be excluded from the schema.
To exclude a field using the PDF Manager, select the field name from the list and press Delete or Backspace. Excluded fields will appear at the bottom of the list with a strikethrough. Click Save to write all exclusions to disk.
Rename remaining fields
Section titled “Rename remaining fields”Once unused fields have been excluded, the remaining fields should be renamed. We rename fields to make it easier to work with PDFs, and because the default names are often undescriptive.
First, select a field in the list. The PDF preview highlights the current field so you can see it in context. Press Enter or double-click the list item to rename it. When you have finished renaming fields, click Save to write changes to disk.
Connect PDF fields to user data
Section titled “Connect PDF fields to user data”The index.ts file for each PDF contains an exported PDFDefinition. This lists the id, title, code, and other metadata about the PDF, along with a resolver. The resolver is a function that maps PDF field names to user data. At the start, all data will be listed as undefined.
export default definePdf<PdfFieldName>({ id: "cjp27-petition-to-change-name-of-adult", title: "Petition to Change Name of Adult", // ... resolver: (data) => ({ petitionerFirstName: undefined, petitionerMiddleName: undefined, petitionerLastName: undefined, county: undefined, oldFirstName: undefined, oldMiddleName: undefined, oldLastName: undefined, // ... }),});We want to replace undefined values with data from the user, but before we can do that, we will need to build a user-facing form to collect data!
Since building a form will take a fair amount of work, let’s go ahead and open a pull request to get our new PDF definition reviewed with fields mapped to undefined. Once we’ve built the form, we can come back and map the values to data from the user.
Congrats! You’ve added a new PDF to Namesake.