Class PdfLoadedAnnotation
The class provides methods and properties to handle the loaded annotations from the existing PDF document.
Implements
Inherited Members
Namespace: Syncfusion.Pdf.Interactive
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public abstract class PdfLoadedAnnotation : PdfAnnotation, IPdfWrapper, INotifyPropertyChanged
Remarks
Please refer UG documentation link for PdfSoundAnnotation from this link https://help.syncfusion.com/file-formats/pdf/working-with-annotations#sound-annotation
Examples
//Load an existing document.
PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Annotations.pdf");
//Get the annotation from loaded document.
PdfLoadedSoundAnnotation soundAnnotation = document.Pages[1].Annotations[5] as PdfLoadedSoundAnnotation;
//Get the page.
PdfLoadedPage page =soundAnnotation.Page;
//Save the document.
document.Save("SoundAnnotation.pdf");
document.Close(true);
'Load an existing document.
Dim document As New PdfLoadedDocument("..\..\Annotations.pdf")
'Gets the annotation from loaded document.
Dim soundAnnotation As PdfLoadedSoundAnnotation = document.Pages(1).Annotations(5) as PdfLoadedSoundAnnotation
'Gets the page.
Dim page As PdfLoadedPage=soundAnnotation.Page
'Save the document.
document.Save("SoundAnnotation.pdf")
document.Close(True)
Fields
ObjectID
Represents the Form field identifier
Declaration
public int ObjectID
Field Value
| Type |
|---|
| System.Int32 |
Properties
CreationDate
Gets the creation date.
Declaration
public DateTime CreationDate { get; }
Property Value
| Type | Description |
|---|---|
| System.DateTime | The creation date. |
Examples
//Load an existing document.
PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Annotations.pdf");
//Gets the annotation from loaded document.
PdfLoadedAnnotation loadedAnnotation = document.Pages[0].Annotations[0] as PdfLoadedAnnotation;
//Gets the creation date.
DateTime creationDate = loadedAnnotation.CreationDate;
//Save the document.
document.Save("output.pdf");
document.Close(true);
'Load an existing document.
Dim document As New PdfLoadedDocument("..\..\Annotations.pdf")
'Gets the annotation from loaded document.
Dim loadedAnnotation As PdfLoadedAnnotation = TryCast(document.Pages(0).Annotations(0), PdfLoadedAnnotation)
'Gets the creation date.
DateTime creationDate = loadedAnnotation.CreationDate;
'Save the document.
document.Save("output.pdf")
document.Close(True)
Page
Gets and sets the PdfLoadedPage where the annotation is present.
Declaration
public PdfLoadedPage Page { get; set; }
Property Value
| Type | Description |
|---|---|
| PdfLoadedPage | The PdfLoadedPage of the existing PDF document |
Examples
//Load an existing document.
PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Annotations.pdf");
//Get the annotation from loaded document.
PdfLoadedSoundAnnotation soundAnnotation = document.Pages[1].Annotations[5] as PdfLoadedSoundAnnotation;
//Get the page.
PdfLoadedPage page =soundAnnotation.Page;
//Save the document.
document.Save("SoundAnnotation.pdf");
document.Close(true);
'Load an existing document.
Dim document As New PdfLoadedDocument("..\..\Annotations.pdf")
'Gets the annotation from loaded document.
Dim soundAnnotation As PdfLoadedSoundAnnotation = document.Pages(1).Annotations(5) as PdfLoadedSoundAnnotation
'Gets the page.
Dim page As PdfLoadedPage=soundAnnotation.Page
'Save the document.
document.Save("SoundAnnotation.pdf")
document.Close(True)
Type
Gets the annotation type.
Declaration
public PdfLoadedAnnotationType Type { get; }
Property Value
| Type | Description |
|---|---|
| PdfLoadedAnnotationType | The annotation type. |
Examples
//Load an existing document.
PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Annotations.pdf");
//Gets the annotation from loaded document.
PdfLoadedAnnotation loadedAnnotation = document.Pages[0].Annotations[0] as PdfLoadedAnnotation;
//Gets the annotation type.
PdfLoadedAnnotationType annotationType = loadedAnnotation.Type;
//Save the document.
document.Save("output.pdf");
document.Close(true);
'Load an existing document.
Dim document As New PdfLoadedDocument("..\..\Annotations.pdf")
'Gets the annotation from loaded document.
Dim loadedAnnotation As PdfLoadedAnnotation = TryCast(document.Pages(0).Annotations(0), PdfLoadedAnnotation)
'Gets the annotation type.
PdfLoadedAnnotationType annotationType = loadedAnnotation.Type
'Save the document.
document.Save("output.pdf")
document.Close(True)
Methods
GetValues(String)
Gets the values associated with the specified key.
Declaration
public List<string> GetValues(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name value. |
Returns
| Type |
|---|
| System.Collections.Generic.List<System.String> |
SetText(String)
Sets the name of the annotation
Declaration
public void SetText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text |
Examples
//Load an existing document.
PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Annotations.pdf");
//Gets the annotation from loaded document.
PdfLoadedSoundAnnotation soundAnnotation = document.Pages[1].Annotations[5] as PdfLoadedSoundAnnotation;
//Sets the annotation text.
soundAnnotation.SetText("Sound Annotation");
//Save the document.
document.Save("SoundAnnotation.pdf");
document.Close(true);
'Load an existing document.
Dim document As New PdfLoadedDocument("..\..\Annotations.pdf")
'Gets the annotation from loaded document.
Dim soundAnnotation As PdfLoadedSoundAnnotation = document.Pages(1).Annotations(5) as PdfLoadedSoundAnnotation
'Sets the annotation text.
soundAnnotation.SetText("Sound Annotation")
'Save the document.
document.Save("SoundAnnotation.pdf")
document.Close(True)
SetValues(String, String)
Set the values associated with the specified key.
Declaration
public void SetValues(string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key value. |
| System.String | value | The value for set. |
Examples
PdfLoadedDocument ldoc = new PdfLoadedDocument("WF_48044_Annotation.pdf");
PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;
PdfLoadedAnnotationCollection annots = lpage.Annotations;
PdfLoadedCircleAnnotation Icircle = annots[64] as PdfLoadedCircleAnnotation;
//Get the author
string author = Icircle.Author;
PdfLoadedPopupAnnotationCollection collection = Icircle.ReviewHistory;
PdfLoadedPopupAnnotationCollection collectionComments = Icircle.Comments;
PdfLoadedPopupAnnotation annotation = collection[1] as PdfLoadedPopupAnnotation;
//Set Unknown state and model
annotation.SetValues("State", "StateModel");
annotation.SetValues("StateModel", "CustomState");
ldoc.Save("result.pdf");
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("WF_48044_Annotation.pdf")
Dim lpage As PdfLoadedPage = CType(ldoc.Pages(0), PdfLoadedPage)
Dim annots As PdfLoadedAnnotationCollection = lpage.Annotations
Dim Icircle As PdfLoadedCircleAnnotation = CType(annots(64), PdfLoadedCircleAnnotation)
Dim author As String = Icircle.Author
Dim collection As PdfLoadedPopupAnnotationCollection = Icircle.ReviewHistory
Dim collectionComments As PdfLoadedPopupAnnotationCollection = Icircle.Comments
Dim annotation As PdfLoadedPopupAnnotation = CType(collection(1), PdfLoadedPopupAnnotation)
'Set Unknown state and model
annotation.SetValues("State", "StateModel")
annotation.SetValues("StateModel", "CustomState")
ldoc.Save("result.pdf")
TryGetValue(String, out Object)
Gets a custom annotation value associated with the specified key.
Declaration
public bool TryGetValue(string key, out object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to the custom annotation value to retrieve. |
| System.Object | value | When this method returns, it contains the value associated with the specified key,
if the key is found; otherwise, |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Examples
// Load an existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Annotation.pdf");
// Access the first page and its annotations.
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
PdfLoadedAnnotationCollection annotations = page.Annotations;
// Retrieve a rectangle annotation.
PdfLoadedRectangleAnnotation testAnnot = annotations[0] as PdfLoadedRectangleAnnotation;
bool foundValue = testAnnot.TryGetValue("Rect", out object values);
// Check the result.
if (foundValue && values is List<string> stringValues)
{
foreach (var val in stringValues)
{
Console.WriteLine($"Found: {val}");
}
}
else
{
Console.WriteLine("No custom value found.");
}
// Dispose resources.
loadedDocument.Close(true);
loadedDocument.Dispose();
' Load the PDF document
Dim loadedDocument As New PdfLoadedDocument("Annotation.pdf")
' Access the first page
Dim page As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage)
' Get the annotation from the page
Dim annotation As PdfLoadedRectangleAnnotation = TryCast(page.Annotations(0), PdfLoadedRectangleAnnotation)
' Try to get a value by key
Dim value As Object = Nothing
If annotation.TryGetValue("Rect", value) Then
Console.WriteLine("Found value: " & value.ToString())
Else
Console.WriteLine("No value found.")
End If
' Clean up
loadedDocument.Close(True)
loadedDocument.Dispose()