Skip to content

Add invoice generation complex flow sample - #130

Merged
datalogics-cgreen merged 22 commits into
pdfrest:mainfrom
datalogics-erics:add-to-pdf-shape-table-samples
Aug 14, 2026
Merged

datalogics-cgreen merged 22 commits into
pdfrest:mainfrom
datalogics-erics:add-to-pdf-shape-table-samples

Conversation

@datalogics-erics

@datalogics-erics datalogics-erics commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a Complex Flow Example that generates a realistic invoice from structured application data through the public pdfRest API.

The sample reads fictional invoice metadata and styling from JSON, line items from CSV, and a local logo image. It creates a blank Letter PDF and composes the invoice with these endpoints:

  • Create Blank PDF
  • Add Shapes to PDF
  • Add Text to PDF
  • Add Tables to PDF
  • Add Image to PDF

The table is built from every CSV row and uses automatic pagination, repeated headers, reserved page regions, totals, and optional tagging. The workflow also adds payment terms, notes, and page numbering after determining the generated page count. The logo is uploaded once and then referenced by its returned resource ID.

Included inputs

  • metadata.json: Fictional seller, customer, invoice, tax, payment, and note data.
  • style.json: Fonts, colors, table text size, and border settings.
  • line-items.csv: Variable invoice line items used to build the table.
  • northstar-logo.png: Fictional local logo image used in the invoice header.

Validation

Each language implementation was run against https://api.pdfrest.com with the same fictional JSON, CSV, and logo inputs:

  • Python
  • Java
  • JavaScript
  • PHP
  • .NET
  • cURL

Each workflow completed all nine API operations successfully with HTTP 200 responses, including the image upload operation. Every generated output was verified as a tagged, two-page Letter PDF. qpdf --check reported no syntax or stream encoding errors for any output. The PHP run also completed without the PHP 8.5 CSV deprecation warning.

- Create a blank PDF and compose an invoice through pdfRest endpoints.
- Build tagged text, shapes, an auto-paginated table, and an image from
  JSON, CSV, style, and logo inputs.
- Include fictional invoice data that demonstrates multipage output,
  reserved footer space, and final totals.

Assisted-by: Codex
- Split the seller and customer panels into aligned boxes.
- Move the table closer to the header to reduce unused page space.
- Keep text padding and table margins aligned with the document edges.

Assisted-by: Codex
- Align the table position field with the surrounding profile properties.
- Keep the sample source consistently formatted after the layout update.

Assisted-by: Codex
- Keep seller details in the From box instead of repeating them above it.
- Increase and reposition the billing boxes to clear the invoice metadata.
- Add realistic service rows so the continuation page has useful content.

Assisted-by: Codex
- Move the From and Bill To panels lower on the first page.
- Keep the spacing even between invoice metadata, panels, and the table.
- Move the panel text with its containing shapes to preserve padding.

Assisted-by: Codex
- Reserve more bottom space for the table on ordinary pages.
- Raise running footers into the reserved content area.
- Keep the final-page footer below the payment panel.

Assisted-by: Codex
- Use the same footer baseline on every invoice page.
- Position the final payment panel above the shared footer.
- Keep both payment sections inside the panel boundary.

Assisted-by: Codex
- Raise payment terms and notes text within the final panel.
- Preserve balanced padding above the shared footer.
- Keep both content sections clear of the panel borders.

Assisted-by: Codex
- Document the API key environment variable and bundled inputs.
- Include dependency installation and the command to run the sample.
- Help new users understand the generated output location.

Assisted-by: Codex
- Build a tagged invoice from bundled JSON and CSV inputs.
- Compose the document with blank PDF, shapes, text, table, image,
  page-info, and resource endpoints.
- Include fictional metadata, styling, line items, and logo assets.

Assisted-by: Codex
- Build a tagged invoice from bundled JSON and CSV inputs.
- Compose the document with blank PDF, shapes, text, table, image,
  page-info, and resource endpoints.
- Declare the multipart form dependency used by the workflow.

Assisted-by: Codex
- Build a tagged invoice from bundled JSON and CSV inputs.
- Compose the document with blank PDF, shapes, text, table, image,
  page-info, and resource endpoints.
- Include setup guidance for the Guzzle dependency and API key.

Assisted-by: Codex
- Add a routed complex-flow sample for tagged invoice generation.
- Build the document from bundled JSON and CSV inputs using pdfRest
  blank PDF, shapes, text, table, image, page-info, and resource calls.
- Document the command-line entry point and API key configuration.

Assisted-by: Codex
- Build a tagged invoice from bundled JSON and CSV inputs.
- Compose the document with blank PDF, shapes, text, table, image,
  page-info, and resource endpoints.
- Use curl and jq to keep the workflow transparent and easy to adapt.

