Search code examples
rubyruby-on-rails-3pdfpdf-reader

How to copy/read a pdf file in ruby/rails 3


I need to both read in and write pdf files and in some cases merge a pdf I have with the one I need to read in. I attempted to do this with the pdf-reader gem and the prawn gem.

The pdf-reader gem doesn't seem to allow straight copying of a file, but instead just pulling text out of files without formatting or images unless you write them in seperately. And even then it only pulls out pieces of files and skips others. Anything else out there for ruby ?

Edit: To be more specific, in some cases I need an exact copy of the pdf, and in others I will need to overlay the copy of one on top of the copy of another. Neither pdf-reader or docsplit seem to be able to make a copy (read in text/formatting/images/fonts etc).


Solution

  • After playing around a lot I found this question: overlay one pdf or ps file on top of another

    Seems that pdftk is as good as its going to get.

    Rails has a gem for this but it looks like it doesn't support overlay: http://pdf-toolkit.rubyforge.org/

    EDIT: Looks like a much better gem is out there but unpublished that supports overlay: https://github.com/tcocca/active_pdftk