原地址:http://www.doc100.net/bugs/t/85462/index.html

PDFBox 与 PDFRender在转换时有清晰度与效率的问题,

PDFBox转换效果稍好,PDFRender更快,但是多线程操作不能大幅提高转换效率。

package com.zas.ice.test;
/** Copyright 2006-2013 ICEsoft Technologies Inc.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the* License. You may obtain a copy of the License at**        http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing,* software distributed under the License is distributed on an "AS* IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either* express or implied. See the License for the specific language* governing permissions and limitations under the License.*/import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.PDimension;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;
import org.icepdf.ri.util.FontPropertiesManager;
import org.icepdf.ri.util.PropertiesManager;import javax.imageio.ImageIO;import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;/*** The <code>PageCapture</code> class is an example of how to save page* captures to disk.  A file specified at the command line is opened and every* page in the document is captured as an image and saved to disk as a* PNG graphic file.** @since 5.0*/
public class PageCapture {static String outputFilePath = "D:\\pdf\\Linux命令行技术大全222222\\";public static void main(String[] args) {// Get a file from the command line to openString filePath = "D:\\pdf\\面向对象软件构造(第二版)中英对照版.pdf";// read/store the font cache.ResourceBundle messageBundle = ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE);PropertiesManager properties = new PropertiesManager(System.getProperties(),ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));new FontPropertiesManager(properties, System.getProperties(), messageBundle);// start the capturePageCapture pageCapture = new PageCapture();pageCapture.capturePages(filePath);}public void capturePages(String filePath) {long beginTime = System.nanoTime();// open the urlDocument document = new Document();// setup two threads to handle image extraction.ExecutorService executorService = Executors.newFixedThreadPool(100);try {document.setFile(filePath);// create a list of callables.int pages = document.getNumberOfPages();java.util.List<Callable<Void>> callables = new ArrayList<Callable<Void>>(pages);for (int i = 0; i <= pages; i++) {callables.add(new CapturePage(document, i));}executorService.invokeAll(callables);executorService.submit(new DocumentCloser(document)).get();} catch (InterruptedException e) {System.out.println("Error parsing PDF document " + e);} catch (ExecutionException e) {System.out.println("Error parsing PDF document " + e);} catch (PDFException ex) {System.out.println("Error parsing PDF document " + ex);} catch (PDFSecurityException ex) {System.out.println("Error encryption not supported " + ex);} catch (FileNotFoundException ex) {System.out.println("Error file not found " + ex);} catch (IOException ex) {System.out.println("Error handling PDF document " + ex);}executorService.shutdown();long endTime = System.nanoTime();System.out.println("耗时: " + (endTime - beginTime) / 1000000000 + " 秒" );}/*** Captures images found in a page  parse to file.*/public class CapturePage implements Callable<Void> {private Document document;private int pageNumber;private float scale = 1f;private float rotation = 0f;private CapturePage(Document document, int pageNumber) {this.document = document;this.pageNumber = pageNumber;}public Void call() {Page page = document.getPageTree().getPage(pageNumber);page.init();PDimension sz = page.getSize(Page.BOUNDARY_CROPBOX, rotation, scale);int pageWidth = (int) sz.getWidth();int pageHeight = (int) sz.getHeight();BufferedImage image = new BufferedImage(pageWidth,pageHeight,BufferedImage.TYPE_INT_RGB);Graphics g = image.createGraphics();page.paint(g, GraphicsRenderingHints.PRINT,Page.BOUNDARY_CROPBOX, rotation, scale);g.dispose();// capture the page image to filetry {System.out.println("Capturing page " + pageNumber);File file = new File(outputFilePath + "imageCapture_" + pageNumber + ".png");ImageIO.write(image, "png", file);} catch (Throwable e) {e.printStackTrace();}image.flush();return null;}}/*** Disposes the document.*/public class DocumentCloser implements Callable<Void> {private Document document;private DocumentCloser(Document document) {this.document = document;}public Void call() {if (document != null) {document.dispose();System.out.println("Document disposed");}return null;}}
}

代码用到了JDK的线程池,也用到了任务callable,算是涨涨见识了

在转换的效果上比PDFRender略好,与PDFBox差不远;在转换的效率上,比PDFBox好很多,比PDFRender略差。

资料包是从一位Iteye用户那里下的,但是记不住他的链接了。

IcePdf官网 http://www.icesoft.org/java/home.jsf

icepdf 将pdf转换为图片相关推荐

  1. java+icepdf+下载,Java中使用icepdf轻松把pdf转换为图片

    Java中使用icepdf轻松把pdf转换为图片 icepdf简介: icepdf是java的一个专门处理pdf的外置的扩展包,使用它可以方便的把pdf转换为图片,当然它的功能不止如此,大家如果想要深 ...

