-
Notifications
You must be signed in to change notification settings - Fork 159
Home
CombinePDF is a nifty model, written in pure Ruby, to parse PDF files and combine (merge) them with other PDF files, watermark them or stamp them (all using the PDF file format and pure Ruby code).
Combining PDF files s very straight forward.
First you create the PDF object that will contain all the combined data.
Then you "inject", using the << operator, the data - either page by page (which is slower) or file by file (which is faster).
The page by page is great if you want to mix things up, but since the "Catalog" dictionary of the PDF file must be updated (the Catalog is an internal PDF dictionary that contains references to all the pages and the order in which they are displayed), it is slower.
Last, you render or save the data.
For Example:
pdf = CombinePDF.new
# one way to combine, very fast:
pdf << CombinePDF.new "file1.pdf"
# different way to combine, slower, but allows to mix things up:
CombinePDF.new("file2.pdf").pages.each {|page| pdf << page}
# Save to file
pdf.save "combined.pdf"
# or render to memory
pdf.to_pdf