Back to Devexpress

PdfFitDestination Class

officefileapi-devexpress-dot-pdf-6c59dbc9.md

latest6.3 KB
Original Source

PdfFitDestination Class

A destination that displays a page that fits the document window.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

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

The following members return PdfFitDestination objects:

Remarks

The Fit destination displays a page that fits the document window. You can associate any number of bookmarks and link annotations with a destination.

Associate the Bookmark with a Destination

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

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

    // Create a Fit destination that refers to the third page
    PdfFitDestination destination =
      new PdfFitDestination(pdfDocumentProcessor.Document.Pages[2]);

    // Create a bookmark
    PdfBookmark bookmark = new PdfBookmark();
    bookmark.Title = "JBIG2 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")

  ' Create a Fit destination that refers to the third page
  Dim destination As New
    PdfFitDestination(pdfDocumentProcessor.Document.Pages(2))

  ' Create a bookmark
  Dim bookmark As New PdfBookmark()
  bookmark.Title = "JBIG2 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 PdfFitDestination object as a parameter to create a link annotation associated with a destination.

The following code snippet creates a link annotation with a destination that displays the third page with the Zoom to Page Level view:

View Example

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

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

    // Create a Fit destination that refers to the third page
    PdfFitDestination destination = pageFacade.CreateFitDestination();

    // Find a specific phrase
    string linkText = "JBIG2 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 linkPageFacade =
           pdfDocumentProcessor.DocumentFacade.Pages[linkSearchResults.PageNumber -1];

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

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

  ' Create a Fit destination that refers to the third page
    Dim destination As PdfFitDestination = pageFacade.CreateFitDestination()

  ' Find a specific phrase
  Dim linkText As String = "JBIG2 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 first page properties
    Dim linkPageFacade As PdfPageFacade = pdfDocumentProcessor.DocumentFacade.Pages(linkSearchResults.PageNumber -1)

    'Create a link annotation associated with the bounding rectangle
    ' and destination
    Dim linkAnnotation As PdfLinkAnnotationFacade =
       linkPageFacade.AddLinkAnnotation(linkRectangle, destination)
    linkAnnotation.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 PdfFitDestination

See Also

PdfFitDestination Members

DevExpress.Pdf Namespace