pdf actions new version#306
Conversation
There was a problem hiding this comment.
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.pyto parseFORMAT.md(## global+## pdf) into a resolved style dict and map it tocreate_pdf’s theme/render inputs. - Update
create_pdfto remove thethemeinput and instead resolve margins/header sizing/typography fromFORMAT.mdat render time;theme_usednow consistently returns"format_md". - Update
edit_pdfcopy and refactorfill_fieldpost-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.
| 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) |
| "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. " |
| 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) |
There was a problem hiding this comment.
I think this colour should also be from the mft
ahmad-ajmal
left a comment
There was a problem hiding this comment.
Just one small fix, please make sure to run ruff lint checks as well.
Summary
Fixes two outstanding issues from V1.3.2 and closes #296.
Changes
New:
app/utils/pdf_format.pyFORMAT.md → PDF style resolver shared by
create_pdfandedit_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 (#141517base,#FF4F18highlight,#6B6E76muted) if FORMAT.md is missing or malformed.Placed in
app/utils/rather thanapp/data/action/because the action loader scans all non-dunder.pyfiles 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_THEMESdict andthemeinput parameterapp.utils.pdf_formatheader_height_infrom FORMAT.md, floored at 30mm so title text always fitstheme_usedalways returns"format_md"(including in simulated mode)app/data/action/edit_pdf.pydefault=#4f46e5etc.) with the single FORMAT.md accent colour#FF4F18— the old themes were removed and the hints were actively misleading the modelfill_fielderror handling:field_namevalidation in the main loop so missing fields are caught immediatelyacroform_opsnow stores(original_index, op)tuples so each warning references the correctop[N]tagapp/utils/__init__.pyNo changes —
pdf_formatis 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_pdfandedit_pdfproduce PDFs whose colours, fonts, headings, margins, and footer match FORMAT.md's## global/## pdfsections_THEMESdict removedtest_payload/ simulated mode still passesOut of scope (not touched)
read_pdf.py— no changesdocx,pptx,xlsx)