需求

将pdf拆分成多个图片 且清晰

依赖


<dependency><groupId>com.kenai.nbpwr</groupId><artifactId>com-sun-pdfview</artifactId><version>1.0.5-201003191900</version><type>nbm</type>
</dependency>

具体代码

package com.example.demo.utils;import com.example.demo.pojo.PdfImg;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.imageio.ImageIO;/***  <p>Title : Pdf2Image </p>*  <p>Description : PDF转换png图片格式</p>** @author huifer* @date 2019年1月2日*/
public class Pdf2Image {private static final int BUFFER_SIZE = 2 * 1024;public static void main(String[] args) throws Exception {String read = "D:\\qfile\\科技查新报告(智慧排涝).pdf";ArrayList<File> strings = pdf2img(read);String newF = "E:\\mck\\PDF2\\fa\\" + read.split("\\\\")[read.split("\\\\").length - 1]+ ".zip";PdfImg pdfImg = new PdfImg();pdfImg.setPdf(read);pdfImg.setZip(newF);System.out.println(pdfImg);FileOutputStream fos2 = new FileOutputStream(new File(newF));toZip(strings, fos2);}public static void toZip(List<File> srcFiles, OutputStream out) throws RuntimeException {long start = System.currentTimeMillis();ZipOutputStream zos = null;byte[] buf = new byte[BUFFER_SIZE];try {zos = new ZipOutputStream(out);for (File srcFile : srcFiles) {zos.putNextEntry(new ZipEntry(srcFile.getName()));int len;FileInputStream in = new FileInputStream(srcFile);while ((len = in.read(buf)) != -1) {zos.write(buf, 0, len);}zos.closeEntry();in.close();}long end = System.currentTimeMillis();System.out.println("压缩完成,耗时:" + (end - start) + " ms");// 删除压缩列表中的文件for (int i = 0; i < srcFiles.size(); i++) {srcFiles.get(i).delete();}} catch (Exception e) {throw new RuntimeException("zip error from ZipUtils", e);} finally {if (zos != null) {try {zos.close();} catch (IOException e) {e.printStackTrace();}}}}public static ArrayList<File> pdf2img(String read) {ArrayList<File> ps = new ArrayList<>();try {String filePath = read;String[] split = filePath.split("\\\\");File file = new File(filePath);RandomAccessFile raf;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);int num = pdffile.getNumPages();for (int i = 0; i < num; i++) {PDFPage page = pdffile.getPage(i);int width = (int) page.getBBox().getWidth();int height = (int) page.getBBox().getHeight();Rectangle rect = new Rectangle(0, 0, width, height);int rotation = page.getRotation();Rectangle rect1 = rect;if (rotation == 90 || rotation == 270) {rect1 = new Rectangle(0, 0, rect.height, rect.width);}BufferedImage img = (BufferedImage) page.getImage(rect.width *2, rect.height*2,rect1,null,true,true);File file1 = new File("E:\\mck\\PDF2\\fa\\" + split[split.length - 1] + "-" + i + ".png");ps.add(file1);ImageIO.write(img, "png", file1);}} catch (FileNotFoundException e1) {System.err.println(e1.getLocalizedMessage());} catch (IOException e) {System.err.println(e.getLocalizedMessage());}return ps;}
}

pdf png 转换超清相关推荐

  1. python项目开发案例-Python项目开发案例集锦 PDF 全彩超清版

    给大家带来的一篇关于Python案例相关的电子书资源,介绍了关于Python.项目开发.Python案例方面的内容,本书是由吉林大学出版社出版,格式为PDF,资源大小99.1 MB,明日科技编写,目前 ...

  2. MP4视频格式转换器怎样转换MKV超清视频格式

    在日常生活中,看电视剧电影都是常有的事情,但是观看高清版的视频比一般的甚至模糊的体验肯定是不一样的.其实模糊的视频是可以转为高清乃至超清的文件,只不过需要使用到视频格式转换器,那么哪款视频转换器转换过 ...

  3. python从入门到精通-Python从入门到精通 PDF 完整超清版

    给大家带来的一篇关于Python入门相关的电子书资源,介绍了关于Python入门.Python精通方面的内容,本书是由清华大学出版社出版,格式为PDF,资源大小18.9 MB,明日科技编写,目前豆瓣. ...

