0

I am using the iTextSharp library in my project. How can I take PDF line's decoration or style? (something that indicates my text from others.)

public static string ReadPdfFile(string fileName)
{
    StringBuilder text = new StringBuilder();

    if (File.Exists(fileName))
    {
        PdfReader pdfReader = new PdfReader(fileName);
        pdfReader.GetNamedDestinationFromStrings();
        for (int page = 1; page <= pdfReader.NumberOfPages; page++)
        {
            ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
            string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

            currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
            text.Append(currentText);
        }
        pdfReader.Close();
    }
    return text.ToString();
}
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
MehmetF
  • 61
  • 1
  • 14
  • Something like this? http://stackoverflow.com/a/6884297/231316 – Chris Haas Aug 11 '14 at 13:10
  • not like this bro. I tried this but i cant did. – MehmetF Aug 11 '14 at 13:23
  • 1
    I'm not sure what "i cant did" means. Does the code not do what you want it to do? Does it not compile? Are you looking to extract information about line drawings (rectangles, circles, etc) and not text? – Chris Haas Aug 11 '14 at 13:28
  • i used this code and didnt compile. I want like this situation. For example i have a header with 16pt and other characters 10pt. Can i seperate 2 sentences? – MehmetF Aug 11 '14 at 13:40
  • 1
    That code was written and tested on iTextSharp 5.1.1. I just tried it again using iTextSharp 5.5.0 and it still compiles and runs just fine. What version of iTextSharp are you targeting and what compiler error message are you getting? – Chris Haas Aug 11 '14 at 13:47

0 Answers0