Back to Devexpress

PdfPageFacade.AddLinkAnnotation(PdfRectangle, PdfDestination) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addlinkannotation-x28-devexpress-dot-pdf-dot-pdfrectangle-devexpress-dot-pdf-dot-pdfdestination-x29.md

latest8.0 KB
Original Source

PdfPageFacade.AddLinkAnnotation(PdfRectangle, PdfDestination) Method

Creates a link annotation in the specified page rectangle.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfLinkAnnotationFacade AddLinkAnnotation(
    PdfRectangle rect,
    PdfDestination destination
)
vb
Public Function AddLinkAnnotation(
    rect As PdfRectangle,
    destination As PdfDestination
) As PdfLinkAnnotationFacade

Parameters

NameTypeDescription
rectPdfRectangle

A page area to add a link annotation.

| | destination | PdfDestination |

A destination (a page reference with specific view parameters) to which the annotation refers.

|

Returns

TypeDescription
PdfLinkAnnotationFacade

An object that contains link annotation properties.

|

Remarks

A destination includes the following view parameters:

  • The displayed document page
  • View parameters: a view mode or a specific point/region on the page to which to navigate
  • The magnification (zoom factor)

Call one of the following methods to create a destination:

View ParametersMethods
Fit the page’s bounding box to the document window both horizontally and vertically.PdfPageFacade.CreateFitBBoxDestination
Fit the page’s bounding box to the document window horizontally.PdfPageFacade.CreateFitBBoxHorizontallyDestination
Fit the page’s bounding box to the document window vertically.PdfPageFacade.CreateFitBBoxVerticallyDestination
Fit the entire page to the document window both horizontally and vertically ( Zoom to Page Level view).PdfPageFacade.CreateFitDestination
Fit the entire page to the document window horizontally.PdfPageFacade.CreateFitHorizontallyDestination
Fit the entire page to the document window vertically.PdfPageFacade.CreateFitVerticallyDestination
Display the specified page area in the document window.PdfPageFacade.CreateFitRectangleDestination
Position the specified page coordinate at the top left document window corner, and specify the zoom factor.PdfPageFacade.CreateXYZDestination

Example

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddLinkAnnotation(PdfRectangle, PdfDestination) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-add-link-to-page/CS/AddLinkToPage/Program.cs#L35

csharp
PdfLinkAnnotationFacade linkAnnotation =
    linkPageFacade.AddLinkAnnotation(linkRectangle, destination);
linkAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Push;

pdf-document-api-add-link-to-page/VB/AddLinkToPage/Program.vb#L32

vb
' and destination
Dim linkAnnotation As PdfLinkAnnotationFacade = linkPageFacade.AddLinkAnnotation(linkRectangle, destination)
linkAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Push

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace