使用iTextsharp从PDF提取乌尔都语文本

问题描述 投票:-1回答:1

[使用iTextsharp从pdf提取Urdu(rtl语言)文本时,它向我显示了镜像(反向)文本,请问有什么例子可以说明我如何从pdf正确提取Urdu文本?

    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(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));

                text.Append(currentText);
            }
            pdfReader.Close();
        }
        return text.ToString();
    }
c# itext
1个回答
0
投票

在波斯语中,就像乌尔都语一样,这是一种rtl语言,在使用iTextSharp进行常规提取后,我使用了自定义方法:

public string ReverseTheString(string source)
{
    try
    {
        return new string(source.ToCharArray().Reverse().ToArray());
    }
    catch (Exception ex)
    {
            return null;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.