Skip to content

Converting PDF into other formats

shairontoledo edited this page Mar 28, 2011 · 1 revision

RGhost has a “utility“ class for converting PDF documents to other formats. The options from Document#render and

RGhost::Engine#render are used for the Convert#to method. Example:

preview = RGhost::Convert.new('/my/dir/file.pdf')
preview.to :png, :multipage => true, :resolution => 72  #returns an Array of Files

The :range option can be used to convert only a subset of a multipage file. Example, returns an Array of Files:

pages = RGhost::Convert.new('/tmp/test.pdf').to :jpeg, :multipage => true, :range => 5..6

Only the first page


  thumb = RGhost::Convert.new('/tmp/test.pdf').to :png  #returns File

Checking for errors

 
  thumb = RGhost::Convert.new('/tmp/test.pdf')
  out = thumb.to :png  #returns File
  if thumb.error
    raise Exception.new “Image error”
  else
     File.cp(out,”/my/dir”)
  end