java pdf转jpg_java pdf转换jpg
/**
* 把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相关推荐
- java pdf to jpg_Java pdf和jpg互转案例
pdfbox: jpg转pdf: /** * 使用pdfbox将jpg转成pdf * @param jpgStream jpg输入流 * @param pdfPath pdf文件存储路径 * @thr ...
- JAVA常用API或编程工具001---ITEXT把html转换成pdf的jar包,使用Java将HTML转换为PDF
iText "XML Worker"允许开发人员以一种程序员友好的方式将XML文件转换成PDF文件.iText还可以将包含CSS样式的HTML转换为PDF格式的文档. 目标: 实现 ...
- 【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 ...
- JAVA实现 PDF转换 常用工具类(html转PDF、PDF添加页码、PDF文件下载、PDF添加印章或者水印)
JAVA实现 PDF转换 常用工具类(html转PDF.PDF添加页码.PDF文件下载.PDF添加印章或者水印)可直接使用 package com.bestvike.util; import com. ...
- Java使用aopse实现word转换pdf
Java使用aopse实现word转换pdf 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/de ...
- java使用wkhtmltopdf将html转换成pdf
使用wkhtmltopdf将html转换成pdf 安装wkhtmltopdf windows下载 window安装 linux安装 使用java调用wkhtmltopdf 注意 安装wkhtmltop ...
- java调用libreoffice_JAVA实现LibreOffice转换PDF文档
首先,安装LibreOffice服务 使用.LibreOfficeAndJodconverter.java package com.jalor.LibreOffice; import java.io. ...
- java实现图片jpg批量转换成pdf
java实现图片jpg批量转换成pdf package jpgTopdf; import java.awt.image.BufferedImage; import java.io.File; impo ...
- Java利用jacob实现wps转换pdf
实现文档格式之间的转换,我使用的是jacob-1.7版本,需要jacob.jar来调用activex控件,本机需安装WPS/office,还需要jacob.jar以及jacob.dll 其中: ...
- java使用swfTools将pdf文件转换swf文件
转载请表明出处 https://blog.csdn.net/Amor_Leo/article/details/89388851 谢谢 java使用swfTools将pdf文件转换swf文件 swfTo ...
最新文章
- Git-remote Incorrect username or password ( access token )
- python的优点和缺点-python的优点和缺点是什么?
- android 继承dialog自定义对话框
- Python之方法调用
- C语言实现hash/DJB2算法(附完整源码)
- COALESCE()、isnull()、nullif()函数的用法
- Spring+Hibernateh使用小结
- matlab 如何画二维图形,Matlab 学习 画图篇 一 二维图形
- 基于51单片机的计算器
- php a文件怎么继承b文件的类,php 如何将存在a文件中图片移到b文件中
- 一文解锁加密算法的秘密
- zabbix分布式监控部署proxy安装
- php 创建文本文件,php-创建文本文件以进行实时下载
- 解决krpano全景视频在QQ浏览器、安卓不能正常播放的问题
- python与java前景-Java和Python现在都很热门,哪个更有前途?
- 前后端-SpringBoot-JPA的简单写法(配合前端vue)
- linux离线安装字体
- 计算机属性内存处理器不可用,电脑属性显示处理器和安装内存不可用怎么回事...
- Your actions speak louder
- Redis - 一个简单的抢红包小项目