Export Chat as PDF — Design Document

Overview

Writers want a portable, readable copy of a conversation they can keep, share, or print — a finished artifact, not a machine-readable data dump. We already ship a JSON export (GET /api/conversations/{uuid}/export) for the full, round-trippable record of a conversation; this feature adds a PDF export aimed at the opposite need: a clean, human-facing document of the story.

PDF export is a convenience, not access — the underlying conversation is always the user's to read in-app and to export as JSON for free. The PDF is the polished, paginated, themed rendering of it. Per the platform's monetization ethic (charge for convenience, never for access — see project_monetization_ethic_access_free_convenience_paid), it is a Pro / Premium feature. The entry point is always visible to everyone (with a Pro badge); non-subscribers are routed to upgrade rather than having the door hidden from them.

Design Goals

Non-Goals

Deliberately out of scope for v1:

The data path (backend)

A new Pro/Premium-gated endpoint returns a prompt-free projection of the conversation, assembled from the same repositories the JSON export uses — but through a separate DTO so prompt/IP fields cannot leak in:

GET /api/conversations/{uuid}/export/pdf-data    (RequireAuthorization; 403 if not Pro/Premium)
  → ConversationPdfData (declared-type WriteAsJsonAsync<T> + Results.Empty — STJ trap)

ConversationPdfData (new record, NOT ConversationExportData):

Explicitly excluded: CustomInstructions, ActiveTrackersJson, character personality/scenario/ system-prompt fields. These are never selected into the projection.

Reuse via extraction (refactor-first). The existing ExportConversation handler assembles conversation metadata + keyset-paged messages + summaries inline. With a second consumer now in scope, the message/summary assembly is lifted into a shared helper both routes call (rule-of-two — feedback_refactor_before_feature_delivery); the PDF route adds the journal read and maps to the prompt-free DTO. The Pro-tier check is the shared SubscriptionGate.IsProOrAboveAsync (creator analytics used it too until 2026-09-30, when Creator insights became a feature bought with Echoes).

Size bound. The PDF route returns a single JSON payload (no zip/multi-part). Above the message cap it returns a structured 409/413-style response the modal renders as "this conversation is too long to export as PDF — use JSON export." (Exact cap: Open Questions.)

The selection modal (frontend)

Opened from the chat header <Dropdown> — a new "Export as PDF" item directly after "Export as JSON", always visible, with a Pro badge. Non-Pro click routes to the upgrade/pricing path; Pro/ Premium click opens the scope modal.

Scope toggles (defaults shown):

Toggle Default Notes
Conversation header ☑ Character / mode / persona / greeting names, dates. Labels only.
Description ☑ (if set) Character public description; row hidden if unset.
Transcript ☑ (locked) The point of the export; cannot be unchecked.
Timestamps ☑ Per-message created-at.
Per-message model name ☐ The model string.
Per-message info ☐ Token/char counts, edited flag, version number.
Inline images ☑ g:// gallery refs resolved + embedded.
Tracker state ☐ Per-assistant-message tracker snapshot.
Story beats ☐ Hidden entirely unless the conversation has Hybrid beats.
Appendix — Summaries / Memories ☐ Rendered after the transcript.
Appendix — Journal ☐ journal_entries, rendered after the transcript.

Theme (radio):

On confirm: fetch /export/pdf-data, build the @react-pdf/renderer document filtered to the selected scope + theme, produce a Blob, and download it (reuse the existing blob-download approach; filename from the conversation title).

The PDF document (frontend, @react-pdf/renderer)

A purpose-built document — title/header block, then the transcript (user/assistant turns styled distinctly), then optional appendix sections. Real pagination + page numbers + footer.

A focused markdown → react-pdf mapping renders message content: paragraphs, bold/italic, headings, unordered/ordered lists, inline code + code blocks, blockquotes, and images (g:// resolved via the existing resolveGalleryImageSrc, embedded as <Image>). This is the one genuinely new rendering surface — ChatMarkdown (ReactMarkdown) can't be reused because react-pdf needs PDF primitives, not DOM. The markdown subset is scoped to what ChatMarkdown actually renders.

Typography. react-pdf needs a static font file per weight and style (TTF or WOFF, not woff2). The EOD brand faces — Quicksand (headings/UI) and Raleway (body) — are registered for every theme, so the document renders in real EOD type rather than a generic built-in face. The Current theme choice additionally applies the user's selected chat font (the chat-font catalog is a bounded set, every one of them included); an unknown font falls back to Raleway, and a font with no italic sets italic text upright. The font files are served from Echo of Dreams' own site, like every other font we use: making a PDF never sends a request to a third-party font service. They cover the full character set, so Czech (and Cyrillic, Vietnamese …) text renders in the PDF. Fonts are fetched at generate time, only the ones the document uses — a fetch failure surfaces as a clear error, not a hang.

Implementation Plan (Sliced)

  1. ✅ Backend data endpoint — ConversationPdfData DTO, extract shared assembly from ExportConversation, Pro-gate, journal read, size cap. Tests.
  2. ✅ Dependency + PDF document — add @react-pdf/renderer to clientConsole; build the document component + markdown→pdf mapping + theme application.
  3. ✅ Scope modal + wiring — modal (shared Modal), dropdown item with Pro badge, non-Pro upgrade route, fetch→generate→download.
  4. 📋 UX/UI pass + review — drive each use case in the preview across all three themes; DoD gate.

Open Questions

All three were settled by shipping; the owner confirmed the feature as implemented (2026-10-28):

Acceptance Criteria

The feature is not done until every box below is verified ✅ against the running product.

User use cases — satisfiable + accessible (verify by driving the UI, not the code):

Behavior:

Invariants that must stay true (carve-outs):

Edges: