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();
评论
3 楼 tyl 2013-04-07  
最新版的jpedal jar包能否提供一个,我下载的好像不是最新的,方法没法用,谢谢
2 楼 jinxiongyi 2012-05-10  
转成图片的质量是怎么调的?我转的,,感觉不够清晰
1 楼 melin 2011-12-12  
我现在最新版本的jpedal,转换为png的时候,中文不能显示。你是怎么处理的?

发现最新版本的API有些变化,PdfDecoder.setFontReplacements(decode_pdf); 
变为:FontMappings.setFontReplacements(); 但是没有带参数。你的decode_pdf值是“UTF-8”?

使用JPedal取代PDFBox的更多相关文章

  1. 利用jpedal进行pdf转换成jpeg,jpg,png,tiff,tif等格式的图片

    项目中运用到pdf文件转换成image图片,开始时使用pdfbox开源库进行图片转换,但是转换出来的文件中含有部分乱码的情况.下面是pdfBox 的pdf转换图片的代码示例. try{ String ...

  2. 取代SharedPreferences的多进程解决方案

    Android的SharedPreferences用来存储一些键值对, 但是却不支持跨进程使用. 跨进程来用的话, 当然是放在数据库更可靠啦, 本文主要是给作者的新库PreferencesProvid ...

  3. pdfbox加载pdf时遇到wrappedioexception报错处理方式

    现在一个项目要对pdf做处理.由于其中一个pdf约为80M左右,用pdfbox读取pdf时遇到了wrappedioexception错误.监控得到说内存不足.于是请教项目经理.他告诉我在Open De ...

  4. 让代码重构渐行渐远系列(3)——string.Equals取代直接比较与非比较

    重构背景及原因 最近由于项目组的人员在不断扩充,导致项目中代码风格各异,大有百花齐放甚至怒放之势.考虑到团队的生存与发展,经过众人多次舌战之后,最终决定项目组根据业务分成几个小分队,以加强团队管理与提 ...

  5. 第1章 重构,第一个案例(3):运用多态取代switch

    3. 运用多态取代与价格相关的条件逻辑 3.1 switch和“常客积分”代码的再次搬迁 (1)switch:最好不要在另一个对象的属性上运用switch语句 switch(getMovie().ge ...

  6. 苹果未来:增强现实设备将会取代iPhone

    近日,华尔街知名度相当高的苹果分析师木斯特(Gene Munster)决定转行组建自己的风险投资公司,临走前他发布了最后一份关于苹果的研究报告,他对苹果未来的发展进行了一番预测.Munster表示,以 ...

  7. 远程桌面不能连接,提示awgina.dll取代错误的解决办法

    远程桌面不能连接,错误提示:您不能初始化一个远程桌面连接,因为在远程计算机上的windows登录软件被不兼容的软件c:\windows\system32\awgina.dll取代,如下图所示: 原因: ...

  8. systemctl 取代 service

    要使用systemd, linux内核版本要高于: 2.6.39 systemctl的命令格式: systemctl 动作命令(如start stop restart status) 服务名称.ser ...

  9. 该不该用inline-block取代float? inline和float的区别?

    该不该用inline-block取代float? 请看这篇文章引用: jtyjty99999的博客 让块级元素 水平排列的通常方式是float, 但是float可能会带来很多意外的问题 可以考虑用in ...

随机推荐

  1. Android应用程序结构总结

    Android应用程序结构分析 由于是初学者,对于Android应用程序的结构的认识是一穷二白的,对于开发Android应用程序,必须先了解其程序的结构和作用.一下就用一个简单的例子来解剖: 从上图的 ...

  2. 1.Java基础-面向对象编程思想(封装继承多态接口)

    封装: 1.定义:隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别. 2.封装的目的是:增强安全性和简化编程,使用者不必了解具体的实现细节,而只是要通过外部接口,一特定的 ...

  3. AP_付款方式汇总:标准付款、退款退货付款、撤销付款(概念)

    2014-06-04 Created By BaoXinjian

  4. socket 请求接收完整的一个http响应(设置recv 接收超时选项SO_RCVTIMEO)

    在前面的系列网络编程文章中,我们都是使用socket 自己实现客户端和服务器端来互相发数据测试,现在尝试使用socket 客户端发 送http 请求给某个网站,然后接收网站的响应数据.http 协议参 ...

  5. 浅析I/O模型

    以下是本文的目录大纲: 一.什么是同步?什么是异步? 二.什么是阻塞?什么是非阻塞? 三.什么是阻塞IO?什么是非阻塞IO? 四.什么是同步IO?什么是异步IO? 五.五种IO模型 六.两种高性能IO ...

  6. RichTextBox指定全部文字显示不同颜色及部分文字高亮颜色显示

    指定全部显示不同颜色: public void SetTextContent(string text, ColorEnum color) { Font font = , FontStyle.Bold) ...

  7. swagger and restful api 参考

      http://git.oschina.net/redArmy/spring-cloud-books/blob/master/spring-cloud-provider-book/src/main/ ...

  8. mysql-5.7 innodb_buffer_pool刷新机制详解

    一.innodb的脏页刷新机制说明: 1.当innodb中的脏页比例超过innodb_max_dirty_pages_pct_lwm的值时,这个时候innodb就会开始刷新脏页到磁盘. 2.当inno ...

  9. Java:多线程,分别用Thread、Runnable、Callable实现线程

    并发性(concurrency)和并行性(parallel)是两个概念,并行是指在同一时刻,有多条指令在多个处理器上同时执行:并发指在同一时刻只能有一条指令执行,但多个进程指令被快速轮换执行,使得宏观 ...

  10. BestCoder Round #4 Miaomiao&#39;s Geometry (暴力)

    Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...