PDFBox的PDF转图片功能

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/gykxp/article/details/5301142

在北京一起做项目的一个哥们有次问我怎样把PDF转图片,一直没有解决,最近看开源时发现了PDFBox,可以由PDF转图片,于是反编其中的部分实现代码,其中转图片的方法如下:

展开阅读全文

pdfbox图片错误

04-02

我用pdfbox做pdf转jpg图片的时候。 报了如下错误rnrn在加载PDF文件请等待...rnorg.apache.pdfbox.exceptions.WrappedIOExceptionrn at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:238)rn at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:862)rn at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:829)rn at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:800)rn at com.p2j.P2JChanger.getPageNums(P2JChanger.java:30)rn at com.p2j.P2JChanger.excute(P2JChanger.java:55)rn at com.p2j.P2J.main(P2J.java:42)rnCaused by: java.lang.OutOfMemoryError: Java heap spacern at org.apache.pdfbox.io.RandomAccessBuffer.write(RandomAccessBuffer.java:117)rn at org.apache.pdfbox.io.RandomAccessFileOutputStream.write(RandomAccessFileOutputStream.java:108)rn at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)rn at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)rn at java.io.FilterOutputStream.close(FilterOutputStream.java:140)rn at org.apache.pdfbox.pdfparser.BaseParser.parseCOSStream(BaseParser.java:448)rn at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:542)rn at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:180)rn ... 6 morernrn在网上查了一下, 好像是要安装patch补丁,补丁内容如下。rnrnIndex: src/main/java/org/apache/pdfbox/pdfparser/BaseParser.javarn===================================================================rn--- src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (revision 773978)rn+++ src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (working copy)rn@@ -351,6 +351,11 @@rn byte[] buffer = new byte[ENDSTREAM.length];rn int nextIdx = pdfSource.read(buffer) % buffer.length; rn rn+ if(nextIdx < 0) rn+ pdfSource.unread( ENDSTREAM );rn+ return;rn+ rn+ rn while(byteRead != -1 ) rn if (cmpCircularBuffer( buffer, (nextIdx-ENDSTREAM.length + buffer.length)%buffer.length, ENDSTREAM )) rn pdfSource.unread( ENDSTREAM );rnrnrn请问我怎么安装,这个补丁到。 我的pdfbox.jar文件中。来修复这个问题 论坛

没有更多推荐了,返回首页