Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfXYZDestination Class

A destination that positions a specific coordinate at the top left corner of the document window, and zooms a page with the specified zoom factor.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v24.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

#Declaration

public class PdfXYZDestination :
    PdfDestination

#Remarks

The XYZ destination displays the page as follows:

  • A specific page point is positioned at the top left corner of the document window.
  • A page is magnified with the specified zoom factor.

You can associate any number of bookmarks and link annotations with a destination.

#Associate a Bookmark with a Destination

This example shows how to create a bookmark with a destination that displays the page as follows:

bookmark

View Example

using System.Collections.Generic;
using DevExpress.Pdf;

using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
{
    // Load a document
    documentProcessor.LoadDocument(@"..\..\Document.pdf");

    // Define search words
    string[] words = { "DX-B5000", "DX-RX800" };

    // Specify search parameters
    PdfTextSearchParameters searchParameters = new PdfTextSearchParameters();
    searchParameters.CaseSensitive = true;
    searchParameters.WholeWords = true;

    foreach (string word in words)
    {
        // Get search results
        PdfTextSearchResults results = documentProcessor.FindText(word, searchParameters);

        // If the text is found, create a destination that positions the found text
        // at the upper window corner
        if (results.Status == PdfTextSearchStatus.Found)
        {
            PdfXYZDestination destination = new PdfXYZDestination(results.Page, 0, results.Rectangles[0].Top, null);

            // Create a bookmark associated with the destination
            PdfBookmark bookmark = new PdfBookmark() { Title = word, Destination = destination };

            // Add the bookmark to the bookmark list
            documentProcessor.Document.Bookmarks.Add(bookmark);
        }
    }
    // Save the modified document
    documentProcessor.SaveDocument(@"..\..\Result.pdf");
}

Call the PdfPageFacade.AddLinkAnnotation method and pass a PdfXYZDestination object as a parameter to create a link annotation associated with a destination.

The code sample below creates a link annotation with a destination that displays the fifth page as follows:

destination

using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    // Load a document
    pdfDocumentProcessor.LoadDocument("Demo.pdf");

    PdfDocumentFacade documentFacade = pdfDocumentProcessor.DocumentFacade;

    // Create an XYZ destination that refers to the fifth page
    PdfXYZDestination destination =
       documentFacade.Pages[4].CreateXYZDestination(100, 524, 1.2f);

    // Find a specific phrase
    string word = "Type 3 fonts";
    PdfTextSearchResults results = pdfDocumentProcessor.FindText(word);

    // If the phrase is found, obtain its bounding rectangle
    if (results.Status == PdfTextSearchStatus.Found)
    {
        PdfRectangle textRectangle = results.Rectangles[0].BoundingRectangle;

        // Access first page properties
        PdfPageFacade pageFacade = documentFacade.Pages[0];

        // Create a link annotation associated with the bounding rectangle
        // and destination
        PdfLinkAnnotationFacade pdfLinkAnnotation =
           pageFacade.AddLinkAnnotation(textRectangle, destination);
        pdfLinkAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Push;

        pdfDocumentProcessor.SaveDocument("out.pdf");
    }
}

#Inheritance

Object
DevExpress.Pdf.Native.PdfDocumentItem
DevExpress.Pdf.Native.PdfObject
PdfDestination
PdfXYZDestination
See Also