Skip to main content
All docs
V24.2

PdfLinkAnnotationFacade Class

Contains members used to manage link annotations without access to their inner structure.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Core

Declaration

public class PdfLinkAnnotationFacade :
    PdfAnnotationFacade

The following members return PdfLinkAnnotationFacade objects:

Remarks

You can create a link annotation associated with a URI string or a destination (a reference to a page with specific view parameters).

The code sample below creates an annotation linked to a URI string:

uri link

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");
}

A destination includes the following view parameters:

  • The displayed document page
  • The location of the document window on this page
  • The magnification (zoom factor)

Call one of the following methods to create a destination:

View Parameters Methods
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

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

destination link

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");
}

The PdfPageFacade.Annotations property returns all page annotation properties. You can filter link annotation properties, cast them to the PdfLinkAnnotationFacade class, and use class properties to modify annotation parameters.

The code sample below changes parameters of a link annotation with the link1 name:

using DevExpress.Pdf;
using System.Linq;

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

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

    // Retrieve all link annotations
    var linkAnnotations = page.Annotations.Where(annotation => annotation.Type == PdfAnnotationType.Link);
    foreach (PdfLinkAnnotationFacade linkAnnotation in linkAnnotations)
    {
        // Change specific annotation's parameters
        if (linkAnnotation.Name == "link1")
        {
            linkAnnotation.BorderStyle = PdfBorderStyle.Dot;
            linkAnnotation.Color = new PdfRGBColor(0.36, 0.54, 0.66);
            linkAnnotation.BorderWidth = 2;
            linkAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Toggle;
        }
    }
    processor.SaveDocument("..\\..\\Result.pdf");
}

Call one of the following methods to flatten an annotation:

Method Description
PdfDocumentFacade.FlattenAnnotations Flattens document annotations.
PdfPageFacade.FlattenAnnotations Flattens annotations of a specific page.
PdfAnnotationFacade.Flatten() Flattens a specific annotation.

The code sample below flattens all link annotations on the first page:

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

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

    // Flatten all link annotations
    page.FlattenAnnotations(PdfAnnotationType.Link);
}

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all link annotations from the first page:

using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{

  // Load a document
  processor.LoadDocument("..\\..\\Document.pdf");

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

  // Retrieve all link annotations
  var links = page.Annotations.Where
    (annotation => annotation.Type == PdfAnnotationType.Link).ToList();

  // Remove all links
  foreach (PdfLinkAnnotationFacade link in links)
  {
      link.Remove();
  }
}

Inheritance

Object
PdfAnnotationFacade
PdfLinkAnnotationFacade
See Also