Using C#
public string[] ReadPdfFiles(string filepath, int pageno, int cordinate1, int coordinate2, int coordinate3, int coordinate4)
{
PdfReader reader = new PdfReader(filepath);
string text = string.Empty;
string[] words = null;
try
{
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(cordinate1, coordinate2, coordinate3, coordinate4);
RenderFilter[] renderFilter = new RenderFilter[1];
renderFilter[0] = new RegionTextRenderFilter(rect);
ITextExtractionStrategy textExtractionStrategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), renderFilter);
text = PdfTextExtractor.GetTextFromPage(reader, pageno, textExtractionStrategy);
words = text.Split('\n');
return words;
}
catch (Exception Ex)
{
reader.Close();
return words;
}
finally
{
reader.Close();
}
}
Using VB.Net
Public Function ReadPdfFiles(filepath As String, pageno As Integer, cordinate1 As Integer, coordinate2 As Integer, coordinate3 As Integer, coordinate4 As Integer) As String()
Dim reader As New PdfReader(filepath)
Dim text As String = String.Empty
Dim words As String() = Nothing
Try
Dim rect As New iTextSharp.text.Rectangle(cordinate1, coordinate2, coordinate3, coordinate4)
Dim renderFilter As RenderFilter() = New RenderFilter(0) {}
renderFilter(0) = New RegionTextRenderFilter(rect)
Dim textExtractionStrategy As ITextExtractionStrategy = New FilteredTextRenderListener(New LocationTextExtractionStrategy(), renderFilter)
text = PdfTextExtractor.GetTextFromPage(reader, pageno, textExtractionStrategy)
words = text.Split(ControlChars.Lf)
Return words
Catch Ex As Exception
reader.Close()
Return words
Finally
reader.Close()
End Try
End Function