Skip to content

Previewing PDF attachments in index tables #585

@hasarindaKI

Description

@hasarindaKI
  • If an attachment is representable? we render the attachment as an image tag
  • representable? can be true for the following types if their related tools are installed on the system
    • PDF
      • If the system has poppler installed -> PopplerPDFPreviewer or
      • If the system has muPDF installed -> MuPDFPreviewer
    • Video
      • If the system has ffmpeg installed -> VideoPreviewer
  • If either poppler or muPDF is installed(Or even for video), we need to create the image_tag as given below..
blob.preview(resize_to_limit: [100, 100])

For more details => https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Preview.html & https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Blob/Representable.html

Proposed change

if value.try(:representable?)
    if value.try(:variable?)
        image_tag( @variant.nil? ? value : value.variant(@variant))
    else
        image_tag(value.blob.preview(resize_to_limit: [100, 100]))
    end
elsif value.try(:attached?)
    link_to value.blob.filename, rails_blob_path(value, disposition: :attachment)
else
    ""
end

Example using Hunter & Co. app

Screenshot 2024-03-07 at 5 19 40 pm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions