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.

CTS 29 - NamedDestination Help Needed

  • 5 Replies
  • 31 Views
*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
CTS 29 - NamedDestination Help Needed
« May 21, 2020, 09:11:08 AM »
otrcomm commented

Hello All,
This is really not an issue except that I am clueless!

Could someone please give me an example of embedding an href link? I suppose I use NamedDestination, but I do not know how.

Thank you,
Murrah Boswell

 PhilterPaper commented

You are looking to bring up a page in a browser, from your PDF document? You probably want to use $annotation->url('https://blahblah', %options);. Take a look at the Annotations documentation. Build the entire documentation package (HTML files) with buildDocs.pl --all in your docs directory. Let me know if you need additional help here.
« Last Edit: May 21, 2020, 09:18:16 AM by Phil »

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
Re: CTS 29 - NamedDestination Help Needed
« Reply #1: May 21, 2020, 02:25:26 PM »
otrcomm commented

Phil,

Thank you for yout prompt response. Ok, I am trying to embed a url in a pdf document. So in the code to generate the document I have added:
Code: [Select]
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();
...

So how would I add a url below the text block to this page with annotation? I am not really new to perl, but I am new to deciphering modules like
PDF::Builder and how to apply them without examples as guides.

Thank you for your help,
Murrah Boswell

PhilterPaper commented

From the Annotation documentation:
Code: [Select]
$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.

and (either in the url() call or separately defined)
Code: [Select]
$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.

I know that the documentation is a bit light on "how to" or "cookbook" examples. I'll mull over whether I can add a new example for annotations. Do you have just the bare installation, or do you have the complete installation with examples and contributions, as well as a tool for generating all the documentation?

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
Re: CTS 29 - NamedDestination Help Needed
« Reply #2: May 21, 2020, 08:36:38 PM »
Code: [Select]
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');

For other fonts and font sizes, you will need to play with the size of the -rect (clickable rectangle) to get all the text within the "box". Turn on the display of the clickable rectangle by setting the line width from 0 to 1.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
Re: CTS 29 - NamedDestination Help Needed
« Reply #3: May 23, 2020, 11:36:45 AM »
otrcomm commented

Hello and Good Morning,

Thank you so very much for this code example. I can study this example and understand better the other documentation you sent and the Annotation documentation.

Hope all is well in Woodstock! I lived outside of North Branch, Sullivan County, over by the Delaware River in the early 70s. In Arizona now!

Thanks again,
Murrah Boswell

otrcomm commented

Hello Again,

I forgot to ask, do you have any plans to add the ability to create pdf portfolios in PDF::Builder? I currently bundle pdfs into portfolios with Acrobat manually but would like a programmatic method.

Thank you,
Murrah Boswell

PhilterPaper commented

I currently have no plans to assemble portfolios, in part because these can pull in non-PDF documents. If someone can point me to portfolio documentation that shows it's fairly easy to do, I might reconsider.

Note that if all you're doing is folding multiple PDFs into one combined PDF, there are utilities out there to do this, and PDF::Builder could easily handle this with just a little Perl code. See the contrib/ and examples/ code. This would only be for PDFs, and would not be a general portfolio.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
Re: CTS 29 - NamedDestination Help Needed
« Reply #4: May 25, 2020, 09:01:10 PM »
otrcomm commented

Hello Phil,
 My requirements are to bundle multiple types of documents into a portfolio that can represent a particular completed project. The PDFs in this portfolio have each been digitally signed so they can not be modified. Combining them into a single PDF would invalidate the digital signatures of each document. I will be talking to a company called iText (https://itextpdf.com/en) about a java based tool they have developed to create PDF portfolios. I do not program in java, so that will be a learning curve just to evaluate their software and see how I might integrate it into my system.

Thank you,
Murrah Boswell

PhilterPaper commented

Combining PDFs without invalidating their digital signatures (as well as incorporating non-PDF documents) sounds quite complicated, and is getting well beyond the warrant of PDF::Builder. Unless someone can show me that it's actually fairly simple, and it could take Builder capabilities to do, I don't see adding portfolio creation to PDF::Builder.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 667
    • View Profile
Re: CTS 29 - NamedDestination Help Needed
« Reply #5: May 26, 2020, 12:13:16 PM »
PhilterPaper commented

I am closing this ticket, as the original issue has been dealt with.

I have opened up CTS 30 - PDF Portfolio for any further discussion on Portfolios. Please continue Portfolio discussion there.