Skip to content

Commit ee867a9

Browse files
author
Sowmiya Loganathan
committed
Added the sample
1 parent 83a92d3 commit ee867a9

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32407.343
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modify-the-redaction-annotation-in-PDF-document", "Modify-the-redaction-annotation-in-PDF-document\Modify-the-redaction-annotation-in-PDF-document.csproj", "{5D66E67B-6C9E-431A-AA29-44E78EE74F4D}"
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+
{5D66E67B-6C9E-431A-AA29-44E78EE74F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5D66E67B-6C9E-431A-AA29-44E78EE74F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5D66E67B-6C9E-431A-AA29-44E78EE74F4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5D66E67B-6C9E-431A-AA29-44E78EE74F4D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BC016595-2A60-4F64-A066-4BF54EC66492}
24+
EndGlobalSection
25+
EndGlobal
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>net6.0</TargetFramework>
6+
<RootNamespace>Modify_the_redaction_annotation_in_PDF_document</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="20.2.0.50" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Pdf.Graphics;
5+
using Syncfusion.Pdf.Interactive;
6+
using Syncfusion.Pdf.Parsing;
7+
using Syncfusion.Pdf.Redaction;
8+
9+
//Get stream from an existing PDF document.
10+
FileStream docStream = new FileStream("../../../Input.pdf", FileMode.Open, FileAccess.Read);
11+
12+
//Load the PDF document.
13+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
14+
15+
foreach (PdfAnnotation annot in loadedDocument.Pages[0].Annotations)
16+
{
17+
//Check for the Redaction annotation.
18+
if (annot is PdfLoadedRedactionAnnotation)
19+
{
20+
//Load the redaction annotation.
21+
PdfLoadedRedactionAnnotation redactAnnot = annot as PdfLoadedRedactionAnnotation;
22+
23+
//Assign the Bounds values.
24+
redactAnnot.Bounds = new RectangleF(50, 50, 100, 100);
25+
26+
//Assign the OverlayText.
27+
redactAnnot.OverlayText = "Redaction";
28+
29+
//Assign the InnerColor.
30+
redactAnnot.InnerColor = Color.Yellow;
31+
32+
//Assign the BorderColor.
33+
redactAnnot.BorderColor = Color.Green;
34+
35+
//Assign the TextColor.
36+
redactAnnot.TextColor = Color.Red;
37+
38+
//Assign the TextAlignment.
39+
redactAnnot.TextAlignment = PdfTextAlignment.Right;
40+
41+
//Assign the RepeatText.
42+
redactAnnot.RepeatText = true;
43+
44+
//Flatten the annotations in the page.
45+
redactAnnot.Flatten = true;
46+
}
47+
48+
loadedDocument.Redact();
49+
50+
//Save the document.
51+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
52+
{
53+
loadedDocument.Save(outputFileStream);
54+
}
55+
56+
//Close the document.
57+
loadedDocument.Close(true);
58+
}

0 commit comments

Comments
 (0)