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.
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"
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
How to merge two pdf's, one created with wicked_pdf and second through paperclip upload
You need to use combined_pdf gem
gem install combine_pdf
pdf = CombinePDF.new
pdf << CombinePDF.load("file1.pdf") # one way to combine, very fast.
pdf << CombinePDF.load("file2.pdf")
pdf.save "combined.pdf"
Otherwise, if you want to do the above code in one line
(CombinePDF.load("file1.pdf") << CombinePDF.load("file2.pdf") << CombinePDF.load("file3.pdf")).save("combined.pdf")
How do I combine a number of images into a single PDF using ruby?
You can use RMagick's ImageList#write
:
If the image format indicated by the filename supports multiple images per file (animated images), write writes all the images in the imagelist to a single file.
Example:
require 'rmagick'
image_list = Magick::ImageList.new("image1.png", "image2.png", "image3.png")
image_list.write("images.pdf")
Related Topics
How to Export a Rails Model to JSON Schema
How to Use Fiddle to Pass or Return a Struct to Native Code
How to Create a Jwt for Use with Apple Music
Ruby - Problems with Expect and Pty
Rails Include Only Selected Columns from Relation
How to Bundle Install Gemfile with Specific Version of Bundler
What's the Efficient Way to Multiply Two Arrays and Get Sum of Multiplied Values in Ruby
Date Range Facets with Sunspot in Ruby on Rails
How to Import Using Fastercsv a Row with a Name Like "CiaráN"
Rails 3/ Git/ Bundler Fatal Could Not Parse Object
Rails Installation Error :The 'Atomic' Native Gem Requires Installed Build Tools
How to Merge Two Hashes That Have Same Keys in Ruby
Celluloid Async Inside Ruby Blocks Does Not Work
How to Return a Fixed Length Binary Representation of an Integer in Ruby
How to Use Ffmpeg on a Remote Machine via Ssh
Fresh Install of Rvm in Ubuntu Isn't Letting Me Install Gems (Zlib Error)
Robustly Call a Flaky API: Proper Error Handling with Net::Http