aboutsummaryrefslogblamecommitdiffstats
path: root/activestorage/lib/active_storage/previewer/pdf_previewer.rb
blob: a2f05c74a60a109e003de80bb4a3c2397b4990b2 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                            
                                          






                                                                                            
# frozen_string_literal: true

module ActiveStorage
  class Previewer::PDFPreviewer < Previewer
    def self.accept?(blob)
      blob.content_type == "application/pdf"
    end

    def preview
      download_blob_to_tempfile do |input|
        draw "mutool", "draw", "-F", "png", "-o", "-", input.path, "1" do |output|
          yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png"
        end
      end
    end
  end
end