shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

Convert pdf to image from remote url #37

Closed josal closed 11 years ago

josal commented 11 years ago

Hi,

I've sucessfully used the convert method in local, with pdfs in my system. Now, in production, I have the pdf files in memory or in S3.

I haven't been able to use StringIO or similar as the first argument.

How could I convert a pdf to images if the source file is not saved in my machine - is in memory or in S3?

Thanks in advance and congrats for this useful gem.

Jose.

shairontoledo commented 11 years ago

Hi,

There is no support for such thing. You will need to steam the s3 object to a temp file, something like:

require 'tempfile'

Tempfile.new('tmp_pdf_file') do |file|
  S3Object.stream('s3key', 's3bucket'){|chunk| file.write chunk }
  file.close
  RGhost::Convert.new(file.path).to :png, :filename => "/path/to/image.png"
end

Thx