CTS logo
hazy blue Catskill Mountains in distance

News:

PDF::Builder v3.028 Released, 31 December 2025
   Please also see the CPAN listing, the GitHub entry, and the latest changes list.


A Thought…

When I make a joke people laugh. When Congress makes a joke it becomes law.

 — Will Rogers

NAME

PDF::Builder::NamedDestination - Add named destinations (views) to a PDF

Inherits from PDF::Builder::Basic::PDF::Dict

Usage

A Named Destination is defined in a PDF which is intended to be the target of a specified Name (string), from within the same PDF, from another PDF, or from a PDF Reader command line (e.g, MyBigPDF.pdf#nameddest=foo). The advantage over going to a specific page is that a Named Destination always points to the same content in the document, even if that location moves around (i.e., to a different page number).

Some Operating Systems support command line invocation (e.g., > MyPDF.pdf#name=bar), and some browsers' PDF readers also support it. #nameddest=foo is the most basic form, and if Named Destinations are supported, this form should work. Some readers support the shortcut #name=foo, and some even support the bare name: #foo (similar to HTML). Named Destination syntax on the command line can vary widely by Reader.

A Named Destination must be unique within a given PDF, and is defined at the top level in the $pdf object. There are often limitations on the length of a Named Destination string (name), including the length of whatever means is used to invoke it (e.g., #nameddest=foo takes up 11 characters before you even get to the name 'foo' itself, so if the limit is 32, you're left with perhaps 21 characters for the name itself). Be aware of this, and keep the names as short as reasonably possible. Spaces within a name are not permitted, and allowable punctuation is limited. Consult the PDF documentation for specifics, but A-Z, a-z, 0-9, and '_' (underscore) are generally permitted. Usually names are case-sensitive ('foo' is a different destination than 'Foo').

    # create a Named Destination 'foo' in this PDF file on page $page
    my $dest = PDF::Builder::NamedDestination->new($pdf);
    # its action will be to go to this page object $page, and a window within it
    # (various 'fits' can be defined
    $dest->goto($page, 'xyz', (undef, undef, undef));
    $pdf->named_destination('Dests', 'foo', $dest);

See "named_destination" in PDF::Builder and "Page Fit Options" in PDF::Builder::Docs for information on named destinations.

METHODS

new

    $dest = PDF::Builder::NamedDestination->new($pdf)

    $dest = PDF::Builder::NamedDestination->new($pdf, @args)

Creates a new named destination object. Any optional additional arguments will be passed on to destination processing for "goto".

    $dest = PDF::Builder::NamedDestination->new($pdf, $page, 'xyz', 0,700, 1.5);

This will create a Named Destination which goes to ("goto") page object $page, with fit XYZ at position 0,700 and zoom factor 1.5.

It is possible to then call `goto()` to override the `new()` defined fit:

    $dest->goto($page, 'fitb'); # overrides XYZ fit 

If you did not give fit options in the `new()` call (just `$pdf`), it will be necessary to call `goto()` with fit settings, anyway:

    $dest = PDF::Builder::NamedDestination->new($pdf);
    $dest->goto($page, 'fit');

Finally, however you created the Named Destination, its action, and its page fit, you need to tell the system to insert an entry into the Named Destination directory:

    $pdf->named_destination('Dests', "foo", $dest);

This is where you actually name the destination. Consult "named_destination" in PDF::Builder and "Page Fit Options" in PDF::Builder::Docs for more information.

Target Destinations

Note that the usual practice for a Named Destination, invoked when the PDF is opened with a Named Destination specified, is to goto a point in the document. It is possible, though unusual, to go to a point in another document (pdf()), launch a local application (launch()), or launch a web browser (uri()).

The only "options" supported for goto and pdf are if you wish to give the location and its arguments (data) in the form of a hash element (anonymous array if more than one value). Unlike Annotation's "action" methods (goto, pdf, uri, and launch), there is no defining a "click area" (button) for the user interaction; thus, no rect, border, or color entries are recognized in NamedDestination. Any found will be ignored.

See "Page Fit Options" in PDF::Builder::Docs for a listing of the available locations and their syntax.

"xyz" is the default fit setting, with position (left and top) and zoom all the same as the calling page's.

    $dest->goto($page, $location, @args)  # preferred

    $dest->goto($page, %opts)  # opts including location and data

A go-to (link) action changes the view to a specified destination (page object, location code, and various pieces of data for it). This is a jump within the current PDF document (internal), and is the usual way of doing things.

Alternate name: link

Originally this method was link, but PDF::API2 changed the name to goto, to match the internal PDF command GoTo. "link" is retained for compatibility.

Notes: goto is a reserved Perl keyword (go to a label), so take care when using this in code that the Perl interpreter doesn't see this as a Perl 'goto'. If you receive an error message about a "missing label" or something equally puzzling, this may have happened. link is a built-in Perl function (Unix ln style command), so take care when using this code that the Perl interpreter doesn't see this as a Perl 'link' call (e.g., error message about "not enough arguments for link").

pdf, pdf_file, pdfile

    $dest->pdf($pdffile, $page_number, $location, @args) # preferred

    $dest->pdf($pdffile, $page_number, %opts) # location is a hash element

Defines the destination as an external PDF-file with filepath $pdffile, on page $page_number (numeric value), and either options %opts (location/fit => any data for it as a scalar or anonymous array) or one of two formats: an array of location/fit string and any data for it, or a location/fit string and an array with any data needed for it.

To go to a Named Destination and then immediately jump to a point in another PDF document is unusual, but possible.

Alternate names: pdf_file and pdfile

Originally this method was pdfile, and had been earlier renamed to pdf_file, but PDF::API2 changed the name to pdf. "pdfile" and "pdf_file" are retained for compatibility.

uri, url

    $dest->uri($url)

Defines the destination as launch-url (typically a web page) with uri $url. There are no options available.

To go to a Named Destination and then immediately launch a web browser is unusual, but possible.

Alternate name: url

Originally this method was url, but PDF::API2 changed the name to uri to match the PDF command. "url" is retained for compatibility.

launch, file

    $dest->launch($file)

Defines the destination as launch-file with filepath $file and page-fit options %opts. The target application is run. Note that this is not a PDF or a browser file -- it is a usually a local application, such as a text editor or photo viewer. There are no options available.

To go to a Named Destination and then immediately launch a local application is unusual, but possible.

Alternate name: file

Originally this method was file, but PDF::API2 changed the name to launch to match the PDF command. "file" is retained for compatibility.

NAVIGATION LINKS

Up (Parents)

Master Index
PDF::Builder -- Facilitates the creation and modification of PDF files

Siblings

PDF::Builder::Annotation -- Add annotations to a PDF
PDF::Builder::Basic::PDF -- Various utilities and support routines
PDF::Builder::Content -- Methods for adding graphics and text to a PDF
PDF::Builder::Docs -- Additional documentation for Builder module
PDF::Builder::FontManager -- Managing the font library for PDF::Builder
PDF::Builder::Lite -- Lightweight PDF creation methods (UNMAINTAINED)
PDF::Builder::Matrix -- Matrix operations library
PDF::Builder::Outline -- Manage PDF outlines (a.k.a. bookmarks)
PDF::Builder::Outlines -- Further Outline handling
PDF::Builder::Page -- Methods to interact with individual pages
PDF::Builder::Resource -- Base class for PDF resources
PDF::Builder::UniWrap -- Support routines for finding line breakpoints with Unicode text
PDF::Builder::Util -- Utility package for often-used methods across the package
PDF::Builder::ViewerPreferences -- How the PDF should be displayed or printed

 

All content © copyright 2005 – 2025 by Catskill Technology Services, LLC.
All rights reserved.
Note that Third Party software (whether Open Source or proprietary) on this site remains under the copyright and license of its owners. Catskill Technology Services, LLC does not claim copyright over such software.

 

This page is https://www.catskilltech.com/Documentation/PDF/Builder/NamedDestination.html

Search Quotations database.

Last updated Thu, 01 Jan 2026 at 7:27 PM

Valid HTML 5

Thu, 12 Mar 2026 at 9:30 AM EDT