Skip to content

Destinations

A destination defines a particular view of a document, consisting of the following items:

  • The page of the document that shall be displayed
  • The location of the document window on that page
  • The magnification (zoom) factor

Destinations may be associated with bookmarks, annotations or actions. In each case, the destination specifies the view of the document that shall be presented when the bookmark or annotation is opened or the action is performed. In addition, the optional PDFFixedDocument.OpenAction property may specify a destination that shall be displayed when the document is opened.
All destinations share the same common properties:

  • Left, Top, Right, Bottom - define the location of the document window on the page. The usage of these value depends on the ZoomMode property.
  • ZoomMode - specifies how the page is zoomed when the destination is opened. The following options are supported:

    • XYZ - display the designated page with the coordinates (Left, Top) positioned at the upper-left corner of the window and the contents of the page magnified by the factor Zoom.
    • Fit - display the designated page with its contents magnified just enough to fit the entire page within the window both horizontally and vertically.
    • FitH - display the designated page with the vertical coordinate Top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of the page within the window.
    • FitV - display the page designated by page, with the horizontal coordinate Left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of the page within the window.
    • FitR - display the designated page with its contents magnified just enough to fit the rectangle specified by the coordinates Left, Bottom, Right and Top entirely within the window both horizontally and vertically.
    • FitB - display the designated page with its contents magnified just enough to fit its bounding box entirely within the window both horizontally and vertically.
    • FitBH - display the designated page with the vertical coordinate Top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of its bounding box within the window.
    • FitBV - display the designated page with the horizontal coordinate Left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of its bounding box within the window.
  • Zoom - the zoom factor to be used when the destination is opened. Its usage depends on the ZoomMode property.

PDF4NET supports the following types of destinations:

Direct page destinations

These destinations specify a location in the current document, the destination page being specified by a PDFPage object.
This destination is represented by the PDFPageDirectDestination class.
The code below shows how to create a destination to first page in the document. When the destination is opened, the page will be zoomed to 400% and top left corner of the page will be placed at the top left corner of the viewer window:

C#
1
2
3
4
5
6
PDFPageDirectDestination pageDirectDestination = new PDFPageDirectDestination();
pageDirectDestination.Page = document.Pages[0];
pageDirectDestination.ZoomMode = PDFDestinationZoomMode.XYZ;
pageDirectDestination.Left = 0;
pageDirectDestination.Top = 0;
pageDirectDestination.Zoom = 400;

Because the destination page is specified by a reference to the page object, it does not matter whether pages are added or removed from the document.

Page number destinations

These destinations are used to specify a location in a remote document, the destination page being specified by its number as a reference to the page object is not possible.
This destination is represented by the PDFPageNumberDestination class.
The code below shows how to create a destination to first page in the document. When the destination is opened, the page will be zoomed to fit entirely in the viewer window:

C#
1
2
3
PDFPageNumberDestination pageNumberDestination = new PDFPageNumberDestination();
pageNumberDestination.Page = 0;
pageNumberDestination.ZoomMode = PDFDestinationZoomMode.FitB;

Because the destination page is specified by its number, is the destination document changes, pages are added or removed, the page that is displayed when the destination opens might change.

Named destinations

These destinations use a symbolic name to create the link between the destination (direct or number based) and its owner (link, bookmark or action).
This destination is represented by the PDFNamedDestination class. It has 2 properties, its Name and the actual Destination. Named destinations are stored in the document's NamedDestinations collection.
The code below shows how to create a named destination.

C#
1
2
3
4
5
PDFNamedDestination namedDestionation = new PDFNamedDestination();
namedDestination.Name = "someName";
namedDestination.Destination = pageDirectDestination;
// ...
document.NamedDestinations.Add(namedDestination);

The advantage of these destinations is that you a attach a named destination to its owner (action, bookmark or link) with an empty Destination. Then when you have the actual destination, you can attach it to the named destination.