需求:公司现在有个将PDF文件转换成.tif格式的图片,然后利用FTP上传到服务器。
所需jar:PDFRenderer-0.9.1.jar
下面代码是将PDF文件转换成.tif格式
package com.xu.test; 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 java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; 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 PDFchangToImage { public static void main(String[] args) { PDFchangToImage.changePdfToImg(); } public static void changePdfToImg() { try { File file = new File("D:\\LT000091209.pdf"); RandomAccessFile raf = new RandomAccessFile(file, "r"); FileChannel channel = raf.getChannel(); MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,0, channel.size()); PDFFile pdffile = new PDFFile(buf); //加载pdf文件 for (int i = 1; i <= pdffile.getNumPages(); i++) { PDFPage page = pdffile.getPage(i); //获取PDF第几页 Rectangle rect = new Rectangle(70, -20, ((int) 320),((int) page.getBBox().getHeight())); int w = 3; //设置图片的宽放大多少倍 int h = 3; //设置图片的高放大多少倍 Image img = page.getImage(rect.width * w, rect.height * h, rect, null, // null for the ImageObserver true, // fill background with white true // block until drawing is done ); BufferedImage tag = new BufferedImage(rect.width * w,rect.height * h, BufferedImage.TYPE_BYTE_GRAY); tag.getGraphics().drawImage(img, 0, 0, rect.width * w,rect.height * h, null); FileOutputStream out = new FileOutputStream("D:\\" + i+ ".tif"); // 输出到文件流 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(tag); param.setQuality(1f, false);// 1f是提高生成的图片质量 0-1之间 encoder.setJPEGEncodeParam(param); encoder.encode(tag); // JPEG编码 out.flush(); out.close(); } channel.close(); raf.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
相关推荐
winfrom完美实现pdf转换成图片
PDF转换成图片的案例,如果不想下载,我的博客有源码和图片讲解,希望可以帮助到大家!
将PDF转换成图片的依赖库文件
利用ghostscript把C# pdf转换成图片利用ghostscript把C# pdf转换成图片利用ghostscript把C# pdf转换成图片
ghostscript把C# pdf转换成图片ghostscript把C# pdf转换成图片
将pdf转换成图片并实现图片压缩(基于python实现) .zip
一款快速将PDF转换为图片的工具,非常简单实用。
经测试觉得非常好用,可以转换输出图片大小。
PDF转换图片(多页转多张) java实现多页PDF转换多张图片
1.PDF转换成图片: 将PDF文件按页转换成.Png图片格式,转换结束会有提示 (转换过的文件将自动移动到对应的文件夹,防止多次转换) 2.图片转换成PDF: 可以将单张照片(.Png/.png)分别转换成.pdf文件,转换结束会有...
pdf转换成图片所用的jar包,包括常用的fontbox-2.0.9.jar和pdfbox-2.0.9.jar,以及pdfbox-debugger-2.0.9.jar,pdfbox-tools-2.0.9.jar,preflight-2.0.9.jar,xmpbox-2.0.9.jar
采用Adobe Acrobat9.0的COM组件,将Pdf文件的每一页转换成对应的图片文件
一款把PDF文件转换成图片(支持多种图片格式)的免费软件。 没有PDF文件阅读器?PDF文档打印时精度太低?手机(特别是iphone/ipad)不支持PDF文件?用这个软件可以轻松解决: (1)把PDF文件转换成图片,一页一个...
解决通过OpenOffice如何将word、excel、ppt、html、txt转换成pdf 解决如何将pdf转换成图片 解决如何将word、excel、ppt、html、txt转换成图片,之前有人传过,但不能运行,现在传个自己的,可以完美转换,谁下谁知道...
C#将pdf转换为图片,使用Ghostscript 将pdf 文件转换为图片,清晰,可靠,ps:需要在电脑上安装Ghostscript ,文件中有安装文件
python将pdf文件转换成图片,可设置图片的清晰度,可对源码进行修改实现pdf文件批量转换为图片。此源码是单个文件的装换,
Spire.Pdf.dll,可以把PDF转成图片,实测.net core可以,压缩包里包含Spire.Pdf.dll和Spire.License.dll
PDF转换成图片,txt,word等多种格式合一软件,方便使用,页面简洁,是您最好的选择