class HexaPDF::Content::CanvasComposer

Parent

The CanvasComposer class allows using the document layout functionality for a single canvas. It works in a similar manner as the HexaPDF::Composer class.

See: HexaPDF::Composer, HexaPDF::Document::Layout

Attributes

canvas[R]

The associated canvas.

document[R]

The associated HexaPDF::Document instance.

frame[R]

The HexaPDF::Layout::Frame instance into which the boxes are laid out.

Public Class Methods

new(canvas, margin: 0)

Creates a new CanvasComposer instance for the given canvas.

The margin can be any value allowed by HexaPDF::Layout::Style::Quad#set and defines the margin that should not be used during composition. For the remaining area of the canvas a frame object will be created.

Public Instance Methods

draw_box(box)

Draws the given HexaPDF::Layout::Box and returns the last drawn box.

The box is drawn into the frame. If it doesn’t fit, the box is split. If it still doesn’t fit, a new region of the frame is determined and then the process starts again.

If none or only some parts of the box fit into the frame, an exception is thrown.

method_missing(name, *args, **kwargs, &block)

Draws any box that can be created using HexaPDF::Document::Layout.

This includes all named boxes defined in the ‘layout.boxes.map’ configuration option.

Examples:

canvas.composer(margin: 10) do |composer|
  composer.text("Some text", position: :float)
  composer.image(machu_picchu, height: 30, align: :right)
  composer.lorem_ipsum(sentences: 1, margin: [0, 0, 5])
  composer.list(item_spacing: 2) do |list|
    composer.document.config['layout.boxes.map'].each do |name, klass|
      list.formatted_text([{text: name.to_s, fill_color: "hp-blue-dark"},
                           {text: "\n#{klass}"}], font_size: 6)
    end
  end
end

See: HexaPDF::Document::Layout#box

Calls superclass method
style(name, base: :base, **properties)

Invokes HexaPDF::Document::Layout#style with the given arguments to create/update and return a style object.