How to Combine PDFs in Ruby

How do you combine PDFs in ruby?

I wrote a ruby gem to do this — PDF::Merger. It uses iText. Here's how you use it:

pdf = PDF::Merger.new
pdf.add_file "foo.pdf"
pdf.add_file "bar.pdf"
pdf.save_as "combined.pdf"

Is it possible to combine a series of PDFs into one using Ruby?

A Ruby-Talk post suggests using the pdftk toolkit to merge the PDFs.

It should be relatively straightforward to call pdftk as an external process and have it handle the merging. PDF::Writer may be overkill because all you're looking to accomplish is a simple append.

combine_pdf not combining the pdfs

It looks like the README for that library calls .to_pdf when sending the data. Hopefully calling #to_pdf on the pdf object like in the example will fix your issue.

send_data pdf.to_pdf, filename: “my_combined_pdf”, type: "application/pdf"

https://github.com/boazsegev/combine_pdf#rendering-pdf-data



Related Topics



Leave a reply



Submit