class HexaPDF::Layout::Style::LinkLayer
See: PDF2.0 s12.5.6.5, Layers, HexaPDF::Type::Annotations::Link
destination on a different page or executing a URI action.
Style objects using link annotations. Typical use cases would be linking to a (named)
The LinkLayer class provides support for linking to in-document or remote destinations for
def call(canvas, box)
Creates the needed link annotation if possible, i.e. if the context of the canvas is a
def call(canvas, box) return unless canvas.context.type == :Page @dest = box.properties['link'] unless @dest || @action page = canvas.context matrix = canvas.graphics_state.ctm quad_points = [*matrix.evaluate(0, 0), *matrix.evaluate(box.width, 0), *matrix.evaluate(box.width, box.height), *matrix.evaluate(0, box.height)] x_minmax = quad_points.values_at(0, 2, 4, 6).minmax y_minmax = quad_points.values_at(1, 3, 5, 7).minmax border_color = case @border_color when [], nil @border_color else canvas.color_from_specification(@border_color).components end annot = { Subtype: :Link, Rect: [x_minmax[0], y_minmax[0], x_minmax[1], y_minmax[1]], QuadPoints: quad_points, Dest: @dest, A: @action, Border: @border, C: border_color, } (page[:Annots] ||= []) << page.document.add(annot) end
def initialize(dest: nil, uri: nil, file: nil, action: nil, border: false, border_color: nil)
LinkLayer.new(uri: "https://my.example.com/path", border: [5 5 2])
LinkLayer.new(dest: [page, :XYZ, nil, nil, nil], border: true)
Examples:
or 4 (CMYK) values.
Defines the border color. Can be an array with 0 (transparent), 1 (grayscale), 3 (RGB)
+border_color+::
rules for annotation borders.
If set to +true+, a standard border is used. Also accepts an array that adheres to the
+border+::
The PDF action that should be executed.
+action+::
HexaPDF::Type::FileSpecification.
should be launched. Can either be a string or a Filespec object. Also see:
The file that should be opened or, if it refers to an application, the application that
+file+::
The URI to link to.
+uri+::
property named 'link' which is used for the destination.
+dest+, +uri+, +file+ nor +action+ is specified, it is assumed that the box has a custom
The destination array or a name of a named destination for in-document links. If neither
+dest+::
+action+ may be specified):
The following arguments are allowed (note that only *one* of +dest+, +uri+, +file+ or
Creates a new LinkLayer object.
def initialize(dest: nil, uri: nil, file: nil, action: nil, border: false, border_color: nil) if dest && (uri || file || action) || uri && (file || action) || file && action raise ArgumentError, "Only one of dest, uri, file or action is allowed" end @dest = dest @action = if uri {S: :URI, URI: uri} elsif file {S: :Launch, F: file, NewWindow: true} elsif action action end @border = case border when false then [0, 0, 0] when true then nil when Array then border else raise ArgumentError, "Invalid value for border: #{border}" end @border_color = border_color end