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文档可以直接进行复制粘贴,需要下载安装相关的编辑工具,才能对文字内容进行编辑.倒不 ...
随机推荐
- Android开发-开发前的配置
一.JDK (不用安装) JDK是 java 语言的软件开发工具,主要用于移动设备.嵌入式设备上的java应用程序. JDK是整个java开发的核心,它包含了JAVA的运行环境,JAVA工具和JA ...
- 2016 - 1 - 3 国旗选择demo
// // ViewController.m // 国旗 // // Created by Mac on 16/1/3. // Copyright © 2016年 Mac. All rights re ...
- linux添加动态库搜索路径
在有时运行程序出现动态库找不着的问题,而明明装了的.这时候可能是没有将相应的路径添加到系统中去. 具体说:cd /etc/ld.so.conf.d/ 可以发现里面有一堆*.conf的文件 我们要做的就 ...
- 5分钟学习maven(根据英文文档整理)
英文原地址:http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 一.前提 需要懂得如何在计算机上安装软件 ...
- java删除指定目录及其文件
import java.io.File; public class Test { public static void main(String args[]){ Test t = new Test() ...
- HTTP协议详解(经典)
转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HTTP是一个属于应用层的面向对象的 ...
- String to Integer (atoi) ---- LeetCode 008
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- Chocolate_DP
Description In 2100, ACM chocolate will be one of the favorite foods in the world. "Green, oran ...
- 一个自定义的窗体样式MessageBox控件
using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Dr ...
- magento缓存系列详解:clean cache
cache是一个很大的概念,涉及的内容方方面面,magento cache是基于zend的,如果你对zend cache理解很深的话,相信magento cache也不再话下,本篇文章着重介绍Flus ...