  2. 【Python】PyMuPDF模块将PDF转换为图片

    上一篇文章介绍了pdf2image模块+poppler将PDF转换为图片,这篇文章主要介绍另外一个模块PyMuPDF.  PyMuPDF(又名"fitz"):MuPDF的Pytho ...

  3. 【Python】pdf2image模块+poppler将PDF转换为图片

    有时我们需要将PDF转换成图片,今天我们主要说的是pdf2image+poppler对PDF转换成图片格式. pdf2image是个包装器,真正的转换工具是poppler GitHub地址:https ...

  4. Python 利用pymupdf将pdf转换为图片并拆分,后通过PIL合并生成一张图片

    文章主要内容主要参考几篇文章并合并在一起的,文章链接依次如下,第二和第三的文章链接是从第一篇文章找到的: (1).https://blog.csdn.net/qq_25115281/article/d ...

  5. 快速将PDF转换为图片:免费的在线PDF转换器

    在现代数字时代,PDF是一种非常常见的文件格式.它们在学术界,商业领域和许多其他领域中被广泛使用.有时,您可能需要将PDF文件转换为图像格式,以便能够方便地与他人共享和使用.在这种情况下,您可以使用免 ...

  6. 实现DOC、DOCX转换为PDF 再将PDF转换为图片

    实现DOC.DOCX转换为PDF 再将PDF转换为图片 首先导入需要的依赖 <dependency><groupId>cn.hutool</groupId>< ...

  7. spring boot整合icepdf实现pdf转图片

    一 项目图片 下载地址: http://www.gxcode.top/code 项目描述 spring boot整合icepdf实现pdf转图片 springboot整合icepdf组件,实现pdf转 ...

  8. Ubuntu下Java使用pdfbox将pdf转换为图片的方法及问题

    Ubuntu下Java使用pdfbox将pdf转换为图片的方法及问题 使用pdfbox-2.0.3和fontbox-2.0.3,实现pdf转图片功能. 官方手册链接: http://pdfbox.ap ...

  9. 文字PDF转换为图片格式的PDF

    在我们的日常工作和生活中,有时候我们需要对PDF文件进行一些特殊处理.有时候,我们希望将PDF的每一页提取出来作为图片,方便在其他场景中使用:而有时候,我们则需要将PDF内的内容转换为图片格式,以防止 ...

  10. 如何将pdf转换为图片?

    其实在PDF的使用过程中,将PDF转换为不同的文件格式是很常规的一个操作,比如有时为了方便使用,我们就会选择将PDF转换成图片格式,这样我们可以任选我们需要的内容进行使用了,比起不停的翻阅整个pdf文 ...

最新文章

  1. 【转】Android 4.3源码的下载和编译环境的安装及编译
  2. 2017/08/08 工作日志
  3. 端计算(3)-kotlin(1)
  4. oracle内部错误排查,Oracle内部错误ORA-600:[1112]
  5. 汉军Hundre考勤数据库数据表分析总结
  6. 《Python Cookbook 3rd》笔记(4.15):顺序迭代合并后的排序迭代对象
  7. Android应用开发-图片加载库Glide
  8. 网站建设中 模板_网站建设之模板网站的缺点
  9. java提示框easyui风格_EasyUI 标签框风格(TagBox Style)_Vue EasyUI Demo
  10. 服务器系统分区 是啥,服务器系统盘分区
  11. 制作透明的图标ICO
  12. 仿souhu页面设计
  13. ATTCK实战系列一(内网渗透入门)
  14. 电影院开工在即,第一部电影就看他
  15. xp系统怎样安装传真服务器,如何安装windows xp传真服务器
  16. 3DMAX、MAYA、C4D区别
  17. Python:雷达图的实现
  18. 如何在Ubuntu系统下挂载新硬盘(win10+Ubuntu双系统单硬盘挂载新硬盘)
  19. 写给这批≥30岁的测试工程师 。
  20. 【解读】主板·主板型号·命名规则√

热门文章

  1. 蓝牙BLE协议分析【附代码实例】
  2. linux snappy 版本,snappy初级文档
  3. 2W+字系统讲解如何用Python自动化操作PPT,学懂这篇文章就够了
  4. 虚拟机去虚拟化教程,过游戏检测,不全你打我
  5. 【解析无线路由器信号消失原因】
  6. java 自然对数的底数_Java求自然对数底e的值
  7. 京东商城系统架构设计原则
  8. 直流有刷/无刷电机的介绍
  9. torch.randn 方法
  10. c语言.jpg图片转成数组_如何把pdf图片转成jpg?快看高手私藏实用的技巧