Skip to content

Commit e627fa0

Browse files
Merge pull request #156 from SyncfusionExamples/952337
952337 Added Get and Set values for PDF annotation sample code
2 parents 75619ac + f502e56 commit e627fa0

9 files changed

Lines changed: 139 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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Load the PDF document from the input stream
9+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream))
10+
{
11+
// Access the first page of the document
12+
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
13+
// Get the collection of annotations from the page
14+
PdfLoadedAnnotationCollection annotations = page.Annotations;
15+
16+
// Check if at least one annotation exists and it's a popup annotation
17+
if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation)
18+
{
19+
// Get the custom value from the annotation
20+
List<string> customValue = annotation.GetValues("custom");
21+
22+
foreach (string value in customValue)
23+
{
24+
// Print the custom value to the console
25+
Console.WriteLine("Custom value from annotation: " + value);
26+
}
27+
}
28+
// Close the document and release resources
29+
loadedDocument.Close(true);
30+
}
31+
}
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// Load the PDF document from the input stream
10+
using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream))
11+
{
12+
// Access the first page of the document
13+
PdfLoadedPage page = ldoc.Pages[0] as PdfLoadedPage;
14+
15+
// Get the collection of annotations from the page
16+
PdfLoadedAnnotationCollection annotations = page.Annotations;
17+
18+
// Check if at least one annotation exists and it's a popup annotation
19+
if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation)
20+
{
21+
// Set a custom key-value pair in the annotation's metadata
22+
annotation.SetValues("custom", "This is the custom data for the annotation");
23+
}
24+
25+
// Save the modified document using a new FileStream
26+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
27+
{
28+
// Save changes to a new PDF file
29+
ldoc.Save(outputStream);
30+
}
31+
// Close the document and release resources
32+
ldoc.Close(true);
33+
}
34+
}
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)