Itextsharp无法在c#中提取pdf unicode内容 [英] Itextsharp can't extract pdf unicode content in c#

查看:171
本文介绍了Itextsharp无法在c#中提取pdf unicode内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 itextsharp 获取pdf文件的内容,如您所见:

I am trying to get the content of pdf file using itextsharp as you can see :

static void Main(string[] args)
{
    StringBuilder text = new StringBuilder();
    using (PdfReader reader = new PdfReader(@"D:\a.pdf"))
    {
        for (int i = 1; i <= reader.NumberOfPages; i++)
        {
            text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
        }
    }
    System.IO.File.WriteAllText(@"c:/a.txt",text.ToString());
    Console.ReadLine();
}

我的pdf内容是用波斯语写的,运行上面的代码后结果如下:

My pdf content is written in Persian ,and after running the above code to result is like this :

但这不是正确的结果。我应该在中设置任何选项itextsharp

But this is not correct result.should i set any option in itextsharp

推荐答案

如果没有原始文件很难说,如果您的字符/单词放错了,那么您应该尝试使用 LocationTextExtractionStrategy 像这样:

It is hard to say without an original file but in case you have characters/words incorrectly placed then you should try to use LocationTextExtractionStrategy like this:

text.Append(PdfTextExtractor.GetTextFromPage(reader,i,new LocationTextExtractionStrategy());

这篇关于Itextsharp无法在c#中提取pdf unicode内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