talira

Versatile PDF creation and manipulation for Ruby

open sourceAGPL-3.0-onlyself-hostablefree

HexaPDF is a pure Ruby library and command-line tool for creating and changing PDF files. Unlike Prawn, which only generates new content, it reads existing PDFs too: it merges, splits and reorders pages, fills and creates AcroForm forms with Adobe Reader-like appearances, adds annotations, outlines and attachments, extracts text, images and files, encrypts with AES-256, signs and verifies digital signatures and optimizes file size. For new documents it has a canvas API that maps to PDF operators and a layout engine with flowing text, styles, lists, multi-column layouts and automatic page breaks, with TrueType font subsetting. Thomas Leitner, who also wrote kramdown, dual-licenses it: AGPL-3.0 with a requirement to keep HexaPDF's producer line in every PDF, or a commercial licence sold per host.

Problems it solves

  • fill in an existing PDF form from my Ruby app and keep the fields looking right in Acrobat
  • merge several PDF files into one in Ruby without shelling out to a Java tool
  • Prawn can make new PDFs but I need to edit an existing one
  • add a digital signature to a PDF from Ruby code
  • encrypt a PDF with a password using AES-256 in Ruby
  • extract the text and images from PDF pages in a Ruby script
  • lay out an invoice PDF with flowing text, columns and automatic page breaks in Ruby
  • compress and optimize large PDF files to shrink them
  • reorder, rotate or delete pages in a PDF from the command line
  • attach files to a PDF or pull out embedded attachments
  • a PDF library for Ruby with no native dependencies to compile
  • validate the internal object structure of a broken PDF
  • create fillable form fields on a PDF I generate

Features

  • pure Ruby with minimal dependencies
  • canvas API mapping to PDF operators
  • document composition engine with flowing text, styles, lists and columns
  • JPEG, PNG and PDF images with transparency
  • UTF-8 text with TrueType fonts and subsetting
  • AcroForm forms with appearance generation
  • annotations and document outlines
  • file attachments and extraction
  • text and image extraction
  • encryption including PDF 2.0 AES-256
View 5 more
  • digital signatures: signing and verification
  • file size optimization
  • PDF object validation
  • hexapdf command for merging, splitting, encrypting, decrypting and optimizing
  • 100% test coverage

Limitations

  • Requires keeping HexaPDF's producer line in every PDF under the AGPL: a commercial licence removes the requirement1

Ways to run it

HexaPDF (AGPL)

You run it, AGPL-3.0-only

free1

You arrange

  • keeping HexaPDF's producer line in every PDF it creates or changes
  • releasing your source under the AGPL when the licence requires it

Self-hosting docs

HexaPDF commercial licence

You run it, under a commercial licence

EUR 600 per physical host a year (any number of VMs on it), EUR 300 per virtual machine a year for VM-only deployments; unlimited hosts on request2

Only in this edition

  • use without the AGPL's conditions
  • development, testing, staging and CI hosts without extra licences

Self-hosting docs

Capabilities

Has an APIplan not known
Has a command line toolplan not known

Alternatives

The same job

These do what HexaPDF does.

  1. Prawn Pure Ruby library for generating PDFs from code
  2. Apache PDFBox The Apache PDFBox library is an open source Java tool for working with PDF documents.
  3. iText Core Generate & Manipulate PDFs Effortlessly
  4. pdf-lib Create and modify PDF documents in any JavaScript environment.
  5. pdf-reader A PDF parser conforming as much as possible to the PDF specification from Adobe

Compare HexaPDF with the top 3