Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Image-to-Text-Replacement-in-PDF/Image-to-Text-Replacement-in-PDF.csproj" />
</Solution>
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>Image_to_Text_Replacement_in_PDF</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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

// Load the input PDF document
using (PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
// Loop through every page in the PDF
foreach (PdfLoadedPage page in document.Pages)
{
PdfLoadedPage loadedPage = page as PdfLoadedPage;
// Get graphics object to draw on the page
PdfGraphics graphics = loadedPage.Graphics;
// Get all images present in the current page
PdfImageInfo[] imageInfos = loadedPage.GetImagesInfo();
// If no images found, skip this page
if (imageInfos == null || imageInfos.Length == 0) continue;
// Font for overlay text
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f);
// Center the overlay text inside the image area
PdfStringFormat centerFormat = new PdfStringFormat
{
Alignment = PdfTextAlignment.Center,
LineAlignment = PdfVerticalAlignment.Middle
};
// Save the current graphics state
graphics.Save();
// Draw overlay text ("Image removed") on top of each image area
foreach (PdfImageInfo info in imageInfos)
{
string overlayText = "Image removed";

graphics.DrawString(
overlayText,
font,
PdfBrushes.Red,
info.Bounds, // Draw the text inside the image area
centerFormat
);
}
// Restore the graphics state after drawing
graphics.Restore();
// Remove the images from the PDF page
foreach (PdfImageInfo info in imageInfos)
{
loadedPage.RemoveImage(info);
}
}
// Save the output PDF
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}

Loading