Skip to content

pdf actions new version#306

Open
AlanAAG wants to merge 2 commits into
V1.3.3from
fix/generalise-styling-FORMAT-pdf-actions
Open

pdf actions new version#306
AlanAAG wants to merge 2 commits into
V1.3.3from
fix/generalise-styling-FORMAT-pdf-actions

Conversation

@AlanAAG
Copy link
Copy Markdown
Collaborator

@AlanAAG AlanAAG commented Jun 2, 2026

Summary

Fixes two outstanding issues from V1.3.2 and closes #296.


Changes

New: app/utils/pdf_format.py

FORMAT.md → PDF style resolver shared by create_pdf and edit_pdf. Parses the ## global (colours, typography) and ## pdf (margins, header height) sections and maps them onto the fpdf2 render pipeline. Falls back to hardcoded CraftBot-brand defaults (#141517 base, #FF4F18 highlight, #6B6E76 muted) if FORMAT.md is missing or malformed.

Placed in app/utils/ rather than app/data/action/ because the action loader scans all non-dunder .py files in the action directory — placing a shared utility there causes a module name collision and import failure at runtime.

app/data/action/create_pdf.py

  • Removes hardcoded _THEMES dict and theme input parameter
  • Styling now derived from FORMAT.md at render time via app.utils.pdf_format
  • Colours, typography sizes, margins, and footer all respond to FORMAT.md changes with no code change required
  • Banner height scales with header_height_in from FORMAT.md, floored at 30mm so title text always fits
  • theme_used always returns "format_md" (including in simulated mode)

app/data/action/edit_pdf.py

  • Updates description: replaces stale multi-theme colour hints (default=#4f46e5 etc.) with the single FORMAT.md accent colour #FF4F18 — the old themes were removed and the hints were actively misleading the model
  • Applies PR Upgrade create_pdf action with themes, visual layout, and unicode safety #286 fix for fill_field error handling:
    • Upfront field_name validation in the main loop so missing fields are caught immediately
    • Post-processing block split into three isolated failure modes: PDF open failure warns all ops individually, per-field try/except so one bad field doesn't block others, disk write failure as its own distinct warning
    • acroform_ops now stores (original_index, op) tuples so each warning references the correct op[N] tag

app/utils/__init__.py

No changes — pdf_format is imported directly in the actions and does not need to be re-exported here. The existing I/O-free contract of this module is preserved.


Acceptance criteria (issue #296)

  • create_pdf and edit_pdf produce PDFs whose colours, fonts, headings, margins, and footer match FORMAT.md's ## global / ## pdf sections
  • Editing FORMAT.md (e.g. changing the highlight colour) visibly changes subsequent PDF output with no code change
  • Hardcoded _THEMES dict removed
  • Missing or malformed FORMAT.md still renders a valid PDF via defaults
  • Existing test_payload / simulated mode still passes

Out of scope (not touched)

  • read_pdf.py — no changes
  • Non-PDF actions (docx, pptx, xlsx)
  • FORMAT.md schema or format
  • Full Roboto font embedding

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors PDF styling so create_pdf can derive colours/typography/margins from agent_file_system/FORMAT.md (with CraftBot defaults as fallback), and improves edit_pdf’s fill_field (AcroForm) error isolation and warning attribution. It also removes the previously hardcoded multi-theme system from create_pdf and updates action descriptions to reduce model confusion.

Changes:

  • Add app/utils/pdf_format.py to parse FORMAT.md (## global + ## pdf) into a resolved style dict and map it to create_pdf’s theme/render inputs.
  • Update create_pdf to remove the theme input and instead resolve margins/header sizing/typography from FORMAT.md at render time; theme_used now consistently returns "format_md".
  • Update edit_pdf copy and refactor fill_field post-processing to validate upfront and isolate failures per operation and per stage (open/apply/write).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
app/utils/pdf_format.py New FORMAT.md parser + theme mapper used by PDF actions.
app/data/action/create_pdf.py Removes _THEMES/theme input; resolves styling from FORMAT.md; adjusts schema/simulated output.
app/data/action/edit_pdf.py Updates action description and improves fill_field error handling/warnings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/data/action/create_pdf.py Outdated
pdf.set_font("Helvetica", "B", 20)
pdf.set_font("Helvetica", "B", _fmt["h1_pt"])
pdf.set_text_color(*t["htxt"])
title_y = y0 + (HH - 20) / 2 - (5 if subtitle else 0)
Comment thread app/data/action/edit_pdf.py Outdated
Comment on lines +17 to +19
"When editing a PDF created by create_pdf, the accent colour is always #FF4F18 "
"(FORMAT.md highlight). Use this for stamps, watermarks, and annotations "
"to match the document style. "
Comment on lines 268 to 274
pdf.rect(lm, y0, pw, HH, style="F")

if doc_title:
pdf.set_font("Helvetica", "B", 20)
pdf.set_font("Helvetica", "B", _fmt["h1_pt"])
pdf.set_text_color(*t["htxt"])
title_y = y0 + (HH - 20) / 2 - (5 if subtitle else 0)
pdf.set_xy(lm + 8, title_y)

if subtitle:
pdf.set_font("Helvetica", "I", 9)
pdf.set_text_color(200, 210, 240)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this colour should also be from the mft

Copy link
Copy Markdown
Collaborator

@ahmad-ajmal ahmad-ajmal left a comment

Choose a reason for hiding this comment

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

Just one small fix, please make sure to run ruff lint checks as well.

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.

3 participants