Pdfunite
Merge PDF files with Ruby.
Pdfunite is a Ruby wrapper for the pdfunite command line tool. No Java required.
Installation
Pdfunite requires the pdfunite
command line tool, which uses the poppler
library.
Linux
Install the poppler-utils
package using your package manager.
OS X
Install poppler
using Homebrew.
In your app
Add this line to your application's Gemfile:
# Gemfile
gem 'pdfunite'
Usage
# Join existing PDF files
pdf_data = Pdfunite.join('file1.pdf', 'file2.pdf', 'file3.pdf')
File.open('joined.pdf', 'wb') { |f| f << pdf_data }
# Join PDF binary data provided by a collection of objects
pdf_data = Pdfunite.join(objects) { |obj| obj.to_pdf }
Optional configuration
# Set pdfunite binary (defaults to the binary on PATH)
Pdfunite.binary = '/opt/local/bin/pdfunite'
# Set custom logger (defaults to STDOUT)
Pdfunite.logger = Logger.new('pdfunite.log')