Itextsharp从pdf获取文本修饰

时间:2014-08-11 12:22:48

标签: c# itextsharp itext

我在项目中使用iTextSharp库。如何拍摄PDF线条的装饰或风格? (表示我的文字来自其他人的东西。)

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();
}

0 个答案:

没有答案