WAIT: Embed multi-page handout PDFs inline with a page-count badge#1893
WAIT: Embed multi-page handout PDFs inline with a page-count badge#1893maebeale wants to merge 1 commit into
Conversation
| <%= render "assets/display_assets", | ||
| resource: resource, file: resource.display_image, | ||
| variant: :hero, link: true %> | ||
| <% if pages > 1 %> |
There was a problem hiding this comment.
🤖 From Claude: Inline embed is gated on pages > 1: single-page PDFs keep the crisp first-page image, and if page count is unknown (poppler missing or not yet analyzed) we fall back to the image rather than embedding. The display_assets render inside <object> is the fallback for browsers that won't render inline PDFs (notably mobile Safari/Chrome).
| # when poppler isn't installed. | ||
| class PdfPageCountAnalyzer < ActiveStorage::Analyzer | ||
| class << self | ||
| def accept?(blob) |
There was a problem hiding this comment.
🤖 From Claude: accept? returns false when pdfinfo is absent, so the analyzer is a no-op (no pages metadata) rather than raising — the view then degrades to the first-page preview. Mirrors how HighResPopplerPdfPreviewer guards on pdftoppm.
| # poppler-utils provides pdftoppm/pdfinfo, used by the PDF previewer and the | ||
| # PDF page-count analyzer (mirrors the production runtime dependency). | ||
| - name: Install poppler-utils | ||
| run: sudo apt-get update && sudo apt-get install -y poppler-utils |
There was a problem hiding this comment.
🤖 From Claude: poppler is already a prod runtime dependency (the PDF previewer shells out to pdftoppm); installing it here lets the new PDF specs actually run instead of self-skipping.
Callout resource pages only showed a PDF's first page, so multi-page training handouts looked like one-pagers. Record each PDF's page count in blob metadata via a poppler analyzer, then embed multi-page PDFs as a scrollable inline viewer and show an "N pages" badge by the download button. Single-page PDFs keep the lightweight first-page preview. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c3d0955 to
10a0ae9
Compare
| <i class="fa-regular fa-copy"></i> <%= pages %> pages | ||
| </span> | ||
| <% elsif !resource.single_page_pdf? %> | ||
| <span class="text-xs text-gray-500">The preview shows the first page only — download to get all pages.</span> |
There was a problem hiding this comment.
🤖 From Claude: Rebase conflict with #1892 resolved here: the badge + inline embed key off the real metadata["pages"] (the introspection #1892's single_page_pdf? comment anticipated), while single_page_pdf? is kept as the pre-backfill fallback — before pdfs:backfill_page_counts runs, a recognized multi-page PDF still shows the "download for all pages" prompt instead of silently looking single-page.
🤖 PR, suggested 👤 review level: 📖 Read — light-logic: a new ActiveStorage analyzer + a view branch, plus a CI dependency and a backfill task
Callout resource pages rendered only a PDF's first page, so multi-page training handouts looked like one-pagers.
PdfPageCountAnalyzerrecords each PDF's page count in blob metadata (metadata["pages"]) via poppler'spdfinfo— runs automatically on attach, no per-request shelling.<object>viewer (falling back to the first-page preview where inline PDFs aren't supported, e.g. some mobile browsers) and shows an "N pages" badge by the download button. Single-page PDFs keep the lightweight first-page image.poppler-utils(already a prod runtime dep via the PDF previewer) so PDF features are testable.pdfs:backfill_page_countsrake task analyzes PDF blobs attached before the analyzer existed.After merge/deploy, run
rake pdfs:backfill_page_countsso existing handout PDFs get their page counts.