这是我第一次来这里,我没有找到任何解决问题的办法。如果我的课文坏了,请不要以为是错的。
对于我的程序,我想调整现有PDF文档中的图像大小。这应该在Java程序中自动发生。在我的搜索过程中,我在网上找到了Ghost4j库,它可以解决我的问题--也许吧!
作为第一次用Ghost4j测试它是否有效,我想从MySQL数据库中加载我的PDF文档,并查看pageCount。
这是我的简短代码:
...
for (File file : convertableFiles) {
InputStream inputStream = new ByteArrayInputStream(file.getFile());
PDFDocument doc = new PDFDocument();
doc.load(inputStream);
System.out.println(doc.getPageCount());
}
...错误出现在第45行= doc.load(inputStream)
(注意:如果我为doc.load使用了新文件(路径)并设置了一个pdfSample文档。它起作用了。但不包括inputStream)
当我执行我的程序时,我每次都会得到这个异常:
Sep 29, 2014 4:54:53 PM ch.carauktion.dbresize.DBFileResizer convert
INFORMATION: P1 (asc): 0 / 1
Sep 29, 2014 4:54:54 PM ch.carauktion.dbresize.DBFileResizer run
SCHWERWIEGEND: P1 (asc): Exception
java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString
at com.lowagie.text.pdf.PdfEncryption.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfReader.readDecryptedDocObj(Unknown Source)
at com.lowagie.text.pdf.PdfReader.readDocObj(Unknown Source)
at com.lowagie.text.pdf.PdfReader.readPdf(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
at org.ghost4j.document.PDFDocument.load(PDFDocument.java:45)
at ch.carauktion.dbresize.pdf.DBPdfResizer.convertFiles(DBPdfResizer.java:50)
at ch.carauktion.dbresize.DBFileResizer.convert(DBFileResizer.java:114)
at ch.carauktion.dbresize.DBFileResizer.run(DBFileResizer.java:59)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.ASN1OctetString
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 10 more对于此项目,实现库,所有这些库都来自下载的ghost4j包:
在我搜索此错误时的示例站点:
http://sourceforge.net/p/itext/mailman/itext-questions/thread/4F422974.1070002@redlab.be/
http://itext-general.2136553.n4.nabble.com/java-lang-NoClassDefFoundError-org-bouncycastle-asn1-ASN1OctetString-td3427288.html
我知道iText 2.1.7不再受支持了,我应该使用5.x.x版本,但是在这里下载最新的iText Lib并不有效,因为在Ghost4j Jar中显然使用了LIB2.1.7。否则,可能是我的错,我现在还不明白如何正确地实现最新版本。
PS:我使用Java 1.7,8.1
我会很高兴,有人知道任何解决办法,或可以帮助我一点。
乌德曼
发布于 2014-09-29 16:28:52
你错过了邦西城堡的依赖。
我不认为PDF库会依赖于此,除非需要保护PDF,但是您可以在这里找到Bouncy城堡:releases.html
尝试使用bcprov-jdk14-147.jar和/或可从Maven中央存储库下载的bcprov-ext-jdk14-147.jar
如果这仍然不起作用,请尝试使用下面列出的其他排除的依赖项:
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<artifactId>bcmail-jdk14</artifactId>
<groupId>bouncycastle</groupId>
</exclusion>
<exclusion>
<artifactId>bcmail-jdk14</artifactId>
<groupId>org.bouncycastle</groupId>
</exclusion>
<exclusion>
<artifactId>bcprov-jdk14</artifactId>
<groupId>bouncycastle</groupId>
</exclusion>
<exclusion>
<artifactId>bcprov-jdk14</artifactId>
<groupId>org.bouncycastle</groupId>
</exclusion>
<exclusion>
<artifactId>bctsp-jdk14</artifactId>
<groupId>org.bouncycastle</groupId>
</exclusion>
</exclusions>
</dependency>注意:您应该使用Maven来获取这些依赖项。
https://stackoverflow.com/questions/26104058
复制相似问题