Skip to content

🖼️ fix: Show EMF/WMF Pictures in PowerPoint Previews - #85

Closed
TomasPalsson wants to merge 1 commit into
sync/v0.8.8-rc4from
fix/pptx-preview-emf-images
Closed

TomasPalsson wants to merge 1 commit into
sync/v0.8.8-rc4from
fix/pptx-preview-emf-images

Conversation

@TomasPalsson

Copy link
Copy Markdown

Problem

PowerPoint templates often store logos as EMF/WMF (Windows metafiles). pptx-preview turns them into data:image/x-emf URIs, which no browser can decode, so the logos render as broken images in the artifact preview. Seen with a customer template where 8 of 11 media files are EMF logos in the slide layouts.

Fix

  • Server: extractPptxMetafileSvgs (new packages/api/src/files/documents/metafiles.ts) converts ppt/media/image*.emf|wmf to SVG with emf-converter (pinned 4.8.7, Apache-2.0, zero deps), keyed by an FNV-1a hash of the entry's base64. That is exactly what pptx-preview puts in img.src.

  • html.ts: the map is embedded as <script id="lc-metafiles" type="application/json">, with < escaped. After the slides render, the iframe swaps matching <img> sources for the SVG data URIs. The swap is wrapped in try/catch and can never trigger the fallback.

  • Budgets:

    • at most 64 metafiles
    • 5 MB per file
    • 8 MB of input in total
    • 3 s of conversion time
    • 256 KB per SVG, 384 KB of SVG in total

    If the map would push a deck over OFFICE_HTML_OUTPUT_CAP, the deck is retried without the map, so no deck that previews today regresses to the slide list.

  • The CSP is unchanged (img-src already allows data:). The DOCX path is untouched.

Verification

  • cd packages/api && npx jest src/files/documents src/files/code: 18 suites, 536 tests passing, 9 of them new.
  • tsc, eslint and prettier are clean on the touched files.
  • Checked in a browser with Playwright against the real customer template, via the storage-backed shell path: before, 3 broken <img>; after, 3 loaded SVG logos.

Not covered

  • EMF used as a CSS background or fill. Only <img> is swapped.
  • EMF+ records that need @napi-rs/canvas. These are skipped, not broken.
  • DOCX.

pptx-preview turns EMF/WMF media into data:image/x-emf URIs, which no
browser can decode, so template logos stored as metafiles render as
broken images. Convert them to SVG on the server with emf-converter
(pinned 4.8.7, Apache-2.0, no deps), embed the SVGs keyed by a hash of
the media's base64, and swap them into the rendered <img> elements once
the slides are drawn.

Bounded by count, per-file, total-input, output and time budgets; a
deck whose preview fits today never loses it to the added map.
@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@TomasPalsson

Copy link
Copy Markdown
Author

Superseded by LibreChat-AI#16672, which is now the source of this change. The squashed commit from that PR is cherry-picked onto sync/v0.8.8-rc4 directly.

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