Versatile PDF creation and manipulation library

$ gem install hexapdf

Latest version 0.24.1 released on 2022-08-11

HexaPDF is AGPL Open Source, a commercial license is available  Buy HexaPDF

"HexaPDF is invaluable for our business. It helps us quickly and efficiently manipulate hundreds of thousands of PDFs. Support for HexaPDF is always responsive, helpful, and easily the best support we've received from any of the software vendors we've worked with.

I highly recommend HexaPDF to any business that needs a fast and rock solid way to work with PDFs."
"The daisyBill platform processes tens of thousands of PDF files a week. Before HexaPDF, malformed PDF files required several approaches to fix. When we introduced HexaPDF, it already did way better then some of our other tools. Over the course of a few months, we worked with HexaPDF's author to improve HexaPDF's ability to process and repair malformed PDFs; this drastically streamlined our PDF tool kit.

When it comes to repairing malformed PDF files I highly recommend HexaPDF, plus it's in Ruby so the code is easy to write!"

PDF Creation

HexaPDF includes facilities for creating PDF documents from scratch. Use the low-level canvas API for drawing graphics and outputting text if you want full control over every aspect. Or use the built-in document layout engine that provides a convenient, word-processor like way of creating complex documents, including automatically flowing text around other content.

require 'hexapdf'
doc =
  font("Times", size: 30).
  text("Hello World", at: [200, 300])
require 'hexapdf'
HexaPDF::Composer.create("hello-world.pdf") do |composer|
  composer.text("Hello World", font_size: 30,
                align: :center, valign: :center)

PDF Encryption and Digital Signatures

HexaPDF supports all password based encryption mechanisms, including AES 256bit, when reading and writing PDF files.

There is also support for digitally signing a PDF using a certificate and for verifying digital signatures.

PDF Manipulation

HexaPDF can read existing documents and modify them in various ways. It supports

  • adding, modifying, re-ordering, or deleting pages,
  • handling annotations including adding new ones,
  • creating interactive forms or filling them out,
  • attaching or extracting files,

and much more!

require 'hexapdf'
doc =
doc.pages.move(3, 5)
new_page = doc.pages.insert(-2), 200, 30).fill
require 'hexapdf'
doc =
doc.acro_form.field_by_name('firstname').value = 'Thomas'
doc.acro_form.field_by_name('city').value = 'Vienna'

Content Extraction

HexaPDF allows extracting various parts of a PDF file, for example text from a page, attached files, embedded images, ...

PDF Optimization

HexaPDF writes output PDF files as compactly as possible. Additionally, it can lossleesly optimize existing PDF files to reduce their file size.

Ready to start with HexaPDF?  Tutorials


HexaPDF is licensed under the GNU Affero General Public License (AGPL), an open source license. It allows you to use HexaPDF for free as long as you adhere to the license. Additionally, there is also a commercial license.

The AGPL puts some restrictions in place to make sure that the community benefits from changes to the code. For example, if you use HexaPDF in an application and distribute that application, you have to make the source code of the whole application available under the AGPL. The same applies if your application is used over a network. Please refer to the license for details.

If you don't want to adhere to the AGPL or can't (e.g. because you can't make the code that uses HexaPDF available under the AGPL), then you need to purchase a commercial license.