Skip to content

Commit

Permalink
920569 Added widget annotation sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerkhan001 committed Nov 12, 2024
1 parent a8654b9 commit b0d3700
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modify-the-widget-annotation-in-PDF-document", "Modify-the-widget-annotation-in-PDF-document\Modify-the-widget-annotation-in-PDF-document.csproj", "{CCB9348A-9780-471A-B1D8-24302CE07ED7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CCB9348A-9780-471A-B1D8-24302CE07ED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCB9348A-9780-471A-B1D8-24302CE07ED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCB9348A-9780-471A-B1D8-24302CE07ED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCB9348A-9780-471A-B1D8-24302CE07ED7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2BEE5587-7C68-4AA1-B722-EC1E82301ABA}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Modify_the_widget_annotation_in_PDF_document</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf;

//Load the PDF document.
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
// Loop through each page in the loaded PDF document.
foreach (PdfLoadedPage page in loadedDocument.Pages)
{
// Access the form within the loaded document.
PdfLoadedForm form = loadedDocument.Form;
// Check if the forms are null.
if (form == null)
{
// Loop through each annotation on the current page.
foreach (PdfLoadedAnnotation annot in page.Annotations)
{
// Check if the annotation is a widget annotation.
if (annot is PdfLoadedWidgetAnnotation)
{
// Cast the annotation to a PdfLoadedWidgetAnnotation type.
PdfLoadedWidgetAnnotation widget = annot as PdfLoadedWidgetAnnotation;
// Set the widget's text value to "true".
widget.Text = "true";
}
}
}
}
//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);

0 comments on commit b0d3700

Please sign in to comment.