iTextSharp的文本提取 [英] Itextsharp text extraction

查看:698
本文介绍了iTextSharp的文本提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用vb.net iTextSharp的获得从PDF文件中的文本内容。该解决方案正常工作的某些文件而​​不是其他,即使很简单的。问题是,该令牌字符串值设置为null(一组空方框)

I'm using itextsharp on vb.net to get the text content from a pdf file. The solution works fine for some files but not for other even quite simple ones. The problem is that the token stringvalue is set to null (a set of empty square boxes)

token = New iTextSharp.text.pdf.PRTokeniser(pageBytes)
    While token.NextToken()
        tknType = token.TokenType()
        tknValue = token.StringValue

我可以meassure内容的长度,但我不能得到实际的字符串内容。

I can meassure the length of the content but I cannot get the actual string content.

我意识到,这取决于PDF的字体发生。如果我创建一个使用Acrobat或使用的PDFCreator速递(由的方法是在我的Visual Studio编辑器的默认字体),我可以得到所有的文本内容的PDF文件。如果相同的PDF使用不同的字体,我得到了空方箱建造的。

I realized that this happens depending on the font of the pdf. If I create a pdf using either Acrobat or PdfCreator with Courier (that by the way is the default font in my visual studio editor) I can get all the text content. If the same pdf is built using a different font I got the empty square boxes.

现在的问题是,我怎么能不管提取字体设置文本?

Now the question is, How can I extract text regardless of the font setting?

感谢

推荐答案

马克的回答补充,可以帮助我很多.iTextSharp实现命名空间和类是从Java版本稍有不同。

complementary for Mark's answer that helps me a lot .iTextSharp implementation namespaces and classes are a bit different from java version

 public static string GetTextFromAllPages(String pdfPath)
    {
        PdfReader reader = new PdfReader(pdfPath); 

        StringWriter output = new StringWriter();  

        for (int i = 1; i <= reader.NumberOfPages; i++) 
            output.WriteLine(PdfTextExtractor.GetTextFromPage(reader, i, new SimpleTextExtractionStrategy()));

        return output.ToString();
    }

这篇关于iTextSharp的文本提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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