  4. 如何将扫描PDF文件转换成word,两个超简单的方法一看就会

    在工作中我们都会经常接触到PDF文件,但是这些都是比较常见的,有时候会因为工作的需要要接触扫描格式的文件,比较难的是需要将扫描PDF文件转换成Word,很多人就很头疼,不知道该从哪里开始下手去做,虽然 ...

  5. 张宇闭关修炼【超清pdf】

    2020张宇闭关修炼[超清]pdf 资料链接 https://shimo.im/docs/rOCr3qKLursLC5Mq/ 祝大家考研顺利! 根据工学.经济学.管理学各学科.专业对硕士研究生入学所应 ...

  6. 2020风中劲草考研政治大纲资料【超清PDF】

    2020风中劲草考研政治[超清PDF] https://shimo.im/docs/kG3RHVX8CpGwQj9X/ 随着政治复习神书<风中劲草>的上市,今天我们来聊一下政治复习的话题. ...

  7. asp.net pdf如何转换成tif_如何将pdf转换成高清图片?你需要这个软件!|电脑|pdf|转换器...

    如今在办公中很多人都喜欢将图片保存为PDF格式,因为PDF格式更便捷.但如果想在PDF文件中选取其中一些图片出来,那么应该如何操作呢?小编在这里给大家分享两个PDF转图片的方法,轻松帮助你解决格式转换 ...

  8. 华人一作登ICCV 2021,实时超分新SOTA!AutoML显神威:1%参数量,超清视频70倍加速...

      视学算法报道   作者:詹政 编辑:好困 小咸鱼 [新智元导读]东北大学王言治团队将网络结构搜索与剪枝搜索相结合,提出了全新的自动搜索框架.该AutoML框架得到的稀疏模型能够在移动设备上实时且高 ...

  9. 看得“深”、看得“清” —— 深度学习在图像超清化的应用

    日复一日的人像临摹练习使得画家能够仅凭几个关键特征画出完整的人脸.同样地,我们希望机器能够通过低清图像有限的图像信息,推断出图像对应的高清细节,这就需要算法能够像画家一样"理解"图 ...

最新文章

  1. 嵌入式CNN检测网络--LCDet
  2. python 投资组合_成功投资组合的提示
  3. akka2.5_发布Akka Toolkit 2.3
  4. RHEL6 虚拟磁带机使用指南
  5. mysql数据生成词云图_CVPR2018关键字分析生成词云图与查找
  6. 向量空间模型(VSM)--用于计算文本相似度
  7. Dual-polarity supply provides ±12V from one IC
  8. Logstash读取Kafka数据写入HDFS详解
  9. Android图片剪裁库:uCrop
  10. 支持向量机(SVM)的原理推导及解释
  11. 利用WebSphere Edge Server构建冷轧系统负载均衡
  12. word2016 卡顿_office2016打开很慢怎么办?office2016打开卡顿缓慢的解决方法
  13. 2 HTML常用标签标签嵌套和并列关系
  14. keystone WSGI流程
  15. office xls Hyperlink
  16. 趣味python | 一步一步绘制小猪佩奇
  17. 入门渗透:telnet远程登入——Meow
  18. 【数字化】分享-广东省企业首席数据官建设指南
  19. 浏览器调用本地应用程序
  20. 【Open3D】人脸深度图转点云,点云表面重建

热门文章

  1. idea 一键展开所有方法 一键收纳所有方法
  2. linux 内存性能评估,内存性能评估工具vmstat/free/smem使用与解读
  3. vs python opencv配置_OPENCV入门教程二:opencv+VS2015开发环境配置
  4. 计算机c语言在线课堂,计算机(C语言)
  5. iis7 下php 环境配置文件,IIS7.X配置PHP运行环境小结_php
  6. python3d绘图代码_python机器学习之3D Matplotlib绘图
  7. .netcore 判断是否 ajax 请求_第3部分-异步使用2-2:Ajax 之 状态码
  8. panda是删除行_如何从Pandas数据帧中删除行列表?
  9. 为什么爬虫都用python_python为什么叫网络爬虫
  10. java panel画椭圆_如何在Java 2D中绘制椭圆?