【发布时间】:2015-05-31 18:14:20
【问题描述】:
我有一个 PDF 要阅读,这让我很抓狂。
pdf 表示客户的电费单(意大利语),他希望我从中读取文本。
现在的问题。当我将粘贴文本从 pdf 复制到记事本时,我得到一堆难以理解的字符...
经过大量研究,我找到了答案。 pdf 包含所有字体,但不包含对应于允许导出文本的 cmap。我发现this link 指的是旧版本的 itext(我使用的是 5.5.5 版)。
如果可能的话,我想要实现的是将文本从字形代码转换为 unicode。
我找到了一些对 Cmap-something 的参考,但不知道如何使用它们,而且网上显然没有示例:(
这是我尝试过的
PdfReader reader = new PdfReader("MyFile.pdf");
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
PrintWriter out = new PrintWriter(new FileOutputStream(txt));
TextExtractionStrategy strategy;
strategy = parser.processContent(1, new SimpleTextExtractionStrategy());
String text = strategy.getResultantText();
String cmapFile="UnicodeBigUnmarked";
byte[] text = encodedText.getBytes();
String cid = PdfEncodings.convertToString(text, cmapFile);
Cid 是一个漂亮的日本字符序列
还有:
FontFactory.registerDirectory("myDirectoryWithAllFonts");
就在尝试转换之前。这个解决方案似乎没有结果
我们将不胜感激。
【问题讨论】: