HexaPDF
Extras¶ ↑
This library contains additional functionality that is not provided by the main HexaPDF library.
To use it, just require 'hexapdf-extras'
and it will update the HexaPDF
configuration settings to make the various extensions available.
Note that you need to install the dependencies of the features you use yourself as they are not listed in the gem file!
QR code Generator¶ ↑
This extension plugs into the graphic objects and boxes system of HexaPDF
and allows one to easily create a fully-scalable QR code:
require 'hexapdf' require 'hexapdf-extras' doc = HexaPDF::Document.new canvas = doc.pages.add.canvas canvas.draw(:qrcode, at: [100, 100], size: 200, data: "https://hexapdf.gettalong.org") doc.write('qrcode.pdf')
Underneath the rqrcode_core
library is used for actually generating the QR code. This means you need to install that library for this extension to work.
The data
argument can be any data that rqrcode_core
understands. The other options understood by rqrcode_core
are also supported.
See HexaPDF::Extras::GraphicObject::QRCode and HexaPDF::Extras::Layout::QRCodeBox for details.
Note: There was a bug in poppler (already fixed) which leads to invalid rendering in Okular (as of 2022-08-06).
Barcode Generator¶ ↑
This extensions provides access to generating nearly any kind of barcode. It taps into the graphic objects and boxes system of HexaPDF
to easily allow creating barcodes:
require 'hexapdf' require 'hexapdf-extras' doc = HexaPDF::Document.new canvas = doc.pages.add.canvas canvas.draw(:barcode, at: [100, 100], width: 300, symbology: :code128, value: "Hello HexaPDF!") doc.write('zint.pdf')
Underneath the ruby-zint
library is used which relies on the libzint library via FFI. This means that you need to install the ruby-zint
library for this extension to work.
See HexaPDF::Extras::GraphicObject::Zint and HexaPDF::Extras::Layout::ZintBox for details.
Swiss QR-bill generator¶ ↑
This extension provides a box class for the document layouting facilities of HexaPDF
to easily create a Swiss QR-bill:
HexaPDF::Composer.create("sample-qr-bill.pdf", margin: 0) do |composer| data = { lang: :de, creditor: { iban: "CH44 3199 9123 0008 8901 2", name: "Max Muster & Söhne", address_line1: "Musterstrasse", address_line2: "123", postal_code: "8000", town: "Seldwyla", country: "CH", }, debtor: { address_type: :combined, name: "Simon Muster", address_line1: "Musterstrasse 1", address_line2: "8000 Seldwyla", country: "CH" }, amount: 2500.25, currency: 'CHF', } composer.swiss_qr_bill(data: data, style: {valign: :bottom}) end
See HexaPDF::Extras::Layout::SwissQRBill for details.