Assisted-by: Codex
…ling

Disable cookie management for the invoice workflow because the pdfRest
requests do not use cookies and some local runtimes cannot initialize their
cookie container correctly.

Assisted-by: Codex
…gs correctly

Send the single image insertion profile as an object, matching the
pdfRest endpoint contract used by the other language samples.

Assisted-by: Codex
- Use the deployed resource-ID image workflow in every language sample.
- Upload the bundled logo once, then reference it with image_id.
- Keep the invoice workflow compatible with the current public API while
  retaining the new shapes, tables, tagging, and pagination coverage.

Assisted-by: Codex
Run the repository Spotless formatter on the new invoice workflow so the
Java verification job passes with the project formatting rules.

Assisted-by: Codex
@datalogics-erics
datalogics-erics marked this pull request as ready for review August 14, 2026 14:33
@datalogics-erics datalogics-erics changed the title Add Python invoice generation complex flow sample Add invoice generation complex flow sample Aug 14, 2026
- Build table header cells with a valid jq filter.
- Generate footer entries for each page without iterating a number.

This keeps the cURL workflow aligned with the other language samples
and allows the complete invoice flow to run successfully.

Assisted-by: Codex
- Supply the delimiter, enclosure, and escape parameters to fgetcsv.
- Avoid PHP 8.5 deprecation warnings while reading invoice line items.

The sample continues to parse the same CSV format without runtime
warnings on current PHP versions.

Assisted-by: Codex
- Add thousands separators to generated currency amounts.
- Keep currency values consistently formatted with two decimal places.

This makes the cURL output match the presentation of the other
language samples.

Assisted-by: Codex

@datalogics-cgreen datalogics-cgreen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting these together. I think the overall structure is solid, but I am requesting changes for a few sample-quality issues before this lands.

  1. In the new .NET sample, the missing PDFREST_API_KEY branch prints an error and returns normally. That makes dotnet run -- create-invoice-from-structured-data exit 0 even though the sample did not run. The other .NET complex-flow samples call Environment.Exit(1); return; for the same precondition, so this one should match that behavior.

  2. Please add a short inline comment near each invoice-data directory constant/path explaining that these samples are intentionally self-contained and read bundled JSON, CSV, and logo fixture files. That should make the new sample shape clear without needing to document it as an exception in every README.

  3. Please add a few more inline comments describing the major API choreography, especially in the .NET and PHP samples. These are sample programs, and this workflow has enough steps that readers would benefit from signposts for: loading structured inputs, creating the blank PDF, adding header shapes/text, adding the auto-paginated table, uploading/reusing the logo resource ID, querying page count, adding final-page/footer content, and downloading the final PDF.

The runtime issue is small, but the readability points matter here because these files are teaching examples as much as runnable code.

- Exit the .NET sample with status 1 when the API key is missing.
- Explain that each language keeps its input fixtures beside the sample.
- Add API workflow signposts to the .NET and PHP implementations.

These changes make the samples easier to follow and ensure a missing
required credential is reported as a failed run.

Assisted-by: Codex
@datalogics-erics

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed all three points in commit 1701e79:

  1. The .NET sample now calls Environment.Exit(1) when PDFREST_API_KEY is missing, matching the other .NET complex-flow samples. I verified the missing-key run exits with status 1.

  2. Added a short comment beside the invoice-data path in each language implementation explaining that the JSON, CSV, and logo fixtures are intentionally bundled beside the sample.

  3. Added workflow signposts to the .NET and PHP samples covering input loading, blank PDF creation, header content, table insertion, logo upload and reuse, page-count lookup, footer content, and final download.

Validation completed:

  • Python compile check
  • JavaScript syntax check
  • PHP lint check
  • cURL shell syntax check
  • Java mvn verify with JDK 17
  • .NET missing-key exit-code check

@datalogics-cgreen datalogics-cgreen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the updates in 1701e79. The requested changes are addressed: the .NET missing-key path now exits non-zero, the fixture-path comments are present across the language samples, and the .NET/PHP samples now have useful workflow signposts for the major API steps.

Validation I reran locally:

  • dotnet build passes, with existing nullability warnings elsewhere in the project.
  • env -u PDFREST_API_KEY dotnet run --no-build -- create-invoice-from-structured-data now reports exit=1 after rebuilding.
  • Python compile, JavaScript syntax check, cURL shell syntax check, and Java Spotless check pass.

I could not rerun PHP lint locally because this machine does not have php installed, but the updated PHP comments/readability changes look correct on review.

EDIT: I fixed my local issue with php and manually ran the sample code to confirm that the expected output was received.

@datalogics-cgreen
datalogics-cgreen merged commit 8051e50 into pdfrest:main Aug 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants