Back to Devexpress

PdfFitBBoxDestination Class

officefileapi-devexpress-dot-pdf-c8bbec00.md

latest6.2 KB
Original Source

PdfFitBBoxDestination Class

A destination that displays a page’s bounding box that fits the document window.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

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

The following members return PdfFitBBoxDestination objects:

Remarks

The FitB destination displays a page’s bounding box that fits the document window. You can associate any number of bookmarks and link annotations with a destination.

Associate a Bookmark with a Destination

The following code snippet creates a bookmark with a destination that displays the eighth page as follows:

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

    // Create a FitB destination that refers to the eighth page
    PdfFitBBoxDestination destination =
       new PdfFitBBoxDestination(pdfDocumentProcessor.Document.Pages[7]);

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

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

    // Add the 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 FitB destination that refers to the eighth page
  Dim destination As New PdfFitBBoxDestination
    (pdfDocumentProcessor.Document.Pages(1))

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

  ' 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 PdfFitBBoxDestination 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 eighth page as follows:

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

    // Access eighth page properties
    PdfPageFacade pageFacade = pdfDocumentProcessor.DocumentFacade.Pages[7];

    // Create a FitBBox destination that refers to the eighth page
    PdfFitBBoxDestination destination = pageFacade.CreateFitBBoxDestination();

    // Find a specific phrase
    PdfTextSearchResults searchResults = pdfDocumentProcessor.FindText("Annotations");

    // If the phrase is found, obtain its bounding rectangle
    if (searchResults.Status == PdfTextSearchStatus.Found)
    {
        PdfPageFacade linkPageFacade =
          pdfDocumentProcessor.DocumentFacade.Pages[searchResults.PageNumber - 1];
        PdfRectangle annotationRectangle = searchResults.Rectangles[0].BoundingRectangle;

        // Create a link annotation associated with the bounding rectangle
        // and destination
        PdfLinkAnnotationFacade linkAnnotation =
          linkPageFacade.AddLinkAnnotation(annotationRectangle, 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 eighth page properties
  Dim pageFacade As PdfPageFacade = pdfDocumentProcessor.DocumentFacade.Pages(7)

  ' Create a destination that refers to the eighth page
  Dim destination As PdfFitBBoxDestination = pageFacade.CreateFitBBoxDestination()

  ' Find a specific phrase
  Dim searchResults As PdfTextSearchResults = pdfDocumentProcessor.FindText("Annotations")

  ' If the phrase if found, obtain its bounding rectangle
  If searchResults.Status = PdfTextSearchStatus.Found Then
    Dim linkPageFacade As PdfPageFacade =
      pdfDocumentProcessor.DocumentFacade.Pages(searchResults.PageNumber - 1)
    Dim annotationRectangle As PdfRectangle = searchResults.Rectangles(0).BoundingRectangle

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

See Also

PdfFitBBoxDestination Members

DevExpress.Pdf Namespace