1.1如何应用PDFRenderer系统实现将PDF文档转换为图片的应用示例1.1.1应用PDFRenderer系统实现将PDF文档转换为图片的应用示例
1、构建示例测试Java应用程序项目
(1)在MyEclipse开发工具中创建一个项目名称为JavaPDFApp的Java应用程序项目
(2)设置项目名称为JavaPDFApp
(3)项目结果
(1)启动项目的属性菜单
(2)切换到Java Build Path页中的Libraries选项页
(3)将下载的PDFRenderer系统文件加入到项目的编译环境中
3、在MyEclipse开发工具中创建示例程序类
(1)示例程序类名称为PDFToImagePictureByPDFRenderer,程序包名称为
com.bluedream.pdfrenderer
(2)将创建出PDFToImagePictureByPDFRenderer程序类的初始代码
4、编程PDFToImagePictureByPDFRenderer程序类的功能实现代码(1)编程PDFToImagePictureByPDFRenderer程序类中的功能方法
(2)PDFToImagePictureByPDFRenderer程序类的完整代码示例package com.bluedream.pdfrenderer;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import ng.reflect.Method;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.UUID;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
public class PDFToImagePictureByPDFRenderer {
public PDFToImagePictureByPDFRenderer() {
super();
}
/
*
* @param orignalPDTFileName 转换前的原始的PDF文件绝对路径和文件名称,比如String orignalPDTFileName ="D:\软件项目程序\Demo1\demo1.pdf";
* @param resultImagePathName 转换后的图片存储的目录路径名称(绝对路径),比如String resultImagePathName ="D:\软件项目程序\Demo1\result\";
* @param exePandParameters 图片清晰度(n>0.0且n<7.0),为PDF的放大参数,也就转换后的图片的尺寸为原始的PDF页尺寸的倍数,默认为1.0(与原始的PDF文件页尺
寸相同);<1.0为缩小,>1.0为放大
* @param isPDFFileDeleted 转换后是否要删除原始的PDF文件,=true 删除原始的PDF文件,=false 不删除原始的PDF文件
*/
public boolean doTransferPdfFileToPicture(String orignalPDTFileName, String resultImagePathName, float exePandParameters, boolean isPDFFileDeleted) {
RandomAccessFile oneRandomAccessFile =null;
MappedByteBuffer oneMappedByteBuffer =null;
PDFFile onePDFFile =null;
FileOutputStream oneFileOutputStream =null;
File orignalPDTFile =null;
JPEGImageEncoder oneJPEGImageEncoder = null;
JPEGEncodeParam oneJPEGEncodeParam = null;
FileChannel oneFileChannel = null;
/
* 最终转换是否成功的返回状态标志,=false 表示转换不成功,=true 表示转换成功*/
boolean isTransferOK =false;
orignalPDTFile = new File(orignalPDTFileName);
try{
try {
/
* 以随机方式读取原始的PDF文档,并创建出RandomAccessFile类的对象实例*/
oneRandomAccessFile = new RandomAccessFile(orignalPDTFile, "r");
} catch (FileNotFoundException e) {
/
* e.printStackTrace()是在标准错误输出流上打印整个Exception轨迹栈(会把
到此这篇pdfview怎么转换成ppt(pdfview怎么转换成图片)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/bcyy/65813.html