java pdf转换jpg
/**
* 把PDF所有页转换为JPG, 并返回所有图片的路劲集合
* @param inputFilePath
* 图片路径,具体到文件名
* @param outputFilePath
* 输出目录, 不需要文件名
* @return
* @throws IOException
*/
public static List<String> Pdf2Jpg(String inputFilePath,
String outputFilePath) throws IOException {
List<String> outputFilePathList = new ArrayList<String>();
// 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转换成图片并输出给前台展示
首先需要导入所需工具类 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>fo ...
- 利用jpedal进行pdf转换成jpeg,jpg,png,tiff,tif等格式的图片
项目中运用到pdf文件转换成image图片,开始时使用pdfbox开源库进行图片转换,但是转换出来的文件中含有部分乱码的情况.下面是pdfBox 的pdf转换图片的代码示例. try{ String ...
- 利用pdf2swf将PDF转换成SWF
将PDF转换成SWF可以使用SWFTools工具中的pdf2swf(http://www.swftools.org/),CSDN快速免积分下载地址http://download.csdn.net/de ...
- swftools 将pdf转换swf常见问题说明
swftools将PDF转成swfSWFTools提供了一系列将各种文件转成swf的工具: font2swf.exe gif2swf.exe jpeg2swf.exe pdf2swf.exe png2 ...
- java PDF转word的初步实现
package com.springboot.springboot.util; import java.io.File; import java.io.FileOutputStream; import ...
- inner join ,left join ,right join 以及java时间转换
1.inner join ,left join 与 right join (from 百度知道) 例表aaid adate1 a12 a23 a3表bbid bdate1 ...
- Python 将pdf转换成txt(不处理图片)
上一篇文章中已经介绍了简单的python爬网页下载文档,但下载后的文档多为doc或pdf,对于数据处理仍然有很多限制,所以将doc/pdf转换成txt显得尤为重要.查找了很多资料,在linux下要将d ...
- ABBYY如何把PDF转换Excel
我们都知道2007以上版本的Office文档,是可以直接将文档转存为PDF格式文档的.那么反过来,PDF文档可以转换成其他格式的文档吗?这是大家都比较好奇的话题.如果可以以其他格式进行保存,就可以极大 ...
- ABBYY把pdf转换成word的方法
有时候我们在网上下载的资料文献是PDF格式文档,遇到喜欢的字句总忍不住想要收藏起来,但是PDF文档不同于普通的Word文档可以直接进行复制粘贴,需要下载安装相关的编辑工具,才能对文字内容进行编辑.倒不 ...
随机推荐
- GoldenGate 之 Bounded Recovery说明
首先,我们来看两个OGG同步中可能的问题: l oracle在线日志包含已提交的和未提交的事务,但OGG只会将已提交的事务写入到队列文件.因此,针对未提交的事务,特别是未提交的长事务,OGG会怎样处理 ...
- Linux访问Windows磁盘实现共享
业务需求说明:公司在部署hadoop集群和DB server与SAN存储,公司的想法是前端通过DB Server能够将非结构化的数据能放进SAN存储当中,而hadoop集群也能够访问这个SAN存储.因 ...
- oracle中的cluster表
大家对通常oracle中的cluster的理解是不准确的,经常和sql server中的cluster index混淆.Cluster是存储一组table的一种方法,这些table共享同一数据块中的某 ...
- hdu 2083
ps:N个数中,中位数是最小距离...第一次WA是因为排序之后最小和最大相加除2...应该是找他们的中位数,而不是中间数. 代码: #include "stdio.h" #incl ...
- ISO c++11 does not allow conversion from string literal to 'char*'
http://stackoverflow.com/questions/9650058/deprecated-conversion-from-string-literal-to-char
- 中国省市 JS代码
很实用的一段JS代码, 用户注册的时候,选择地址常用到.代码如下: <script language="javascript"> var g_selProvince; ...
- AmazeUI常用组件
按钮样式 <span class="am-badge">1</span> #正方形 <span class="am-badge am-ba ...
- IOS 作业项目(3) 霓虹灯效果
先上效果图 #import "CHViewController.h"@interface CHViewController (){ int i; int j;}@pro ...
- Java 集合深入理解(6):AbstractList
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情比天蓝,来学学 AbstractList 吧! 什么是 AbstractList AbstractList 继承自 ...
- PHP 安全
作为PHP程序员,特别是新手,对于互联网的险恶总是知道的太少,对于外部的入侵有很多时候是素手无策的,他们根本不知道黑客是如何入侵的.提交入侵.上传漏洞.sql 注入.跨脚本攻击等等.作为最基本的防范你 ...