java - 从java PDFBOX获取不规则
问题描述
我正在使用 Java PDFBOX 2.0.12 来尝试阅读乳胶生成的 PDF。一切似乎都工作正常,但由于某种原因,某些值(<、<=、>、>=)被更改为问号(?),并且我收到各种警告,例如“警告:a105 (105) 没有 Unicode 映射”字体 F18"。任何帮助将不胜感激。
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
解决方案
正如评论中所讨论的 - 该文件应该写为 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);
}
推荐阅读
- c# - 我可以通过公共空间或其他方式更改场景(价值?)吗?我不想每次都编写新代码并更改要加载的场景
- python - 如何在单词/事物词典中找到前 N 个相似词?
- python - 如果我必须直接单击横幅并在另一个选项卡上打开它,如何使用 selenium 获得重定向链?
- html - 如何在 html 和 css 中用正方形内的圆圈绘制形状?
- 3d - 绕 X 轴和 Z 轴旋转也会导致绕 Y 轴旋转?
- c# - .Net 核心实体框架 LINQ 表达式无法翻译
- php - 由于代码片段,订单摘要卡在微调器上
- java - 如何在 AnyLogic 中获取节点内的代理数量?
- svg - SVG 矩形旋转
- typescript - gatsby build → WebpackError: TypeError: Cannot read property 'pathname' of undefined