- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从java打印一个pdf文件。我尝试了很多打印pdf的方法,但都失败了。最后在stackoverflow上找到了解决方案。但我尝试运行下面的代码,但编译代码时出现问题
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper paper = new Paper();
paper.setSize(612.0, 832.0);
double margin = 10;
paper.setImageableArea(margin, margin, paper.getWidth() - margin, paper.getHeight() - margin);
pf.setPaper(paper);
pf.setOrientation(PageFormat.LANDSCAPE);
// PDFBox
PDDocument doc=PDDocument.load(file);
job.setPageable(new PDPageable(doc, job));
job.setJobName("funciona?");
if(job.printDialog()){
job.print();
}
运行代码时出现一些问题。我在下面给出错误消息
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.pdfbox.pdmodel.PDDocument.<clinit>(PDDocument.java:75)
at Main.Create_Report_Card$4.actionPerformed(Create_Report_Card.java:419)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 38 more
最佳答案
将 commons-logging jar 添加到您的项目中。如果您使用的是 mavenized 项目,请在 pom.xml 中添加其依赖项。
如果您必须手动添加 commons-logging jar,请确保它在类路径中可用。
对于maven依赖,在pom.xml中添加以下artifactId。
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
您还可以从以下 URL 搜索或下载最新版本的 jar:
http://repo1.maven.org/maven2/commons-logging/commons-logging/
关于java - 使用 PDFBox jar 文件打印 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33227115/
在 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
我是一名优秀的程序员,十分优秀!