- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问候,
我目前正在尝试阅读 pdf 文档的文本。在尝试了超过 15 种不同的解决方案之后,代码仍然当我使用命令“java -jar pdfx.jar”运行它时抛出此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDocument
at com.test.pdf.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
主.java
package com.test.pdf;
import java.io.*;
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.text.PDFTextStripper;
public class Main {
public static void main(String[] args){
PDDocument pd;
BufferedWriter wr;
try {
File input = new File("C:/Users/Test/Desktop/check.pdf");
File output = new File("C:/Users/Test/Desktop/Ergebnis.txt");
pd = PDDocument.load(input);
System.out.println(pd.getNumberOfPages());
System.out.println(pd.isEncrypted());
pd.save("Copy.pdf");
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(1);
wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
stripper.writeText(pd, wr);
if (pd != null) {
pd.close();
}
wr.close();
} catch (Exception e){
e.printStackTrace();
}
}
}
还有 pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PDFReader</groupId>
<artifactId>PDFReader</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifest>
<mainClass>com.test.pdf.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.11</version>
</dependency>
</dependencies>
</project>
PdfBox 和 common-logging 的 jar 已经添加到类路径中。Build 运行正常,没有报错。pdf 文件位于我的桌面上,我在构建后将 jar 移动到那里并使用 cmd 运行它。
最佳答案
把这个插件放到你的pom中然后执行java -jar PDFReader-0.0.1-SNAPSHOT-jar-with-dependencies.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.test.pdf.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
关于java - 使用 PDFBox 并使用 Maven 构建时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52065010/
在 apache PDFBox 网站上,http://pdfbox.apache.org/2.0/migration.html ,PDF 渲染示例。 ImageIOUtil.writeImage(bi
我们正在使用 PDFBox 从 PDF 中提取文本。 某些 PDF 的文本无法正确提取。 下图显示了 PDF 中的一部分作为图像: 文本提取后,我们得到以下文本: 3, 8 5 EU R 1 Nett
任何人都可以帮我了解如何使用 Apache PDFBOX 将文本替换为图像吗? 最佳答案 import java.io.File; import java.io.IOException;
我正在升级我的项目中的库并将 pdfbox 从 0.6.7 升级到 1.6.0 版,但找不到 LucenePDFDocument 类。 Apache 页面上的文档/教程中仍然提到了该类。有任何想法吗?
在我的应用程序中,我使用 Apache PDFBox 来呈现 PDF 文件并进行静音打印。 PDFBox 可以很好地渲染 PFD,但我遇到了问题 缩放 来到图片。 在这里我想在打印 PDF 之前设置页
我正在使用使用 pdfbox 2.0.3 的 Apache Tika 1.14。 我用它来提取文件的文本内容。在生产模式下处理许多文件时,我会记录许多如下语句: WARN o.a.p.pdmodel
有人能给我一个关于如何使用 Apache PDFBox 将 PDF 文件转换为不同图像的示例吗(PDF 的每一页一个图像)? 最佳答案 1.8.* 版本的解决方案: PDDocument docume
我正在使用 PDF BOX 获取 PDF 文本的颜色信息。我可以使用以下代码获得输出。但是我的疑问是 StrokingColor 代表什么,Non stroking color 代表什么。基于此,我将
我终于成功地让 PDFBox 打印我的 unicodes。但现在,我想了解我提出的解决方案。下面的代码可以运行并将 ≥ 打印到页面上。 有两件事不起作用: 改变PDType0Font.load(doc
我正在使用 PDF BOX 获取 PDF 文本的颜色信息。我可以使用以下代码获得输出。但是我的疑问是 StrokingColor 代表什么,Non stroking color 代表什么。基于此,我将
我的项目要求在 Apache pdfbox api 的帮助下生成发票。截至目前,我可以在生成的 pdf 中插入图像、文本,但在生成表格时发现困难。我什至找不到单个示例模板。如果有人有请提供链接。 注意
我如何使用 PDFBox 2.0.0 获取字段位置?在 Pdfbox 1.8.11 中,我是这样工作的: String formTemplate = "Template.pdf
我在我们的一个项目中使用了 CMS Magnolia。在日志文件中有很多错误,例如: 字体 ArialMT 中使用的 OpenType 布局表未在 PDFBox 中实现 这对 PDF 有什么影响?可以
我一直在使用 PDFBox 1.8 来处理 pdf。现在我计划转向 PDFBox 2.0-RC-2。我在迁移时遇到一些问题。 在 PDFBox 1.8 中,我曾经使用以下方法从 PDPage 获取 t
我正在使用 PDFBox 1.7.0(由于生产服务器中的版本较旧,我无法选择该版本)。我正在尝试将图像添加到已有 Logo 的现有 PDF 中。当我添加新图像时,旧图像就像被替换一样消失了。 // U
我正在使用 Apache PDFBox 库 在可填写的 PDF 表格 (AcroFrom) 中填写信息。完成信息填写后,我需要编写一个新的PDF文件(不可编辑格式)。 我尝试了 setReadOnly
在对 PDDocument 进行数字签名后,我已关闭 Apache PDFBox 中的 PDDocument。我收到警告:当我关闭我的实例时,You did not close PDF Documen
我在 wildfly 模块中使用 Apache Tika(tika-app 1.17)。当我开始提取 PDF 时,它总是抛出错误: java.lang.NoClassDefFoundError: Co
我尝试使用 pdfbox 并使用 groovy 进行编译,但我不知道 这是我使用的代码 groovyc main.groovy 但不起作用,请帮助我 this.class.classLoader.ro
我在 wildfly 模块中使用 Apache Tika(tika-app 1.17)。当我开始提取 PDF 时,它总是抛出错误: java.lang.NoClassDefFoundError: Co
我是一名优秀的程序员,十分优秀!