【问题标题】:Getting irregularities from java PDFBOX从java PDFBOX获取不规则
【发布时间】:2018-10-07 03:45:49
【问题描述】:

我正在使用 Java PDFBOX 2.0.12 来尝试阅读乳胶生成的 PDF。一切似乎都正常,但由于某种原因,某些值(,>=)被更改为问号(?),我收到各种警告例如“警告:字体 F18 中没有 a105 (105) 的 Unicode 映射”。任何帮助将不胜感激。

Java 代码:

try {
        PDDocument document = PDDocument.load(file);
        PDFTextStripper pdfStripper = new PDFTextStripper();

          //Retrieving text from PDF document
          String text = pdfStripper.getText(document);
          System.out.println(text);

          //Closing the document
          document.close();
    } catch (InvalidPasswordException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

乳胶代码:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\usepackage[T1]{fontenc} % font encoding
\usepackage[utf8]{inputenc}

\title{algorithmicx (algpseudocode) example}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithmic}[1]
\If{$quality\ge 9$}:
\State $a\gets perfect$
\ElsIf{$quality\ge 7$}:
\State $a\gets good$
\ElsIf{$quality\ge 5$}:
\State $a\gets medium$
\ElsIf{$quality\ge 3$}:
\State $a\gets bad$
\Else
\State $a\gets unusable$
\EndIf
\end{algorithmic}
\end{document}

生成/使用的文档:https://drive.google.com/file/d/1P16FMHc1Pkd897G448Zd_6pgmnoWQLGt/view?usp=sharing

【问题讨论】:

  • 我使用 ExtractText 命令行实用程序获得了正确的文本提取 - 可能写入文件并使用编辑器查看它。我确实得到了错误,这是因为你的字体使用了非标准的字形名称。
  • @TilmanHausherr 有没有办法解决这个问题?
  • 可能是 Latex 的问题:它使用字形的位图创建 type 3 字体,而不是使用矢量字体(例如 truetype 或 type1)。您的 PDF 在更高的分辨率下看起来很糟糕,例如在 Adob​​e Reader 中查看 600% 的“else”中的“e”。 Latex 还应该创建有效的字形名称,对于“d”,字形名称是“d”而不是“a100”。 (查看 PDFBox PDFDebugger 中的字体)出于某种原因,“质量”是使用 type1 字体完成的,这很好,但“其他”不是。
  • @tilman Hausherr,所以这是 PDF 问题? PDFBOX 是否允许我将字体替换为另一个?
  • 不是PDF问题。替换 PDF 中的字体会变得非常复杂。最好从乳胶方面解决这个问题,即找出为什么使用此位图字体打印“else”。这太80年代了。也许只用乳胶标签创建一个新问题并使用我的 cmets。建议标题:“为什么 Latex 会为我的 PDF 生成位图字体?”。提及正在使用的软件和版本。

标签: java pdf latex operators pdfbox


【解决方案1】:

正如 cmets 中所讨论的 - 该文件应该被编写为 utf8 并使用像 NOTEPAD++ 这样的良好编辑器打开。

    try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(txtFile), Charsets.UTF_8);
         PDDocument document = PDDocument.load(pdfFile))
    {
        PDFTextStripper stripper = new PDFTextStripper();
        stripper.writeText(document, out);
    }

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 2012-06-10
    • 2014-07-27
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多