Skip to content

feat(gateway): implement PDF form stamping with iText #11

@rsalus

Description

@rsalus

Note for implementers: The design outlined here is a guideline, not a strict specification. Feel free to pivot from the suggested approach if you discover a better solution during implementation. Update the issue with your rationale when deviating significantly.

Summary

Implement PDF form stamping using iText7 to fill prior authorization form templates.

Context

The current PdfFormStamper returns an empty byte array. Production implementation must:

  1. Load procedure-specific PA form template
  2. Map PAFormData.FieldMappings to AcroForm fields
  3. Fill and flatten the form
  4. Return stamped PDF bytes

Dependencies

Issue Relationship
#5 Blocked by - need form template

Tasks

  • Load PDF template from assets
  • Access AcroForm using iText7 API
  • Iterate FieldMappings and set values
  • Flatten form after filling
  • Write to MemoryStream and return bytes
  • Handle missing fields (log warning, continue)
  • Add unit tests with sample PDF

iText7 Pattern

using var pdfDoc = new PdfDocument(new PdfReader(template), new PdfWriter(output));
var form = PdfAcroForm.GetAcroForm(pdfDoc, true);

foreach (var (fieldName, value) in formData.FieldMappings)
{
    var field = form.GetField(fieldName);
    if (field != null) field.SetValue(value);
}

form.FlattenFields();

Files

File Action
apps/gateway/Gateway.API/Services/PdfFormStamper.cs Modify
apps/gateway/Gateway.API/Assets/sample-pa-form.pdf Create
apps/gateway/Gateway.API.Tests/Services/PdfFormStamperTests.cs Create

Design References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions