diff --git a/activestorage/lib/active_storage/previewer/mupdf_previewer.rb b/activestorage/lib/active_storage/previewer/mupdf_previewer.rb index f1f9aa85be200..a5bd3537549db 100644 --- a/activestorage/lib/active_storage/previewer/mupdf_previewer.rb +++ b/activestorage/lib/active_storage/previewer/mupdf_previewer.rb @@ -4,7 +4,11 @@ module ActiveStorage class Previewer::MuPDFPreviewer < Previewer class << self def accept?(blob) - blob.content_type == "application/pdf" && mutool_exists? + pdf?(blob.content_type) && mutool_exists? + end + + def pdf?(content_type) + Marcel::Magic.child? content_type, "application/pdf" end def mutool_path diff --git a/activestorage/test/previewer/mupdf_previewer_test.rb b/activestorage/test/previewer/mupdf_previewer_test.rb index 40b864c622e23..a15bdccee147e 100644 --- a/activestorage/test/previewer/mupdf_previewer_test.rb +++ b/activestorage/test/previewer/mupdf_previewer_test.rb @@ -32,6 +32,19 @@ class ActiveStorage::Previewer::MuPDFPreviewerTest < ActiveSupport::TestCase end end + test "previewing an Illustrator document that's a PDF subtype" do + blob = create_file_blob(fixture: "report.pdf", filename: "file.ai", content_type: "application/illustrator") + + ActiveStorage::Previewer::MuPDFPreviewer.new(blob).preview do |attachable| + assert_equal "image/png", attachable[:content_type] + assert_equal "file.png", attachable[:filename] + + image = MiniMagick::Image.read(attachable[:io]) + assert_equal 612, image.width + assert_equal 792, image.height + end + end + test "previewing a PDF that can't be previewed" do blob = create_file_blob(filename: "video.mp4", content_type: "application/pdf")