How to Read and Mark(Highlight) a pdf file using C#

≯℡__Kan透↙ 提交于 2019-12-20 04:29:10

问题


I have a pdf file which i am Reading as string page by page.Now from page 4 onwards my pdf contains billing information.These Billing information are under section for Example :- say one is Local Billing information and other is STD billing information etc.Now as per my requirement if user wants to validate Local Billing information my code should read all the Local Billing data and validate it,in case any data(row) validation gets failed it should highlight that row of the PDF File.

Here is my Code in c#

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

        if (File.Exists(fileName))
        {
            PdfReader pdfReader = new PdfReader(fileName);

            for (int page = 2; 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();
    }
}

来源:https://stackoverflow.com/questions/21850782/how-to-read-and-markhighlight-a-pdf-file-using-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!