使用JPedal取代PDFBox
http://wanggp.iteye.com/blog/1144177
————————————————————————————————————————————————
之前都是使用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();
评论
发现最新版本的API有些变化,PdfDecoder.setFontReplacements(decode_pdf);
变为:FontMappings.setFontReplacements(); 但是没有带参数。你的decode_pdf值是“UTF-8”?
使用JPedal取代PDFBox的更多相关文章
- 利用jpedal进行pdf转换成jpeg,jpg,png,tiff,tif等格式的图片
项目中运用到pdf文件转换成image图片,开始时使用pdfbox开源库进行图片转换,但是转换出来的文件中含有部分乱码的情况.下面是pdfBox 的pdf转换图片的代码示例. try{ String ...
- 取代SharedPreferences的多进程解决方案
Android的SharedPreferences用来存储一些键值对, 但是却不支持跨进程使用. 跨进程来用的话, 当然是放在数据库更可靠啦, 本文主要是给作者的新库PreferencesProvid ...
- pdfbox加载pdf时遇到wrappedioexception报错处理方式
现在一个项目要对pdf做处理.由于其中一个pdf约为80M左右,用pdfbox读取pdf时遇到了wrappedioexception错误.监控得到说内存不足.于是请教项目经理.他告诉我在Open De ...
- 让代码重构渐行渐远系列(3)——string.Equals取代直接比较与非比较
重构背景及原因 最近由于项目组的人员在不断扩充,导致项目中代码风格各异,大有百花齐放甚至怒放之势.考虑到团队的生存与发展,经过众人多次舌战之后,最终决定项目组根据业务分成几个小分队,以加强团队管理与提 ...
- 第1章 重构,第一个案例(3):运用多态取代switch
3. 运用多态取代与价格相关的条件逻辑 3.1 switch和“常客积分”代码的再次搬迁 (1)switch:最好不要在另一个对象的属性上运用switch语句 switch(getMovie().ge ...
- 苹果未来:增强现实设备将会取代iPhone
近日,华尔街知名度相当高的苹果分析师木斯特(Gene Munster)决定转行组建自己的风险投资公司,临走前他发布了最后一份关于苹果的研究报告,他对苹果未来的发展进行了一番预测.Munster表示,以 ...
- 远程桌面不能连接,提示awgina.dll取代错误的解决办法
远程桌面不能连接,错误提示:您不能初始化一个远程桌面连接,因为在远程计算机上的windows登录软件被不兼容的软件c:\windows\system32\awgina.dll取代,如下图所示: 原因: ...
- systemctl 取代 service
要使用systemd, linux内核版本要高于: 2.6.39 systemctl的命令格式: systemctl 动作命令(如start stop restart status) 服务名称.ser ...
- 该不该用inline-block取代float? inline和float的区别?
该不该用inline-block取代float? 请看这篇文章引用: jtyjty99999的博客 让块级元素 水平排列的通常方式是float, 但是float可能会带来很多意外的问题 可以考虑用in ...
随机推荐
- Android开发学习之SQLite数据存取浅析
一.SQLite的介绍 1.SQLite简介 SQLite是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入 式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低 ...
- jseclipse 是eclipse插件,让你编写js代码感觉更爽
一直以来都没有客意的去找一下eclipse下面的javascript开发插件,今天在网上无意发现了一个,回去试了一下,感觉不错.写JS代码根写PHP代码差不多感觉挺爽的.JSEclipse是个Ecli ...
- ISE联合modelsim功能仿真和综合后仿真1
1.代码输入 (1).新建一个ISE工程,名字为count4. (2).新建一个verilog文件 (3).选择verilog module 输入file name为count4,单击next默认知道 ...
- [na]win PPTP场景与搭建
这也是在不成熟时期的一种对windows远程访问的好奇. 现在看来没啥用了. 现在一般都用linux的openvpn+gg方案了 远程访问方案: ,端口映射 ,vpn 实现这种远程访问的协议:pptp ...
- asp.net web网站权限系统的简单设计
权限设计总结一句话就是:拥有权限的主体来管控系统的各种资源资源,及在资源上体现的各种操作. 概括来说就是,权限离不开三要素: 1:权限的主体 2:管控的资源 3:各种操作 现对三要素分别做简单的阐述 ...
- 基于jquery的邮箱输入联想插件开发
js代码: /*create by code_bunny 20140701 973295131@qq.com https://github.com/OOP-Code-Bunny */ (functio ...
- linq语法之select distinct Count Sum Min Max Avg
原文来自:http://www.50cms.com/Pages_13_72.aspx 本篇详细说明linq中的Select和Count/Sum/Min/Max/Avg等的用法. Select/Dist ...
- 山寨一个std::bind\boost::bind
这里是最初始的版本,参考https://github.com/cplusplus-study/fork_stl/blob/master/include/bind.hpp 提供了最简洁的实现方式. 第一 ...
- 通过分区(Partitioning)提高Spark的运行性能
在Sortable公司,很多数据处理的工作都是使用Spark完成的.在使用Spark的过程中他们发现了一个能够提高Sparkjob性能的一个技巧,也就是修改数据的分区数,本文将举个例子并详细地介绍如何 ...
- 使用codedom 编写脚本解释器
本篇博客的目的是为了保存例子,怕自己忘记. private void dd(string code) { string path = "BonkerSpace"; if (File ...