Skip to content

feat: render an inline PDF viewer for .pdf links in chat#494

Open
X-15 wants to merge 1 commit into
cogwheel0:mainfrom
X-15:feat/inline-pdf-viewer
Open

feat: render an inline PDF viewer for .pdf links in chat#494
X-15 wants to merge 1 commit into
cogwheel0:mainfrom
X-15:feat/inline-pdf-viewer

Conversation

@X-15

@X-15 X-15 commented Jun 4, 2026

Copy link
Copy Markdown

What

Renders an inline PDF viewer when an assistant message contains a link to a PDF (a URL ending in .pdf). Instead of a plain hyperlink, the message shows a preview card:

  • Preview — the first page is rendered into the card.
  • Tap → fullscreen — a scrollable viewer with native momentum scrolling.
  • Share — from the card or the viewer, via the OS share sheet.

This is a general "Conduit can display PDFs sent in a conversation" capability; it keys purely off the .pdf link, so it works with any backend that returns/links PDFs.

How

  • Adds pdfrx (PDFium) for rendering.
  • No white flash: pages are pre-rasterized to images. pdfrx's live viewer paints a blank white rectangle until the async render lands, which is very visible in a debug build.
  • Memory-bounded: the fullscreen viewer renders pages lazily around the viewport and holds them under a hard 64 MB LRU budget — small docs stay fully resident (flicker-free); large docs stay bounded regardless of page count.
  • Caching: downloaded once into a dedicated, bounded flutter_cache_manager instance; the card pre-renders page 1 to a held image; both card and viewer open from the local file.
  • Share: copies the cached file to a uniquely-named temp file (Android doesn't reliably honor share_plus fileNameOverrides) so the receiver sees a meaningful name, then sweeps old temp dirs.
  • Basic resilience: retry on load failure, per-page error fallback, Semantics labels.

Notes

  • New dependency: pdfrx (flutter_cache_manager / path_provider / share_plus were already present), reflected in pubspec.yaml / pubspec.lock.
  • User-facing strings are hardcoded English as a starting point — happy to move them to AppLocalizations if preferred.
  • Verified on Android (Samsung S23, arm64).

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "feat: render an inline PDF viewer for .p..." | Re-trigger Greptile

Comment thread lib/shared/widgets/markdown/renderer/pdf_inline_view.dart
Comment thread lib/shared/widgets/markdown/renderer/pdf_inline_view.dart
Comment thread lib/shared/widgets/markdown/renderer/pdf_inline_view.dart
Comment thread lib/shared/widgets/markdown/renderer/pdf_inline_view.dart Outdated
@X-15 X-15 force-pushed the feat/inline-pdf-viewer branch 2 times, most recently from e5e4311 to 047a561 Compare June 4, 2026 09:32
When an assistant message contains a link to a PDF (a URL ending in .pdf),
render it inline as a preview card instead of a plain hyperlink: tap to
open a fullscreen, scrollable viewer; share the file from the card or the
viewer. It keys purely off the .pdf link, so it works with any backend
that links PDFs.

Implementation notes:

- Adds pdfrx (PDFium) for rendering.
- Pages are pre-rasterized to images so scrolling never flashes a blank
  white page (pdfrx's live viewer rasterizes lazily on paint, which is
  very visible in a debug build). The fullscreen viewer renders pages
  lazily around the viewport and holds them under a hard 64 MB LRU budget,
  so a large document cannot blow up memory while small documents stay
  fully resident and flicker-free.
- The PDF is downloaded once into a dedicated, bounded cache and opened
  from the local file; the card pre-renders page 1 to a held image.
- Share copies the cached file to a uniquely-named temp file (Android does
  not reliably honor share_plus fileNameOverrides) and sweeps old temp
  files so they do not accumulate.
- Basic resilience: retry on load failure, per-page error fallback,
  Semantics labels.

User-facing strings are hardcoded English as a starting point and could be
moved to AppLocalizations. Verified on Android (Samsung S23, arm64).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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