Back to Devexpress

PdfFitRectangleDestination Class

officefileapi-devexpress-dot-pdf-1be5dd49.md

latest7.0 KB
Original Source

PdfFitRectangleDestination Class

A destination that displays a specific page rectangle in the document window.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

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

The following members return PdfFitRectangleDestination objects:

Remarks

The FitR destination displays a specific page rectangle (returned by the Rectangle property) in the document window. 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 second page as follows:

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

    // Define a page rectangle
    PdfRectangle destRectangle = new PdfRectangle(50, 50, 300, 300);

    // Create a FitR destination that refers to the second page
    PdfFitRectangleDestination destination =
            new PdfFitRectangleDestination(pdfDocumentProcessor.Document.Pages[1], destRectangle);

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

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

    // Add a bookmark to the document collection
    pdfDocumentProcessor.Document.Bookmarks.Add(bookmark);

    // Save the result
    pdfDocumentProcessor.SaveDocument("out.pdf");
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  ' Load a document
  pdfDocumentProcessor.LoadDocument("Demo.pdf")

  ' Define a page rectangle
  Dim destRectangle As New PdfRectangle(50, 50, 300, 300)

  ' Create a FitR destination that refers to the second page
  Dim destination As New
    PdfFitRectangleDestination(pdfDocumentProcessor.Document.Pages(1), destRectangle)

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

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

  ' Add a bookmark to the document collection
  pdfDocumentProcessor.Document.Bookmarks.Add(bookmark)

  ' Save the result
  pdfDocumentProcessor.SaveDocument("out.pdf")
End Using

Call the PdfPageFacade.AddLinkAnnotation method and pass a PdfFitRectangleDestination 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 second page’s area as follows:

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

    // Access second page properties
    PdfPageFacade destinationPageFacade =
      pdfDocumentProcessor.DocumentFacade.Pages[1];

    // Define a page rectangle
    PdfRectangle destRectangle = new PdfRectangle(50, 50, 300, 300);

    // Create a FitR destination that refers to the second page
    PdfFitRectangleDestination destination =
      destinationPageFacade.CreateFitRectangleDestination(destRectangle);

    // Find a specific phrase
    string linkText = "JPX images";
    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;

        // Access first page properties
        PdfPageFacade pageFacade =
           pdfDocumentProcessor.DocumentFacade.Pages[linkSearchResults.PageNumber-1];

        // 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("Demo.pdf")

  ' Access second page properties
  Dim destinationPageFacade As PdfPageFacade =
    pdfDocumentProcessor.DocumentFacade.Pages(1)

  ' Define a page rectangle
  Dim destRectangle As New PdfRectangle(50, 50, 300, 300)

  ' Create a FitR destination that refers to the second page
  Dim destination As PdfFitRectangleDestination =
    destinationPageFacade.CreateFitRectangleDestination(destRectangle)

  ' Find a specific phrase
  Dim linkText As String = "JPX images"
  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

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

    ' 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 PdfFitRectangleDestination

See Also

PdfFitRectangleDestination Members

DevExpress.Pdf Namespace