Skip to content

Commit 6a83b1c

Browse files
committed
952337 Added Get and Set values for PDF annotation sample code
1 parent 74361f3 commit 6a83b1c

9 files changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-value-from-PDF-annotation", "Get-value-from-PDF-annotation\Get-value-from-PDF-annotation.csproj", "{B83CBD04-0016-419B-BD77-081A35DCF2EB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B83CBD04-0016-419B-BD77-081A35DCF2EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B83CBD04-0016-419B-BD77-081A35DCF2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B83CBD04-0016-419B-BD77-081A35DCF2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B83CBD04-0016-419B-BD77-081A35DCF2EB}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Get_value_from_PDF_annotation</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Syncfusion.Pdf.Interactive;
2+
using Syncfusion.Pdf.Parsing;
3+
using Syncfusion.Pdf;
4+
5+
// Load the existing PDF document using FileStream
6+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
7+
{
8+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream))
9+
{
10+
// Get the first page
11+
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
12+
13+
// Get all annotations on the page
14+
PdfLoadedAnnotationCollection annotations = loadedPage.Annotations;
15+
16+
// Make sure the 65th annotation exists and is a circle annotation
17+
if (annotations.Count > 64 && annotations[64] is PdfLoadedCircleAnnotation circleAnnotation)
18+
{
19+
// Get the review history from the circle annotation
20+
PdfLoadedPopupAnnotationCollection reviewHistory = circleAnnotation.ReviewHistory;
21+
22+
// Ensure review history has at least two items
23+
if (reviewHistory != null && reviewHistory.Count > 1)
24+
{
25+
// Get the second popup annotation from review history
26+
PdfLoadedPopupAnnotation popupAnnotation = reviewHistory[1] as PdfLoadedPopupAnnotation;
27+
28+
if (popupAnnotation != null)
29+
{
30+
// Get values for the "State" key
31+
List<string> values = popupAnnotation.GetValues("State");
32+
foreach (string value in values)
33+
{
34+
Console.WriteLine(value);
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Set-value-from-PDF-annotation", "Set-value-from-PDF-annotation\Set-value-from-PDF-annotation.csproj", "{D4AF6325-8E64-4964-936E-4CA47FB892E4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D4AF6325-8E64-4964-936E-4CA47FB892E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D4AF6325-8E64-4964-936E-4CA47FB892E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D4AF6325-8E64-4964-936E-4CA47FB892E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D4AF6325-8E64-4964-936E-4CA47FB892E4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.

Annotation/Set-value-from-PDF-annotation/.NET/Set-value-from-PDF-annotation/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+

2+
using Syncfusion.Pdf.Interactive;
3+
using Syncfusion.Pdf.Parsing;
4+
using Syncfusion.Pdf;
5+
6+
// Load the existing PDF document using FileStream
7+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
8+
{
9+
using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream))
10+
{
11+
// Get the first page
12+
PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;
13+
14+
// Get all annotations on the page
15+
PdfLoadedAnnotationCollection annots = lpage.Annotations;
16+
17+
// Access the 65th annotation (index starts at 0)
18+
if (annots.Count > 64 && annots[64] is PdfLoadedCircleAnnotation Icircle)
19+
{
20+
// Get the author of the circle annotation
21+
string author = Icircle.Author;
22+
23+
// Get the review history and comments
24+
PdfLoadedPopupAnnotationCollection collection = Icircle.ReviewHistory;
25+
PdfLoadedPopupAnnotationCollection collectionComments = Icircle.Comments;
26+
27+
// Check if there's at least a second item in the review history
28+
if (collection != null && collection.Count > 1)
29+
{
30+
PdfLoadedPopupAnnotation annotation = collection[1] as PdfLoadedPopupAnnotation;
31+
32+
if (annotation != null)
33+
{
34+
// Set custom state and state model
35+
annotation.SetValues("State", "Unknown");
36+
annotation.SetValues("StateModel", "CustomState");
37+
}
38+
}
39+
}
40+
41+
// Save the modified document using FileStream
42+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
43+
{
44+
ldoc.Save(outputStream);
45+
}
46+
47+
ldoc.Close(true);
48+
}
49+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Set_value_from_PDF_annotation</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)