gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.25k stars 70 forks source link
pdf pdf-generation pdf-manipulation ruby

HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby

HexaPDF is a pure Ruby library with an accompanying application for working with PDF files. It was designed with ease of use and performance in mind. It uses lazy loading and lazy computing when possible and tries to produce small PDF files by default.

In short, it allows

HexaPDF is available under two license, the AGPL and a commercial license, see the License section for details.

Features

Usage

The HexaPDF distribution provides the library as well as the hexapdf application. The application can be used to perform common tasks like merging PDF files, decrypting or encrypting PDF files and so on.

When HexaPDF is used as a library, it can be used to do all the task that the command line application does and much more. Here is a "Hello World" example that shows how to create a simple PDF file:

require 'hexapdf'

doc = HexaPDF::Document.new
canvas = doc.pages.add.canvas
canvas.font('Helvetica', size: 100)
canvas.text("Hello World!", at: [20, 400])
doc.write("hello-world.pdf")

For detailed information have a look at the HexaPDF website where you will the API documentation, example code and more.

It is recommend to use the HTML API documentation provided by the HexaPDF website as it is enhanced with example graphics and PDF files and tightly integrated into the rest of the website.

Requirements and Installation

Since HexaPDF is written in Ruby, a working Ruby installation is needed - see the official installation documentation for details. Note that you need Ruby version 2.6 or higher as prior versions are not supported!

HexaPDF works on all Ruby implementations that are CRuby compatible, e.g. TruffleRuby, and on any platform supported by Ruby (Linux, macOS, Windows, ...).

Apart from Ruby itself the HexaPDF library has only one external dependency geom2d which is written and provided by the HexaPDF authors. The hexapdf application has an additional dependency on cmdparse, a command line parsing library.

HexaPDF itself is distributed via Rubygems and therefore easily installable via gem install hexapdf.

Difference to Prawn

The main difference between HexaPDF and Prawn is that HexaPDF is a full PDF library whereas Prawn is a library for generating content.

To be more specific, it is easily possible to read an existing PDF with HexaPDF and modify parts of it before writing it out again. The modifications can be to the PDF object structure like removing superfluous annotations or the the content itself.

Prawn has no such functionality. There is basic support for using a PDF as a template using the pdf-reader and prawn-template gems but support is very limited. However, Prawn has a very featureful API when it comes to creating content, for individual pages as well as across pages.

If you want to migrate from Prawn to HexaPDF, there is the migration guide with detailed information and examples, comparing the Prawn API to HexaPDF's equivalents.

Why use HexaPDF?

Development

Clone the repository and then run rake dev:setup. This will install the needed Rubygem dependencies as well as make sure that all applications needed for the tests are available.

License

AGPL - see the LICENSE file for licensing details. Commercial licenses are available at https://gettalong.at/hexapdf/.

A commercial license is needed as soon as HexaPDF is distributed with your software or remotely accessed via a network and you don't provide the source code of your application under the AGPL. For example, if you serve PDFs on the fly in a web application.

Contact sales@gettalong.at for more information!

Some included files have a different license:

Contributing

See https://hexapdf.gettalong.org/contributing.html for more information.

Author

Thomas Leitner, https://gettalong.org