title: How to convert the pdf uploaded using Active Storage to image in rails
body: <p>I have used Active Storage to upload the pdf files and i need to convert it to the image and save it as a attachment to active storage.
  I used the code as suggested here <a href="https://stackoverflow.com/questions/2974442/how-to-convert-pdf-files-to-images-using-rmagick-and-ruby">How to convert PDF files to images using RMagick and Ruby</a>
  When i used this code</p>
  <pre class="lang-rb prettyprint-override"><code>
  project_file.rb
  class ProjectFile &lt; ApplicationRecord
    has_many_attached: files
  end
  
  some_controller.rb
  def show
    pdf = url_for(ProjectFile.last.files.first)
    PdfToImage.new(pdf).perform
  end
  
  pdf_to_image.rb
  class PdfToImage
    require 'rmagick'
  
    attr_reader :pdf
  
    def initialize(pdf)
      @pdf = pdf
    end
  
    def perform
      Magick::ImageList.new(pdf)
    end
  end
  
  </code></pre>
  <p>It gave me this error when i try to execute it.</p>
  <p><code>no data returned `http://localhost:3001/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--d3dc048a53b43337dc372b3845901a7912391f9e/MA42.pdf' @ error/url.c/ReadURLImage/247 </code></p>
  <p>May be something is wrong with my code, so anyone suggest me what am i doing wrong or are there any better solution to my questions.</p>
  <p>ruby '2.6.5'</p>
  <p>rails '6.0.1'</p>
  <p>gem 'rmagick'</p>