/**

* 把PDF所有页转换为JPG, 并返回所有图片的路劲集合

* @param inputFilePath

* 图片路径,具体到文件名

* @param outputFilePath

* 输出目录, 不需要文件名

* @return

* @throws IOException

*/

public static List Pdf2Jpg(String inputFilePath,

String outputFilePath) throws IOException {

List outputFilePathList = new ArrayList();

// load a pdf from a byte buffer

File file = new File(inputFilePath);

RandomAccessFile raf = new RandomAccessFile(file, "r");

FileChannel channel = raf.getChannel();

ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());

PDFFile pdffile = new PDFFile(buf);

System.out.println("页数: " + pdffile.getNumPages());

for (int i = 1; i <= pdffile.getNumPages(); i++) {

// draw the first page to an image

PDFPage page = pdffile.getPage(i);

// get the width and height for the doc at the default zoom

Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()

.getWidth(), (int) page.getBBox().getHeight());

// generate the image

Image img = page.getImage(rect.width, rect.height, // width &

// height

rect, // clip rect

null, // null for the ImageObserver

true, // fill background with white

true // block until drawing is done

);

BufferedImage tag = new BufferedImage(rect.width, rect.height,

BufferedImage.TYPE_INT_RGB);

tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height, null);

String outputFilePath2 = outputFilePath + System.currentTimeMillis() + ".jpg";

FileOutputStream out = new FileOutputStream(outputFilePath2); // 输出到文件流

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(tag); // JPEG编码

out.close();

outputFilePathList.add(outputFilePath2);

}

return outputFilePathList;

}

java pdf转jpg_java pdf转换jpg相关推荐

  1. java pdf to jpg_Java pdf和jpg互转案例

    pdfbox: jpg转pdf: /** * 使用pdfbox将jpg转成pdf * @param jpgStream jpg输入流 * @param pdfPath pdf文件存储路径 * @thr ...

  2. JAVA常用API或编程工具001---ITEXT把html转换成pdf的jar包,使用Java将HTML转换为PDF

    iText "XML Worker"允许开发人员以一种程序员友好的方式将XML文件转换成PDF文件.iText还可以将包含CSS样式的HTML转换为PDF格式的文档. 目标: 实现 ...

  3. 【Java】SpringBoot后端格式转换:把Word转成PDF再按页转成图片在前端展示(Linux)

    ConvertUtil 1. word2pdf 1.1 aspose-word插件 1.2 word转pdf 1.2.1 添加license文件 1.2.2 具体实现 2. pdf2imgByPage ...

  4. JAVA实现 PDF转换 常用工具类(html转PDF、PDF添加页码、PDF文件下载、PDF添加印章或者水印)

    JAVA实现 PDF转换 常用工具类(html转PDF.PDF添加页码.PDF文件下载.PDF添加印章或者水印)可直接使用 package com.bestvike.util; import com. ...

  5. Java使用aopse实现word转换pdf

    Java使用aopse实现word转换pdf 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/de ...

  6. java使用wkhtmltopdf将html转换成pdf

    使用wkhtmltopdf将html转换成pdf 安装wkhtmltopdf windows下载 window安装 linux安装 使用java调用wkhtmltopdf 注意 安装wkhtmltop ...

  7. java调用libreoffice_JAVA实现LibreOffice转换PDF文档

    首先,安装LibreOffice服务 使用.LibreOfficeAndJodconverter.java package com.jalor.LibreOffice; import java.io. ...

  8. java实现图片jpg批量转换成pdf

    java实现图片jpg批量转换成pdf package jpgTopdf; import java.awt.image.BufferedImage; import java.io.File; impo ...

  9. Java利用jacob实现wps转换pdf

    实现文档格式之间的转换,我使用的是jacob-1.7版本,需要jacob.jar来调用activex控件,本机需安装WPS/office,还需要jacob.jar以及jacob.dll 其中:     ...

  10. java使用swfTools将pdf文件转换swf文件

    转载请表明出处 https://blog.csdn.net/Amor_Leo/article/details/89388851 谢谢 java使用swfTools将pdf文件转换swf文件 swfTo ...

最新文章

  1. Git-remote Incorrect username or password ( access token )
  2. python的优点和缺点-python的优点和缺点是什么?
  3. android 继承dialog自定义对话框
  4. Python之方法调用
  5. C语言实现hash/DJB2算法(附完整源码)
  6. COALESCE()、isnull()、nullif()函数的用法
  7. Spring+Hibernateh使用小结
  8. matlab 如何画二维图形,Matlab 学习 画图篇 一 二维图形
  9. 基于51单片机的计算器
  10. php a文件怎么继承b文件的类,php 如何将存在a文件中图片移到b文件中
  11. 一文解锁加密算法的秘密
  12. zabbix分布式监控部署proxy安装
  13. php 创建文本文件,php-创建文本文件以进行实时下载
  14. 解决krpano全景视频在QQ浏览器、安卓不能正常播放的问题
  15. python与java前景-Java和Python现在都很热门,哪个更有前途?
  16. 前后端-SpringBoot-JPA的简单写法(配合前端vue)
  17. linux离线安装字体
  18. 计算机属性内存处理器不可用,电脑属性显示处理器和安装内存不可用怎么回事...
  19. Your actions speak louder
  20. Redis - 一个简单的抢红包小项目

热门文章

  1. MySQL备份的几种常用方法与恢复步骤
  2. 计算机换显卡,老平台只换显卡 这样升级行不行?
  3. 蚂蚁安全键盘空白或应该显示安全键盘却显示的系统键盘的问题(iOS中时间佛历如何转换为公历)
  4. 中级软件设计师刷题笔记
  5. 一键生成2020年虎年头像
  6. Chaos Mesh介绍
  7. 如何让计算机从固态硬盘启动不了,电脑设置固态硬盘启动的方法
  8. 不知道何时,我逐渐丧失了表达能力
  9. DaVinci:RGB 混合器
  10. Julia·Pluto·Plots报错解决方法