PDF Templates

PDF generation system for creating documents from templates with mapped data fields. Supports multi-page templates, combined fields, fill-in sessions, and e-signature integration.

Source Files

LayerPath
Schemabackend/src/db/schema.ts
Template Routesbackend/src/routes/admin/pdf-templates.ts
Field Def Routesbackend/src/routes/pdf-data-field-definitions.ts
Combined Field Routesbackend/src/routes/pdf-combined-fields.ts
Export Routesbackend/src/routes/pdf-export.ts
Session Routesbackend/src/routes/pdf-document-sessions.ts
Export Servicebackend/src/services/pdf-export-service.ts
Template Servicebackend/src/services/pdf-template-service.ts
Session Servicebackend/src/services/pdf-session-service.ts
Admin Pagefrontend/src/pages/admin/PdfTemplatesList.tsx
Export Pagefrontend/src/pages/PdfExport.tsx
Componentsfrontend/src/components/pdf/ (8 files)

Database Tables

TablePurpose
pdfTemplatesMain entity — name, description, page count, status
pdfTemplatePagesIndividual pages within a template (background image, dimensions)
pdfTemplateFieldsPositioned fields on a page (x, y, width, height, font, mapping)
pdfCombinedFieldsComposite fields that merge multiple data sources into one output
pdfDataValuesStored values for template fields per entity
pdfDocumentSessionsTracks form-filling progress (draft state, completion status)
pdfDataFieldDefinitionsReusable field definitions with data source mappings

PDF Generation Pipeline

  1. Template design — admin uploads page backgrounds and positions fields via the template editor
  2. Field mapping — each field is linked to a data source (entity field, combined field, or manual input)
  3. Session creation — user starts a fill-in session for a specific entity (e.g., building or project)
  4. Data population — mapped fields auto-fill from entity data; manual fields are filled by the user
  5. Exportpdf-lib renders the final PDF with all field values overlaid on the template pages
  6. Storage — generated PDF is saved as a file and linked to the source entity

E-Signature Integration

TablePurpose
signatureRequestsOutgoing signature requests linked to a PDF document
signedDocumentsCompleted signed documents returned from the signature provider

Signature workflow integrates with external e-signature services for legally binding document signing.

Frontend Components

ComponentPurpose
PdfTemplateEditorVisual editor for positioning fields on template pages
PdfFieldMapperMap template fields to data sources
PdfPreviewLive preview of the generated PDF
PdfSessionFormFill-in form for manual fields during a session
PdfExportDialogExport options and download

Relationships

PdfTemplate 1──* PdfTemplatePages 1──* PdfTemplateFields
PdfTemplate 1──* PdfDocumentSessions
PdfTemplateField *──1 PdfDataFieldDefinition
PdfCombinedField *──* PdfDataFieldDefinitions
Session *──1 Users (author)
Session ──> Files (exported PDF)

Documents | Files | Buildings | Projects | Admin Dashboard | Service Layer Pattern | Database Architecture