之前都是使用PDFBOX0.8版本来实现PDF转为Image,0.8版本的PDFBox转为Image还有N多问题,比如部分扫描PDF无法转换、缺少字体等等问题。而且我们是修改PDFBox源代码来解决上述问题,但是还是不能解决全部问题。
JPedal是一个商业的处理PDF软件,但是JPedal有一个裁切版,裁切版JPedal使用LGPL协议进行开源,可免费使用。如下摘抄官方说明:
JPedal is a commercial PDF library, so it is not free (and it cannot realistically be because no income means no money to fund development and support). OEM customers also get access to the source code so they have free access to the product in the sense they are not limited – they can alter it if they want. Commercial users get free support in the sense we charge everyone a yearly fee to cover general support costs.
We also have a cutdown version of the PDF viewer which we release under an LGPL license. This means that you can access the source code and the jar and use them without any payment. You just have to abide by the LGPL license. In this sense it is totally free.
We build it from the full version and remove items (so it gets most bug fixes and some features). So it is free in that sense. Our hope is that it will encourage lots of people to use it, to do interesting things with it and some may become commercial clients. And we like to have a free entry-level version – it appeals to the rebel in our nature
And being a cut-down version of a commercial product means you are likely to see updates – there are several ‘dead’ free Java PDF libraries because they do not generate any revenues to put back into development and support.
选择使用JPedal替换Pdfbox出于如下方面考虑:
第一:解决扫描类PDF、缺少字体问题,不用修改源代码,解决软件后续维护升级问题。
第二:转换效率高。一个70页PDF,使用PDFBox转换时间为27秒左右,而且使用JPedal的转换时间才16秒,大大地缩短转换时间。
第三:由于只需要把PDFBox转换为Image,暂无其他需求,故裁切版JPedal已可满足需求。
下面使用JPedal 转换为图片的代码:
/** instance of PdfDecoder to convert PDF into image */
PdfDecoder decode_pdf = new PdfDecoder(true);
/** set mappings for non-embedded fonts to use */
PdfDecoder.setFontReplacements(decode_pdf);
/** open the PDF file - can also be a URL or a byte array */
decode_pdf.openPdfFileFromInputStream(in, false);
// decode_pdf.openPdfFile("C:/myPDF.pdf", "password"); //encrypted
// file
// decode_pdf.openPdfArray(bytes); //bytes is byte[] array with PDF
// decode_pdf.openPdfFileFromURL("http://www.mysite.com/myPDF.pdf",false);
/** get page 1 as an image */
// page range if you want to extract all pages with a loop
// int start = 1, end = decode_pdf.getPageCount();
int pageCount = decode_pdf.getPageCount();
if (curPage > pageCount || curPage <= 0)
curPage = pageCount;
BufferedImage img = null;
img = decode_pdf.getPageAsImage(curPage );
pageCnt=String.valueOf(pageCount);
FileOutputStream out;
out = new FileOutputStream(file);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(img);
out.close();
分享到:
相关推荐
icepdf、pdfbox、jpedal_lgpl模块代码,下载后可直接运行
0.使用了 jpedal、pdfbox、PDFRenderer、icepdf,前3个包和代码都有,最后个只有包 1.pdf转图片常用的四种方式,包和代码全有(icepdf只有包),注释也很清晰, 2.是做个老项目时找来的,要对jdk1.5用,所以基本下载...
JPedal完美破解和利用Jpedal进行PDF图片转换实例。
包含所有jpedal依赖
jpedal 纯java 对pdf进行操作
最新的jpedal开源jar包,pdf转图片等功能,jpedal_lgpl属于jpedal免费向大众开放的包
jpedal_lgpl.jar
jpedal是开源纯Java的PDF文档解析库,可以用来读取PDF文档中的文字、图形。以上文件是核心引用的jar包。
pdf转jpg pdf转pdf jpedal_lgpl及代码
jpedal-lgpl-4.74b27.jar
JPedal Source源码Eclipse项目,直接导入Eclipse能够运行View.java类
应用JPedal系统库实现将PDF文档转换为图片程序,其中的jpedal-server.jar为JPedal系统库文件,加入到系统的编译环境中,PDFPagesToHiResImages.java为代码示例,TestPDFPagesToHiResImages.java为测试的程序代码,...
该依赖包包含icepdf-core.jar、jpedal_lgpl.jar、pdfbox-1.7.1.jar、poi-2.5.1-final-20040804.jar、poi-2.5.1-final-20040804.jar、xfire-core-1.2.6.jar包。
JPedal是一个收费的PDF处理类,在官网下载的只能试用30天,非常讨厌,本花了点心血破解了,赚点资源分
LGPL版本不是破解版本,也不是试用版本不必考虑30天试用问题,开源免费版本,使用稳定,乱码问题解决。
Java的开源pdf解析器,可执行文件,可以直接运行并打开PDF文件
该解码器采用了 2007 年为 JPedal PDF 渲染器开发的 JBIG2 图像处理技术,并将其作为通用库提供给更广泛的使用。 JDeli 图像库 https://www.idrsolutions.com/jdeli 包含一个增强且速度更快的版本,并且还为 Tiff ...
已成功在实际项目中得到应用,相比pdfbox,jpedal对中文的PDF处理是非常强的。pdfbox,jpedal对中文PDF转JPG是不理想的。图片变形,无形中多了一页,而且图片的效果完全变了。本人折腾了一天的时候尝试了各种开源项目...
icepdf、pdfbox、jpedal_lgpl等jar,操作pdf转换img所需的所有jar