Skip to content

IN-PROGRESS: Show PDF resources in the browser's inline viewer#1893

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

IN-PROGRESS: Show PDF resources in the browser's inline viewer#1893
maebeale wants to merge 1 commit into
mainfrom
maebeale/prod-staging-resource-mismatch

Conversation

@maebeale

@maebeale maebeale commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

🤖 PR, suggested 👤 review level: 📖 Read — light-logic: a shared view partial branching on PDF vs. not, plus removal of the earlier page-count machinery

Callout resource pages and the resource detail page previewed only a PDF's first page as an image, so multi-page handouts looked like one-pagers.

  • PDFs now render in the browser's built-in inline viewer (scrollable, all pages — every major browser ships one), falling back to the first-page/image preview for the rare client that can't.
  • Non-PDF resources keep the existing preview.
  • Extracted the PDF-or-preview choice into assets/_resource_display, shared by the callout resource viewer and the resource show page.

Per review feedback, dropped the page-counting approach entirely (the PdfPageCountAnalyzer + metadata["pages"] badge, the poppler-utils CI step, the pdfs:backfill_page_counts task, and the hardcoded single_page_pdf?) — the browser viewer shows every page, so none of it is needed. No backfill or deploy step required now.

<%= 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 Outdated
# 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.

@maebeale maebeale force-pushed the maebeale/prod-staging-resource-mismatch branch from c3d0955 to 10a0ae9 Compare June 23, 2026 15:27
@maebeale maebeale changed the title WAIT: Embed multi-page handout PDFs inline with a page-count badge HOLD: Embed multi-page handout PDFs inline with a page-count badge Jun 28, 2026
@jmilljr24

jmilljr24 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

I see the pdf viewer for multi page is just using the built in browser feature. That's a good thing since all major browsers support it.

In that case, my vote would be to completely remove the code around counting the number of pages. If PDF use browser pdf view, else use preview. Keeps it simple and even for single page pdf's it becomes obvious the file is actually a PDF not just an image.

This would work well on the Resource show as well.

@maebeale maebeale changed the title HOLD: Embed multi-page handout PDFs inline with a page-count badge IN-PROGRESS: Embed multi-page handout PDFs inline with a page-count badge Jul 4, 2026
Callout resource pages and the resource detail page previewed only a
PDF's first page as an image, so multi-page handouts looked like
one-pagers. Render PDFs in the browser's built-in inline viewer instead
(scrollable, all pages — every major browser ships one), falling back to
the first-page/image preview for the rare client that can't. Non-PDF
resources keep the existing preview. Extracted the PDF-or-preview choice
into assets/_resource_display so the callout viewer and resource show
page share it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 4, 2026 14:45
@maebeale maebeale force-pushed the maebeale/prod-staging-resource-mismatch branch from 10a0ae9 to 0aa0cb6 Compare July 4, 2026 14:45
@maebeale maebeale changed the title IN-PROGRESS: Embed multi-page handout PDFs inline with a page-count badge IN-PROGRESS: Show PDF resources in the browser's inline viewer Jul 4, 2026
can't. Anything else (images, etc.) renders through the shared asset
pipeline. `resource` is a decorated Resource. %>
<% display = resource.display_image %>
<% if display.respond_to?(:attached?) && display.attached? && display.content_type == "application/pdf" %>

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: The PDF check keys off display_image (the resolved hero: primary_asset → downloadable_asset → …), not the downloadable file directly — so a resource with a primary image and a downloadable PDF still shows its image here, and only resources whose hero actually is a PDF get the inline viewer. respond_to?(:attached?) guards against the symbol/string defaults display_image can return.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates resource/callout rendering so PDFs can be displayed inline via the browser’s built-in PDF viewer (instead of only showing a first-page preview), and removes the prior hardcoded “single-page PDF titles” logic. It also adjusts request specs around callouts and bumps the checkout Action version in CI.

Changes:

  • Add a shared assets/_resource_display partial that renders PDFs via an inline <object> viewer and falls back to the existing asset pipeline for non-PDFs.
  • Remove Resource#single_page_pdf? and its associated specs / “download for all pages” prompt in registration resource specs.
  • Update callout request specs to assert PDF vs non-PDF rendering, and bump actions/checkout in CI.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/requests/events/registrations_spec.rb Removes expectations about the “download for all pages” prompt on multi-page resources.
spec/requests/events/registration_ticket_callouts_spec.rb Adds coverage asserting inline-PDF rendering for PDF resources and no inline-PDF markup for non-PDF resources.
spec/models/resource_spec.rb Removes tests for the deleted #single_page_pdf? behavior.
app/views/resources/show.html.erb Switches the hero asset rendering to the shared assets/resource_display partial.
app/views/events/callouts/_resource_body.html.erb Removes the “download for all pages” prompt and uses the shared assets/resource_display partial.
app/views/assets/_resource_display.html.erb New partial that renders PDFs inline via <object> and uses the existing display_assets pipeline otherwise.
app/models/resource.rb Deletes the hardcoded single-page title list and #single_page_pdf?.
AGENTS.md Updates/extends architecture reference entries (counts/models/concerns).
.github/workflows/ci.yml Bumps actions/checkout major version in the CI workflow.

Comment on lines +6 to +7
<% display = resource.display_image %>
<% if display.respond_to?(:attached?) && display.attached? && display.content_type == "application/pdf" %>
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.

3 participants