吐槽弄了半天, iteye 的编辑器今天是有问题啊, 死活弄不好,插入不了代码,每次插入都显示到顶部,好烦
没心思好好写博客了, 直接看代码吧:
1、 引入相关的jar
<!-- PDF 转 图片 --> <dependency> <groupId>com.sun.pdfview</groupId> <artifactId>pdfrenderer</artifactId> <version>0.9.1-patched</version> </dependency>
2、 直接运行代码
private static void PdfToJpg() throws Exception { File file = new File("D:\\upload\\xxx.pdf"); // PDF路径 String getPdfFilePath = "D:\\upload\\img"; // 生成图片路径 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()); int pageNum = pdffile.getNumPages(); for (int i = 1; i <= pageNum; i++) { // draw the first page to an image PDFPage page = pdffile.getPage(i); int width = (int) page.getBBox().getWidth(); int height = (int) page.getBBox().getHeight(); System.out.println ("width:" + width); System.out.println ("height:" + height); // get the width and height for the doc at the default zoom Rectangle rect = new Rectangle(0, 0, width, height); int n = 2; //图片清晰度(n>0且n<7) pdf放大参数 // 放大pdf到n倍,创建图片 int imgW = width * n; int imgH = height * n; // generate the image Image img = page.getImage(imgW, imgH, // 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(imgW, imgH,BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(img, 0, 0, imgW, imgH,null); FileOutputStream out = new FileOutputStream(getPdfFilePath + File.separator + i + ".jpg"); // 输出到文件流 System.out.println("成功保存图片到 : " +getPdfFilePath+ File.separator + i + ".jpg"); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); // 设置图片质量 /*JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam (tag); param.setQuality (1f, true); //1f~0.01f是提高生成的图片质量 encoder.setJPEGEncodeParam (param);*/ encoder.encode(tag); // JPEG编码 out.close(); } }
相关推荐
PDF To JPEG Pro 是一款非常实用的专业pdf转jpg软件,只需三步就能帮助用户轻松将一个或者多个PDF文件快速转换为包括JPG、TIF、BMP、PNG、GIF、PSD、HDP、PAM、PBM、PPM、DCX、PS、PGM、RAW、GIF在内的多种主流图片...
批量 pdf 转jpg
拥有这款PDF转换器,您相当于有了WORD转PDF转换器,PDF转WORD转换器,PDF转DOC转换器,PDF转TXT转换器,PDF转HTML转换器,PDF转JPG转换器,PDF转HTML转换器,PDF转FLASH转换器,DOC转PDF转换器,TXT转PDF转换器,...
PDF转JPG——免费在线PDF转成图片格式
C#代码PDF转JPG 在实际的办公过程中根据实际的情况,我们有时候需要把图片做成PDF格式的,有时候又需要把PDF的转成图片格式的
PDF转JPG工具
C# ( PDF转JPG
JAVA中PDF转JPG的方法,直接调用方法就可用
PDF转JPG等图片工具,效果好,免注册,绿色版,只是转换出来的图片不够清晰
pdf转jpg破解版
pdf转JPG最好的软件,很好用的,本人一直在用
PDF转JPG软件,注册后免费使用,功能强大效果好!
java中pdf转jpg
PDF转换JPG图片格式。软件十分强大给力。
自己总结的一种免费的pdf转jpg方法,见附件。
=========================最实用的pdf转jpg 工具类,本人亲测有效,欢迎下载=========================。
PDF转JPG格式完整版,内含注册码,能够成功将PDF文档转为JPG图片格式
pdf转JPG软件无水印官方破解版,支持像素选择等