title: Multipage PDF processing to PNG using Carrierwave
body: <p>I am uploading a PDF in my Rails application using <a href="https://github.com/jnicklas/carrierwave" rel="nofollow">Carrierwave</a>. My aim is to convert each page in the PDF to an PNG and ensure that each of these PNGs resides in the uploads directory which Carrierwave creates based on my model etc. </p>
  
  <p>Current progress is that I am able to upload a PDF, convert it to a series of PNGs in the temporary directory that Carrierwave creates but I am unable to work out the correct approach to moving these converted PNGs into the designated uploads directory:</p>
  
  <pre><code>"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  </code></pre>
  
  <blockquote>
    <p>UPDATE - Added below my current attempt and error code</p>
  </blockquote>
  
  <p>My current code is as follows:</p>
  
  <pre><code>def extract(format)
    cache_stored_file! if !cached?
    images = Magick::ImageList.new(current_path)
    images.write File.dirname( current_path ) &lt;&lt; "/" &lt;&lt; filename
  end
  
  def filename
    super != nil ? super.split('.').first + '.png' : super
  end
  </code></pre>
  
  <p>All attempts to move the files using any approach to the uploads directory results in some sort of 'no such file or directory' Error. For example using:</p>
  
  <pre><code>images.each do |f|
    FileUtils.mv f.filename, File.join("#{Rails.root}/#{store_dir}", "image-0.png")
  end
  
  Errno::ENOENT (No such file or directory - 
  (/Users/reggie/ExampleApp/public/uploads/tmp/20120611-2259-7520-3647/image-0.png,
   /Users/reggie/ExampleApp/public/uploads/painting/image/39/image-0.png))
  </code></pre>
  
  <p>Any suggestions would be welcomed to help me get through this wall I have hit.</p>
  
  <p>Just as a side note as to why I am not using the <a href="https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/processing/rmagick.rb#L278" rel="nofollow">manipulate</a> logic, example code (see below) results in the same as above i.e. converted files in the temporary directory created by Carrierwave, <strong>however</strong> all the converted images remain with the .pdf file extension.</p>
  
  <pre><code>manipulate!(:format =&gt; :png) do |img|
    img
  end
  </code></pre>