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
- A finished reading artifact, not a data dump. Real pagination, page numbers, a title page/header, selectable vector text, the story rendered the way the reader saw it (markdown, inline images).
- The PDF is shareable; it must never leak creator IP or prompts. This is load-bearing. The JSON
export carries
CustomInstructionsandActiveTrackersJson(prompt/IP content) because it is the user's private data dump. The PDF is something a user hands to someone else — so the PDF data path emits a prompt-free projection: header labels (character/mode/persona/greeting names) only, never the personality/scenario/system-prompt bodies, never custom instructions, never the tracker definition prompts. - User controls the scope. A selection modal lets the user choose exactly what the document contains before it is generated.
- Reuse the substrate. The data already loads via the conversation read path; gallery images
already resolve client-side; the chat header already hosts an "Export as JSON" item; the download
plumbing (
downloadExport) already exists. Build on these, don't reinvent. - Gate enforced server-side. A client-only Pro check is trivially bypassed. The data endpoint that feeds the PDF is gated on tier; the UI gate is a courtesy on top.
Non-Goals
Deliberately out of scope for v1:
- Server-side PDF rendering. Rendering happens client-side with
@react-pdf/renderer, reusing the data the client already holds. No headless browser, no C# PDF library, no re-implementing markdown / gallery resolution / theming in the backend. - Exporting prompts, custom instructions, or tracker/character prompt bodies. Never. See design goals — this is a hard line, not a default.
- Arbitrarily large conversations. Client-side rendering bounds memory. Conversations beyond a message cap (see Open Questions) fall back to "use JSON export" with a clear message; multi-part PDF assembly is not in v1.
- Date-range / message-range selection. v1 exports the whole conversation. Range selection is a later addition if asked for.
- A new persisted artifact. The PDF is generated on demand and downloaded; nothing is stored server-side.
- System-message export.
web_messagesallowsrole=2but no write path ever persists one (the system prompt is assembled per-request, never stored). There is nothing to export, so the toggle does not exist.
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):
- Header (labels only):
Title,CharacterName,ModeName,PersonaName,GreetingName,CharacterDescription(the character's public description blurb — never prompt fields; null if unset),CreatedAt,UpdatedAt,MessageCount. - Messages:
Role(user/assistant),Content(markdown, withg://gallery refs left raw — resolved client-side),Model,TrackerJson,BeatJson,SynthesisKind,CreatedAt,UpdatedAt(edited indicator),VersionNumber,TokenCountApprox,CharacterCount. - Appendix:
Summaries(level, content, period start/end, tracker timeline — the same reader-facing shape the JSON export uses, minus nothing sensitive),JournalEntries(content, category, source — fromjournal_entries).
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):
- Light document — EOD default light palette (default selection; best for print).
- Dark document — EOD default dark palette.
- Current user theme — the live theme tokens/fonts the console already holds in memory.
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)
- ✅ Backend data endpoint —
ConversationPdfDataDTO, extract shared assembly fromExportConversation, Pro-gate, journal read, size cap. Tests. - ✅ Dependency + PDF document — add
@react-pdf/renderertoclientConsole; build the document component + markdown→pdf mapping + theme application. - ✅ Scope modal + wiring — modal (shared
Modal), dropdown item with Pro badge, non-Pro upgrade route, fetch→generate→download. - 📋 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):
- Message cap for PDF export: 1,500 selected-version messages (
PdfExportMaxMessages,ConversationsEndpoints.cs:4523). - "Description" semantics: the character's public description blurb, never prompt fields.
- Non-Pro entry point: routes to /pricing (
ExportPdfModal.tsx:6).
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):
- As a Pro/Premium user, I can open "Export as PDF" from the chat header dropdown, choose a scope, and download a readable PDF of my conversation — without insider knowledge.
- As a free user, I can see the "Export as PDF" item (with a Pro badge) and clicking it routes me to the upgrade path — I am never silently blocked with no explanation.
- As any subscriber, I can pick Light / Dark / Current-theme and the downloaded PDF reflects that choice — including EOD brand typography (Quicksand/Raleway), and my own chat font under Current.
- As any subscriber, I can toggle each scope option and the resulting PDF includes/excludes exactly those sections.
Behavior:
-
GET /api/conversations/{uuid}/export/pdf-datareturns the prompt-free projection for the owner; returns403for a non-Pro/Premium caller;404for a non-existent/foreign conversation. - The transcript renders markdown (bold/italic/headings/lists/code/blockquote) and embeds inline
g://gallery images. - Story beats toggle is present only when the conversation actually has Hybrid beats.
- Summaries and Journal appendices render after the transcript when selected.
- The generated PDF has multi-page pagination with page numbers.
Invariants that must stay true (carve-outs):
- The PDF data endpoint never emits
CustomInstructions,ActiveTrackersJson, or any character personality/scenario/system-prompt field — verified by inspecting the response payload for a character whose prompts are non-empty. - The free JSON export path is unchanged — still ungated, still round-trippable, still includes the user's own full data.
- The "Transcript" toggle cannot be unchecked (a PDF always contains the conversation).
- The "System messages" toggle does not exist (no system messages are ever stored).
Edges:
- A conversation above the message cap returns a clear "too long — use JSON export" message, not a hung browser or a truncated PDF.
- An empty conversation (greeting only) produces a valid one-page PDF, not an error.
- A non-Pro user who manually hits the endpoint gets
403, not data. - A conversation with no character description / no journal / no summaries renders cleanly with those sections simply absent.