-
Notifications
You must be signed in to change notification settings - Fork 47
923107: Added proper code example for replacing existing image in PDF #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
Redaction/Replace-existing-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF.slnx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Solution> | ||
| <Project Path="Replace-existing-text-in-a-PDF/Replace-existing-text-in-a-PDF.csproj" Id="27ffc4d8-a2ca-4a30-aba0-80a4db3a1895" /> | ||
| </Solution> |
26 changes: 26 additions & 0 deletions
26
...n/Replace-existing-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/App.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> | ||
| </startup> | ||
| <runtime> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" /> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Syncfusion.Licensing" publicKeyToken="632609b4d040f6b4" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-32.2462.5.0" newVersion="32.2462.5.0" /> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Syncfusion.Compression.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-100.2460.1.0" newVersion="100.2460.1.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| </runtime> | ||
| </configuration> | ||
Binary file added
BIN
+205 KB
...place-existing-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/Data/Input.pdf
Binary file not shown.
Empty file.
50 changes: 50 additions & 0 deletions
50
...n/Replace-existing-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System.Drawing; | ||
| using Syncfusion.Pdf; | ||
| using Syncfusion.Pdf.Graphics; | ||
| using Syncfusion.Pdf.Parsing; | ||
| using Syncfusion.Pdf.Redaction; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
|
|
||
| namespace Replace_existing_text_in_a_PDF | ||
| { | ||
| internal class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| // Load the PDF document | ||
| using (PdfLoadedDocument ldoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) | ||
| { | ||
| // Dictionary to store the found text bounds for each page | ||
| Dictionary<int, List<RectangleF>> matchedTextbounds = new Dictionary<int, List<RectangleF>>(); | ||
| // Get the first page of the PDF | ||
| PdfLoadedPage page = ldoc.Pages[0] as PdfLoadedPage; | ||
| // Search for the text and get its bounding rectangles | ||
| ldoc.FindText("Fusce", out matchedTextbounds); | ||
| // Loop through each page with matches | ||
| for (int i = 0; i < matchedTextbounds.Count; i++) | ||
| { | ||
| // Get all rectangles where the text was found on this page | ||
| List<RectangleF> rectangles = matchedTextbounds[i]; | ||
| // Loop through each found rectangle | ||
| for (int j = 0; j < rectangles.Count; j++) | ||
| { | ||
| // Create a redaction area with transparent fill over the found text | ||
| PdfRedaction redaction = new PdfRedaction(rectangles[j], Color.Transparent); | ||
| // Draw the replacement text on the redaction area | ||
| redaction.Appearance.Graphics.DrawString( | ||
| "Hello", | ||
| new PdfStandardFont(PdfFontFamily.Helvetica, 9), | ||
| PdfBrushes.Black, | ||
| PointF.Empty | ||
| ); | ||
| // Add the redaction to the page | ||
| page.AddRedaction(redaction); | ||
| } | ||
| } | ||
| // Save the PDF document | ||
| ldoc.Save(Path.GetFullPath(@"Output/Output.pdf")); | ||
| } | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...ng-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: AssemblyTitle("Replace-existing-text-in-a-PDF")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("Replace-existing-text-in-a-PDF")] | ||
| [assembly: AssemblyCopyright("Copyright © 2026")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // Setting ComVisible to false makes the types in this assembly not visible | ||
| // to COM components. If you need to access a type in this assembly from | ||
| // COM, set the ComVisible attribute to true on that type. | ||
| [assembly: ComVisible(false)] | ||
|
|
||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
| [assembly: Guid("27ffc4d8-a2ca-4a30-aba0-80a4db3a1895")] | ||
|
|
||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
67 changes: 67 additions & 0 deletions
67
...a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/Replace-existing-text-in-a-PDF.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
| <ProjectGuid>{27FFC4D8-A2CA-4A30-ABA0-80A4DB3A1895}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>Replace_existing_text_in_a_PDF</RootNamespace> | ||
| <AssemblyName>Replace-existing-text-in-a-PDF</AssemblyName> | ||
| <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
| <Deterministic>true</Deterministic> | ||
| <NuGetPackageImportStamp> | ||
| </NuGetPackageImportStamp> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>true</Optimize> | ||
| <OutputPath>bin\Release\</OutputPath> | ||
| <DefineConstants>TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Reference Include="Syncfusion.Compression.Base, Version=32.2462.5.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL"> | ||
| <HintPath>..\packages\Syncfusion.Compression.Base.32.2.5\lib\net462\Syncfusion.Compression.Base.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="Syncfusion.Licensing, Version=32.2462.5.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL"> | ||
| <HintPath>..\packages\Syncfusion.Licensing.32.2.5\lib\net462\Syncfusion.Licensing.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="Syncfusion.Pdf.Base, Version=32.2462.5.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL"> | ||
| <HintPath>..\packages\Syncfusion.Pdf.WinForms.32.2.5\lib\net462\Syncfusion.Pdf.Base.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Core" /> | ||
| <Reference Include="System.Drawing" /> | ||
| <Reference Include="System.Numerics" /> | ||
| <Reference Include="System.Xml.Linq" /> | ||
| <Reference Include="System.Data.DataSetExtensions" /> | ||
| <Reference Include="Microsoft.CSharp" /> | ||
| <Reference Include="System.Data" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Xml" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Program.cs" /> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="App.config" /> | ||
| <None Include="packages.config" /> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| </Project> |
6 changes: 6 additions & 0 deletions
6
...lace-existing-text-in-a-PDF/.NET Framework/Replace-existing-text-in-a-PDF/packages.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Syncfusion.Compression.Base" version="100.2.38" targetFramework="net48" /> | ||
|
sameerkhan001 marked this conversation as resolved.
Outdated
|
||
| <package id="Syncfusion.Licensing" version="32.2.5" targetFramework="net48" /> | ||
| <package id="Syncfusion.Pdf.WinForms" version="32.2.5" targetFramework="net48" /> | ||
| </packages> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.