Click here to Skip to main content
15,881,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a specific requirement of extracting images from a specific area in a pdf file.The area might be a selected or highlighted or from a given set of coordinates.

When i went through, all the approaches are to extract images and text entirely from the PDF on not in a specified location. I tried with iTextSharp,Syncfussion,Apose but couldn't figure out a better approach for this.

If somebody could help me out in this it would be greatful. Can you share your ideas and suggestion on how to implement this in .net.

Regards,
Kranthi.
Posted

1 solution

using (var pdfReader = new PdfReader(Server.MapPath(savePath1)))
{
float distanceInPixelsFromLeft = 360;
float distanceInPixelsFromBottom = 30;
float width = 120;
float height = 80;

var rect = new System.util.RectangleJ(
distanceInPixelsFromLeft,
distanceInPixelsFromBottom,
width,
height);



var filters = new RenderFilter[1];
filters[0] = new RegionTextRenderFilter(rect);

ITextExtractionStrategy strategy =
new FilteredTextRenderListener(
new LocationTextExtractionStrategy(),
filters);
try
{
var currentText = PdfTextExtractor.GetTextFromPage(
pdfReader,
c,
strategy);

currentText =
Encoding.UTF8.GetString(Encoding.Convert(
Encoding.Default,
Encoding.UTF8,
Encoding.Default.GetBytes(currentText)));

text.Append(currentText);

//Validation for text existing in the area
if (text.ToString() != "")
{
ValidateErrorMessage.Text = "Text exists in Barcode area";
ValidateErrorMessage.Visible = true;
}
else
{
ValidateErrorMessage.Text = "Barcode area is valid";
ValidateErrorMessage.Visible = true;
}
}
catch (Exception ex)
{

ValidateErrorMessage.Text = "Barcode area not valid";
ValidateErrorMessage.Visible = true;

}

pdfReader.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900