pdf转图片

PDF文件不管是在WindowsUnix还是在苹果公司的Mac OS操作系统中都是通用的,今天我们来讲讲怎么把它转成图片。
  • 使用了两个jar包
    pdfbox-2.0.7.jar
    fontbox-2.0.7.jar
//文件路径
File file = new File("E:\\aaa\\03100160021100508428.pdf");
try {
     PDDocument doc = PDDocument.load(file);
     PDFRenderer renderer = new PDFRenderer(doc);
     int pageCount = doc.getNumberOfPages();
     for(int i=0;i<pageCount;i++){
          BufferedImage image = renderer.renderImageWithDPI(i, 296);  //296为dpi
          //BufferedImage image = renderer.renderImage(i, 2.5f);  //2.5f为缩放比
          ImageIO.write(image, "PNG", new File("E:\\aaa\\pdfbox_image.png"));
     }
} catch (IOException e) {
     e.printStackTrace();
}

这样就OK啦 是不是so easy~
小晕同学棒棒哒~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 注:该篇文章摘自于github.com/vhf/free-programming-books,英文版。访问该项目获...
    stuha阅读 3,973评论 0 13
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,268评论 25 708
  • 往外看的人,做着梦。往内看的人,醒着。 ——荣格
    晞晨阅读 130评论 0 0
  • 文‖阿jing 已是一个月没有回家了。明天学校决定放假,因为国庆节来了。 “每逢佳节倍思亲”。真的,我不知道怎么仍...
    阿jing阅读 435评论 3 8
  • // 将子view添加进父view [self.view1 sd_addSubviews:@[subview1, ...
    万忍阅读 228评论 0 0