Back to Devexpress

PdfPageFacade.AddLinkAnnotation(PdfRectangle, String) Method

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

latest5.0 KB
Original Source

PdfPageFacade.AddLinkAnnotation(PdfRectangle, String) Method

Creates a link annotation in the specified rectangle on the page.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfLinkAnnotationFacade AddLinkAnnotation(
    PdfRectangle rect,
    string uri
)
vb
Public Function AddLinkAnnotation(
    rect As PdfRectangle,
    uri As String
) As PdfLinkAnnotationFacade

Parameters

NameTypeDescription
rectPdfRectangle

A page area to add a link annotation.

| | uri | String |

A URI associated with the annotation.

|

Returns

TypeDescription
PdfLinkAnnotationFacade

An object that contains link annotation properties.

|

Example

The following code snippet creates an annotation linked to a URI string:

View Example

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Find the target phrase in the document
    string linkText = "Evaluation";
    PdfTextSearchResults linkSearchResults = processor.FindText(linkText);

    if (linkSearchResults.Status == PdfTextSearchStatus.Found)
    {
        PdfRectangle linkRectangle = linkSearchResults.Rectangles[0].BoundingRectangle;
        string linkUri = "https://community.devexpress.com/blogs/";

        // Add a link annotation to the found text
        PdfLinkAnnotationFacade uriAnnotation = page.AddLinkAnnotation(linkRectangle, linkUri);
        uriAnnotation.Name = "link1";
        uriAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Push;
    }
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

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

  ' Find the target phrase in the document
  Dim linkText As String = "Evaluation"
  Dim linkSearchResults As PdfTextSearchResults = processor.FindText(linkText)

  If linkSearchResults.Status = PdfTextSearchStatus.Found Then
    Dim linkRectangle As PdfRectangle = linkSearchResults.Rectangles(0).BoundingRectangle
    Dim linkUri As String = "https://community.devexpress.com/blogs/"

    ' Add a link annotation to the found text
    Dim uriAnnotation As PdfLinkAnnotationFacade = page.AddLinkAnnotation(linkRectangle, linkUri)
    uriAnnotation.Name = "link1"
    uriAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Push
  End If
  processor.SaveDocument("..\..\Result.pdf")
End Using

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddLinkAnnotation(PdfRectangle, String) 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-uri/CS/AddLinkToUri/Program.cs#L28

csharp
// Add a link annotation to the found text
PdfLinkAnnotationFacade uriAnnotation = page.AddLinkAnnotation(linkRectangle, linkUri);
uriAnnotation.Name = "link1";

pdf-document-api-add-link-to-uri/VB/AddLinkToUri/Program.vb#L26

vb
' Add a link annotation to the found text
Dim uriAnnotation As PdfLinkAnnotationFacade = page.AddLinkAnnotation(linkRectangle, linkUri)
uriAnnotation.Name = "link1"

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace