Skip to content

WAIT: Embed multi-page handout PDFs inline with a page-count badge#1893

Draft
maebeale wants to merge 1 commit into
mainfrom
maebeale/prod-staging-resource-mismatch
Draft

WAIT: Embed multi-page handout PDFs inline with a page-count badge#1893
maebeale wants to merge 1 commit into
mainfrom
maebeale/prod-staging-resource-mismatch

Conversation

@maebeale

Copy link
Copy Markdown
Collaborator

🤖 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.

  • PdfPageCountAnalyzer records each PDF's page count in blob metadata (metadata["pages"]) via poppler's pdfinfo — runs automatically on attach, no per-request shelling.
  • Callout resource view embeds multi-page PDFs as a scrollable inline <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.
  • CI now installs poppler-utils (already a prod runtime dep via the PDF previewer) so PDF features are testable.
  • pdfs:backfill_page_counts rake task analyzes PDF blobs attached before the analyzer existed.

After merge/deploy, run rake pdfs:backfill_page_counts so existing handout PDFs get their page counts.

<%= render "assets/display_assets",
resource: resource, file: resource.display_image,
variant: :hero, link: true %>
<% if pages > 1 %>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Comment thread .github/workflows/ci.yml
# 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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>
@maebeale maebeale force-pushed the maebeale/prod-staging-resource-mismatch branch from c3d0955 to 10a0ae9 Compare June 23, 2026 15:27
<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>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

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