1. Products
  2.   PDF
  3.   Ruby
  4.   CombinePDF
 
  

Open Source Ruby API for PDF Files Parsing & Merging

Ruby PDF Library enables developers to Combine PDF files, add content, stamp, watermark to existing PDF files inside Ruby Apps.

CombinePDF is an open Source pure Ruby library that gives software developers the capability to work with PDF files inside Ruby apps. Portable Document Format (PDF) file is one of the World’s most used file formats for storing and sharing information across the globe. PDF files are particularly convenient for documents such as magazine articles, product brochures, flyers, etc.

The library enables software developers to load and parse PDF files and combines them with other PDF files, add stamp as well as a watermark to PDFs, add content to existing PDF pages, add page numbers, PDF data renderings (all using the PDF file format and pure Ruby code). The library has provided limited support for encrypted files as well as very basic support for compressed files.  The CombinePDF library is written natively in Ruby and smoothly works on all Ruby platforms that follow Ruby 2.0 compatibility.

.

Previous Next

Getting Started with CombinePDF

To install the CombinePDF on your system, please run the following command, 

Install CombinePDF with ruby gems

gem install combine_pdf 

Load and Parse PDF Data via Ruby API

The open source PDF library CombinePDF has included support for loading and parsing PDF files inside Ruby applications. As recommended, loading data from PDF files is easy. Developers can also parse PDF files from memory. It is very effective to load data from memory, especially for data received via the internet or from a different library. Same like parsing, rendering can also be performed either to the memory or to a file.

Load & Parse PDF Data via Ruby API


  # Loading & Parsing PDF Data
  pdf = CombinePDF.load("file.pdf")
  pdf_data = prawn_pdf_document.render # Import PDF data from Prawn
  pdf = CombinePDF.parse(pdf_data)
  
  # Loading & Parsing Data from a Remote Location
  
  require 'combine_pdf'
  require 'net/http'

  url = "https://example.com/my.pdf"
  pdf = CombinePDF.parse Net::HTTP.get_response(URI.parse(url)).body

Combine PDF Document or Pages

The open source PDF library CombinePDF has provided complete support for loading and merging PDF files via Ruby commands. Developers can easily add PDF data via the file system or directly from the memory. The library also allows adding only specific pages for example you can choose to add even or odd pages. Please keep in mind that adding the whole file is faster than adding each page separately.

Merge PDF Document via Ruby Library


  # Combine PDF Document 
  
  pdf = CombinePDF.new
  pdf << CombinePDF.load("file1.pdf") # one way to combine, very fast.
  pdf << CombinePDF.load("file2.pdf")
  pdf.save "combined.pdf"

Add Content to Existing PDF Pages via Ruby

CombinePDF API gives software developers the power to add images, text, or logos to an existing PDF file using a couple of lines of Ruby code. To insert content into an existing PDF document, first you need to import text from an existing PDF page. Once imported, you can easily add it to the PDF page of your choice.

Add Image/Logo to Existing PDF via Ruby

 
  company_logo = CombinePDF.load("company_logo.pdf").pages[0]
  pdf = CombinePDF.load "content_file.pdf"
  pdf.pages.each {|page| page << company_logo} # notice the << operator is on a page and not a PDF object.
  pdf.save "content_with_logo.pdf"

Add Page Numbers to PDF

Adding page numbers to PDF is always useful because searching for any specific information becomes easy with page numbers. Adding page numbers makes your file more organized and easier to follow. The open source library CombinePDF enables software developers to add page numbers to a PDF object or file. Developers can use various options to add page numbers, such as top, bottom, left, right, or center, etc.

Add Page Numbers to a PDF File via Ruby

 
  pdf = CombinePDF.load "file_to_number.pdf"
  pdf.number_pages
  pdf.save "file_with_numbering.pdf"

  # Place the Page Number at a custom location 
  
  pdf.number_pages(location: [:bottom_right]) 
 English