Skip to content

Custom PDF layout (replace MPMB template)#80

Merged
igor47 merged 1 commit into
mainfrom
custom-pdf-layout
May 26, 2026
Merged

Custom PDF layout (replace MPMB template)#80
igor47 merged 1 commit into
mainfrom
custom-pdf-layout

Conversation

@igor47

@igor47 igor47 commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces src/services/characterPdf.ts (MPMB template fill) with a self-contained pdf-lib renderer. We can't redistribute MPMB's sheets, so we own the layout end-to-end.
  • Layout inspired by the WotC 2024 character sheet: top identity strip with stat tiles, vertical ability column on the left with notched tabs and explicit save row, sectioned right column for Weapons / Skills / Spellcasting / Features / Equipment.
  • generateCharacterPdf(char, playerName?) and generateCampaignPdf(entries) keep the same signatures — no route changes needed.

What it looks like

Page 1 (always):

  • Top strip: Identity block (name + background/class/species/subclass/alignment/size/player labeled lines), a 2×2 stats grid (Initiative / Speed / Passive Perception / Prof Bonus), and AC / HP (cur/max + temp write-in) / Hit Dice (per-die tiles, X'd if used).
  • Left column: Six vertical ability cards. Each has a notched-tab label, the modifier as a big number with a score chip below, a horizontal divider, and a centered save row (filled disc = proficient).
  • Right column: Weapons (wielded items only, write-in line for Atk bonus), Skills (single list, alphabetical, with ability tag), Spellcasting (per-class DC / Atk / Ability + slot tiles with X for used), Features & Traits (names only, 2 columns), Equipment (names + tags, 2 columns, coins line at bottom).

Page 2+ (only if needed): Wild Shape block for druids; per-class spells with cantrip / prepared / spellbook sections.

Tests

characterPdf.test.ts rewritten at the behavior level: PDF parses, page count in range, drawn text appears in decoded content streams. The helper inflates each `PDFRawStream` and decodes PDF hex string literals (`<54657374> Tj`) so ASCII text matches work.

MPMB assets

`assets/mpmb/*.pdf` is no longer referenced by any code path. Left on disk for the separate history-rewrite task.

Test plan

  • `mise run check` passes (Biome + tsc)
  • `mise run test` passes (689/689)
  • Open the PDF route on a real character and confirm the new layout renders without obvious overlap or clipping
  • Generate a campaign PDF with 3+ characters and confirm pages concatenate cleanly

Replaces the MPMB template-fill PDF generator with a self-contained
pdf-lib renderer. Layout is inspired by the 2024 WotC sheet (top
identity strip with stat tiles, vertical ability column on the left
with notched tabs and explicit save row, sectioned right column for
Weapons / Skills / Spellcasting / Features / Equipment).

Public API is unchanged: generateCharacterPdf(char, playerName?) and
generateCampaignPdf(entries) keep the same signatures, so the
/characters/:id/pdf and /campaigns/.../pdf routes need no changes.

Tests in characterPdf.test.ts are rewritten at the behavior level —
they assert that the PDF parses, has the expected page count, and
contains the expected drawn text (via a helper that inflates each
PDFRawStream and decodes the hex string literals).

The assets/mpmb/*.pdf template files are no longer referenced by
any code path but are left on disk for a separate history-rewrite
task to remove.

utils/sample-character-pdf.ts is a small dev helper that renders
the first non-archived character in the dev DB to /tmp/csheet-sample.pdf
for visual iteration on the layout.
@igor47 igor47 merged commit 0ef8187 into main May 26, 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.

1 participant