I am using ITextSharp version 5.5.3.0 and I am trying to extract text from a pdf in C#. The pdf is a form, and not an image. This is the code:
var text = new StringBuilder();
// The PdfReader object implements IDisposable.Dispose, so you can
// wrap it in the using keyword to automatically dispose of it
using (var pdfReader = new PdfReader(inFileName))
{
// Loop through each page of the document
for (var page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
var currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
}
return text.ToString();
}
The returned text is unusable. The pdf was generated with GhostScript.
Does anyone have a suggestion regarding what the problem cound be? Or any suggestions?