Sha256: 4b80e2b77b434c1bf87ae3e338af0406eb7a8359edbd9fae1e5e67082c7ddfa8

Contents?: true

Size: 1.89 KB

Versions: 33

Compression:

Stored size: 1.89 KB

Contents

# # Composer
#
# This example shows how [HexaPDF::Composer] simplifies the creation of PDF
# documents by providing a high-level interface to the box layouting engine.
#
# Basic style properties can be set on the [HexaPDF::Composer#base_style] style.
# These properties are reused by every box and can be adjusted on a box-by-box
# basis.
#
# Various methods allow the easy creation of boxes, for example, text and image
# boxes. All these boxes are automatically drawn on the page. If the page has
# not enough room left for a box, the box is split across pages (which are
# automatically created) if possible or just drawn on the new page.
#
# Usage:
# : `ruby composer.rb`
#

require 'hexapdf'

lorem_ipsum = "Lorem ipsum dolor sit amet, con\u{00AD}sectetur
adipis\u{00AD}cing elit, sed do eiusmod tempor incidi\u{00AD}dunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exer\u{00AD}citation
ullamco laboris nisi ut aliquip ex ea commodo consequat. ".tr("\n", " ")

HexaPDF::Composer.create('composer.pdf') do |pdf|
  pdf.base_style.update(line_spacing: {type: :proportional, value: 1.5},
                        last_line_gap: true, align: :justify)
  image_style = pdf.base_style.dup.update(border: {width: 1}, padding: 5, margin: 10)
  link_style = pdf.base_style.dup.update(fill_color: [6, 158, 224], underline: true)
  image = File.join(__dir__, 'machupicchu.jpg')

  pdf.text(lorem_ipsum * 2)
  pdf.image(image, style: image_style, width: 200, position: :float)
  pdf.image(image, style: image_style, width: 200, position: :absolute,
            position_hint: [200, 300])
  pdf.text(lorem_ipsum * 20, position: :flow)

  pdf.formatted_text(["Produced by ",
                      {link: "https://hexapdf.gettalong.org", text: "HexaPDF",
                       style: link_style},
                      " via HexaPDF::Composer"],
                      font_size: 15, align: :center, padding: 15)
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
hexapdf-0.20.4 examples/018-composer.rb
hexapdf-0.20.3 examples/018-composer.rb
hexapdf-0.20.2 examples/018-composer.rb
hexapdf-0.20.1 examples/018-composer.rb
hexapdf-0.20.0 examples/018-composer.rb
hexapdf-0.19.3 examples/018-composer.rb
hexapdf-0.19.2 examples/018-composer.rb
hexapdf-0.19.1 examples/018-composer.rb
hexapdf-0.19.0 examples/018-composer.rb
hexapdf-0.18.0 examples/018-composer.rb
hexapdf-0.17.3 examples/018-composer.rb
hexapdf-0.17.2 examples/018-composer.rb
hexapdf-0.16.0 examples/018-composer.rb
hexapdf-0.15.9 examples/018-composer.rb
hexapdf-0.15.8 examples/018-composer.rb
hexapdf-0.15.7 examples/018-composer.rb
hexapdf-0.15.6 examples/018-composer.rb
hexapdf-0.15.5 examples/018-composer.rb
hexapdf-0.15.4 examples/018-composer.rb
hexapdf-0.15.3 examples/018-composer.rb