Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.
use PDF::Builder;use PDF::Builder::Util;use PDF::Builder::Annotation;...my $pdf = PDF::Builder->new(-compress => $compress);my $annotation = PDF::Builder::Annotation->new();...my $page = $pdf->page();$page->mediabox(595,842);...my $text = $page->text();...
$annotation->url($url, %options) Defines the annotation as a launch-url with url $url and options %options (-rect, -border, -color: see descriptions below). This page is usually brought up in a browser, and may be remote.
$annotation->rect($llx,$lly, $urx,$ury) Sets the rectangle (active click area) of the annotation, given by -rect option. This is any pair of diagonally opposite corners of the rectangle. The default clickable area is the icon itself. Defining option. Note that this "option" is actually required. -rect => [LLx, LLy, URx, URy] Set annotation rectangle at [LLx,LLy] to [URx,URy] (lower left and upper right coordinates). LL to UR is customary, but any diagonal is allowed.$annotation->border(@b) Sets the border-style of the annotation, if applicable, as given by the -border option. There are three entries in the array: horizontal and vertical corner radii, and border width. A border is used in annotations where text or some other material is put down, and a clickable rectangle is defined over it (-rect). A border is not used when an icon is being used to mark the clickable area. The default is [0 0 1] (solid line of width 1, with sharp corners). Defining option: -border => [CRh, CRv, W] -border => [CRh, CRv, W [, on, off...]] Set annotation border style of horizontal and vertical corner radii CRh and CRv (value 0 for squared corners) and width W (value 0 for no border). The default is squared corners and a solid line of width 1 ([0 0 1]). Optionally, a dash pattern array may be given (on length, off length, as one or more pairs). The default is a solid line. The border vector seems to ignore the first two settings (corner radii), but the line thickness works, on basic Readers. The radii may work on some other Readers.$annotation->Color(@color) Set the icon's fill color. The color is an array of 1, 3, or 4 numbers, each in the range 0.0 to 1.0. If 1 number is given, it is the grayscale value (0 = black to 1 = white). If 3 numbers are given, it is an RGB color value. If 4 numbers are given, it is a CMYK color value. Currently, named colors (strings) are not handled. For link and url annotations, this is the color of the rectangle border (-border given with a width of at least 1). If an invalid array length or numeric value is given, a medium gray ( [0.5] ) value is used, without any message. If no color is given, the usual fill color is black. Defining option: -color => [ ] or not 1, 3, or 4 numbers 0.0-1.0 A medium gray (0.5 value) will be used if an invalid color is given. -color => [ g ] If g is between 0.0 (black) and 1.0 (white), the fill color will be gray. -color => [ r, g, b ] If r (red), g (green), and b (blue) are all between 0.0 and 1.0, the fill color will be the defined RGB hue. [ 0, 0, 0 ] is black, [ 1, 1, 0 ] is yellow, and [ 1, 1, 1 ] is white. -color => [ c, m, y, k ] If c (red), m (magenta), y (yellow), and k (black) are all between 0.0 and 1.0, the fill color will be the defined CMYK hue. [ 0, 0, 0, 0 ] is white, [ 1, 0, 1, 0 ] is green, and [ 1, 1, 1, 1 ] is black.
use strict;use warnings;use PDF::Builder;my $pdf = PDF::Builder->new(-compress => 'none');my $page = $pdf->page();my $text = $page->text();my $font = $pdf->corefont('Times-Roman');$text->font($font, 20);my $x = 100;my $y = 600;$text->translate($x, $y);$text->text("Click ");$x += $text->advancewidth("Click ");# x,y should be at LL corner of "here" (on baseline)$text->fillcolor('blue');$text->text("here");my $target_width = $text->advancewidth("here");my $annotation = $page->annotation();$annotation->url("https://www.google.com", -rect => [$x-1, $y-5, $x+1+$target_width, $y-5+1+20], # clickable area -border => [0, 0, 0], # show border with 0 0 1 -color => [0, 1, 0], # green border color );# restore color and do rest of line$text->fillcolor('black');$text->text(" to go to Google.");$pdf->saveas('urlexmp.pdf');