PdfPageFacade.AddLinkAnnotation(PdfRectangle, PdfDestination) Method
In This Article
Creates a link annotation in the specified page rectangle.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Pdf.v24.2.Core.dll
NuGet Package: DevExpress.Pdf.Core
#Declaration
public PdfLinkAnnotationFacade AddLinkAnnotation(
PdfRectangle rect,
PdfDestination destination
)
#Parameters
Name | Type | Description |
---|---|---|
rect | Pdf |
A page area to add a link annotation. |
destination | Pdf |
A destination (a page reference with specific view parameters) to which the annotation refers. |
#Returns
Type | Description |
---|---|
Pdf |
An object that contains link annotation properties. |
#Remarks
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. | Pdf |
Fit the page’s bounding box to the document window horizontally. | Pdf |
Fit the page’s bounding box to the document window vertically. | Pdf |
Fit the entire page to the document window both horizontally and vertically (Zoom to Page Level view). | Pdf |
Fit the entire page to the document window horizontally. | Pdf |
Fit the entire page to the document window vertically. | Pdf |
Display the specified page area in the document window. | Pdf |
Position the specified page coordinate at the top left document window corner, and specify the zoom factor. | Pdf |
#Example
The code sample below creates a link annotation with a destination that displays the third page with the Zoom to Page Level view:
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");
}
See Also