Back to Devexpress

PdfXYZDestination Class

officefileapi-devexpress-dot-pdf-dff13f88.md

latest8.0 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfXYZDestination :
    PdfDestination
vb
Public Class PdfXYZDestination
    Inherits PdfDestination

The following members return PdfXYZDestination objects:

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:

View Example

csharp
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");
}
vb
Imports System.Collections.Generic
Imports DevExpress.Pdf

Using documentProcessor As New PdfDocumentProcessor()

    ' Load a PDF document
    documentProcessor.LoadDocument("..\..\Document.pdf")

    ' Define search words
    Dim words() As String = { "DX-B5000", "DX-RX800" }

    ' Specify search parameters
    Dim searchParameters As New PdfTextSearchParameters()
    searchParameters.CaseSensitive = True
    searchParameters.WholeWords = True

    For Each word As String In words
        ' Get search results
        Dim results As PdfTextSearchResults = 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 Then
            Dim destination As New PdfXYZDestination(results.Page, 0, results.Rectangles(0).Top, Nothing)

            ' Create a bookmark associated with the bookmark
            Dim bookmark As New PdfBookmark() With {.Title = word, .Destination = destination}

            ' Add the bookmark to the bookmark list
            documentProcessor.Document.Bookmarks.Add(bookmark)
        End If
    Next word
    ' Save the modified document
    documentProcessor.SaveDocument("..\..\Result.pdf")
End Using

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:

csharp
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");
    }
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  ' Load a document
  pdfDocumentProcessor.LoadDocument("Demo.pdf")
  Dim documentFacade As PdfDocumentFacade = pdfDocumentProcessor.DocumentFacade

  ' Create an XYZ destination that refers to the fifth page
  Dim destination As PdfXYZDestination =
     documentFacade.Pages(4).CreateXYZDestination(100, 524, 1.2F)

  ' Find a specific phrase
  Dim word As String = "Type 3 fonts"
  Dim results As PdfTextSearchResults = pdfDocumentProcessor.FindText(word)

  ' if the phrase is found, obtain its bounding rectangle
  If results.Status = PdfTextSearchStatus.Found Then
    Dim textRectangle As PdfRectangle = results.Rectangles(0).BoundingRectangle

    ' Access first page properties
    Dim pageFacade As PdfPageFacade = documentFacade.Pages(0)

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

    pdfDocumentProcessor.SaveDocument("out.pdf")
  End If
End Using

Inheritance

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

See Also

PdfXYZDestination Members

DevExpress.Pdf Namespace