java - 从 java PDFBOX 获取违规行为

标签 java pdf latex operators pdfbox

我正在使用 Java PDFBOX 2.0.12 尝试阅读 Latex 生成的 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();
    }

latex 代码:

\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

最佳答案

正如评论中所讨论的 - 文件应该编写为 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);
    }

关于java - 从 java PDFBOX 获取违规行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52685280/

相关文章:

java - 为什么这个类实现两个接口(interface),其中一个接口(interface)已经从公共(public)父类扩展?

java - Apache PDFBox - 无法读取 PDF 中的所有字段

jquery - 使用 Ajax 调用在新窗口中打开 pdf

pdf - 想要自定义或更改受密码保护的 PDF 中密码提示中显示的消息

r - 使用 R/Knitr/Rstudio 中的表包测试 latex 表内的统计数据(即卡方检验)

python - 如何在 latexpdf 输出中使用 Sphinx 获取列表周围的间距?

r - 如何使用 xtable 和 sweave 在表格中打印上标?

java - fatal error 的影响 - native 代码中发生崩溃

java - Eclipse 为可访问的代码(变体)提供死代码警告

java - 玩!根地址的框架路由通配符