officefileapi-devexpress-dot-pdf-dbd9f924.md
Contains members used to manage link annotations without access to their inner structure.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public class PdfLinkAnnotationFacade :
PdfAnnotationFacade
Public Class PdfLinkAnnotationFacade
Inherits PdfAnnotationFacade
The following members return PdfLinkAnnotationFacade objects:
You can create a link annotation associated with a URI string or a destination (a reference to a page with specific view parameters).
The following code snippet creates an annotation linked to a URI string:
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");
}
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
A destination includes the following view parameters:
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 following code snippet 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");
}
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 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");
}
Imports DevExpress.Pdf
Imports System.Linq
Using processor As New PdfDocumentProcessor()
' Load a document
processor.LoadDocument("..\..\Demo.pdf")
' Access the first page properties
Dim facade As PdfDocumentFacade = processor.DocumentFacade
Dim page As PdfPageFacade = facade.Pages(0)
' Retrieve all link annotations
Dim linkAnnotations = page.Annotations.Where(Function(annotation) annotation.Type = PdfAnnotationType.Link)
For Each linkAnnotation As PdfLinkAnnotationFacade In linkAnnotations
' Change specific annotation's parameters
If linkAnnotation.Name = "link1" Then
linkAnnotation.BorderStyle = PdfBorderStyle.Dot
linkAnnotation.Color = New PdfRGBColor(0.36, 0.54, 0.66)
linkAnnotation.BorderWidth = 2
linkAnnotation.HighlightMode = PdfAnnotationHighlightingMode.Toggle
End If
Next linkAnnotation
processor.SaveDocument("..\..\Result.pdf")
End Using
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);
}
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)
' Flatten all link annotations
page.FlattenAnnotations(PdfAnnotationType.Link)
End Using
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();
}
}
Imports DevExpress.Pdf
Imports System.Linq
Using processor As New PdfDocumentProcessor()
processor
'Load a document:
processor.LoadDocument("..\..\Document.pdf")
' Access the first page properties
Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)
' Retrieve all link annotations
Dim links = page.Annotations.Where
(Function(annotation) annotation.Type = PdfAnnotationType.Link).ToList()
' Remove all links
For Each link As PdfLinkAnnotationFacade In links
link.Remove()
Next link
End Using
Object PdfAnnotationFacade PdfLinkAnnotationFacade
See Also