Back to Devexpress

PdfFitHorizontallyDestination Class

officefileapi-devexpress-dot-pdf-7ba7ab6a.md

latest7.8 KB
Original Source

PdfFitHorizontallyDestination Class

A destination that positions a specific Y coordinate at the top left corner of the document window, and zooms a page so that it fits the window horizontally.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

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

The following members return PdfFitHorizontallyDestination objects:

Remarks

The FitH destination displays a page as follows:

  • A specific Y coordinate (returned by the Top property) is positioned at the top left corner of the document window.
  • The entire page fits the document window vertically (the Fit Width zoom).

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

Associate a Bookmark with a Destination

The code sample below creates a bookmark with a destination that displays the first page as follows:

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

    // Find a specific phrase
    PdfTextSearchResults textSearchResults = pdfDocumentProcessor.FindText("Total:");

    // If the phrase is found, obtain the page that contains it
    // and the top vertical coordinate of the phrase's rectangle
    if (textSearchResults.Status == PdfTextSearchStatus.Found)
    {
        PdfPage destinationPage = textSearchResults.Page;
        double top = textSearchResults.Rectangles[0].Top;

        // create FitH a destination
        // that positions the phrase at the top left window corner
        PdfFitHorizontallyDestination destination =
              new PdfFitHorizontallyDestination(destinationPage, top);

        // Create a bookmark
        PdfBookmark bookmark = new PdfBookmark();
        bookmark.Title = "Total";

        // Associate the bookmark with the created destination
        bookmark.Destination = destination;

        // Add a bookmark to the collection
        pdfDocumentProcessor.Document.Bookmarks.Add(bookmark);
    }
    pdfDocumentProcessor.SaveDocument("out.pdf");
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  ' Load a document
  pdfDocumentProcessor.LoadDocument("Roll Paper.pdf")

  ' Find a specific phrase
  Dim textSearchResults As PdfTextSearchResults = pdfDocumentProcessor.FindText("Total:")

  ' If the phrase is found,obtain the page that contains it
  ' and the top vertical coordinate of the phrase's rectangle
  If textSearchResults.Status = PdfTextSearchStatus.Found Then
    Dim destinationPage As PdfPage = textSearchResults.Page
    Dim top As Double = textSearchResults.Rectangles(0).Top

    ' Create a FitH destination
    ' that positions the phrase at the top left window corner
    Dim destination As
        New PdfFitHorizontallyDestination(destinationPage, top)

    ' Create a bookmark
    Dim bookmark As New PdfBookmark()
    bookmark.Title = "Total"

    ' Associate the bookmark with the created destination
    bookmark.Destination = destination

    ' Add a bookmark to the collection
    pdfDocumentProcessor.Document.Bookmarks.Add(bookmark)
  End If
  pdfDocumentProcessor.SaveDocument("out.pdf")
End Using

Call the PdfPageFacade.AddLinkAnnotation method and pass a PdfFitHorizontallyDestination 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 third page as follows:

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

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

    // Access third page properties
    PdfPageFacade destinationPageFacade =
      pdfDocumentProcessor.DocumentFacade.Pages[2];

    // Create a FitH destination that refers to the fourth page
    PdfFitHorizontallyDestination destination =
      destinationPageFacade.CreateFitHorizontallyDestination(134);

    // Find a specific phrase
    string linkText = "Rattlesnake Canyon Grocery Total";
    PdfTextSearchResults linkSearchResults =
      pdfDocumentProcessor.FindText(linkText);

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

        // Create a link annotation associated with the bounding rectangle
        // and destination
        PdfLinkAnnotationFacade pdfLink =
          pageFacade.AddLinkAnnotation(linkRectangle, destination);
        pdfLink.HighlightMode = PdfAnnotationHighlightingMode.Push;
    }
    // Save the result
    pdfDocumentProcessor.SaveDocument("out.pdf");
    }
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  ' Load a document
  pdfDocumentProcessor.LoadDocument("Roll Paper.pdf")

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

  ' Access third page properties
  Dim destinationPageFacade As PdfPageFacade =
    pdfDocumentProcessor.DocumentFacade.Pages(2)

  ' Create a destination that refers to the fourth page
  Dim destination As PdfFitHorizontallyDestination =
    destinationPageFacade.CreateFitHorizontallyDestination(134)

  ' Find a specific phrase
  Dim linkText As String = "Rattlesnake Canyon Grocery Total"
  Dim linkSearchResults As PdfTextSearchResults =
    pdfDocumentProcessor.FindText(linkText)

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

    ' Create a link annotation associated with the bounding rectangle
    ' and destination
    Dim pdfLink As PdfLinkAnnotationFacade =
      pageFacade.AddLinkAnnotation(linkRectangle, destination)
    pdfLink.HighlightMode = PdfAnnotationHighlightingMode.Push
  End If
  ' Save the result
  pdfDocumentProcessor.SaveDocument("out.pdf")
End Using

Inheritance

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

See Also

PdfFitHorizontallyDestination Members

DevExpress.Pdf Namespace