ICEpdf版本为:6.3.0

1.转换代码如下:

package com.icepdf;import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;public class Pdf2ImgUtil {public static void main(String[] args){String filePath="G:/BaiduYunDownload/ce.pdf";Document document=new Document();try{document.setFile(filePath);float scale=1.0f; //缩放比例float rotation=0f; //旋转角度  for(int i=0;i<document.getNumberOfPages();i++){BufferedImage image=(BufferedImage)document.getPageImage(i,GraphicsRenderingHints.SCREEN,Page.BOUNDARY_CROPBOX,rotation,scale);RenderedImage rendImage=image;File file=new File("G:/BaiduYunDownload/icepdf_"+i+".jpg");// 这里png作用是:格式是jpg但有png清晰度  ImageIO.write(rendImage,"png",file);image.flush();  }document.dispose();}catch(Exception e){System.out.println(e.getMessage());e.printStackTrace();}System.out.println("======================完成============================");}
}

去除ICEpdf转换后图片上的水印,需要把下面两个类增加到自己的项目中去。

1.ProductInfo,包名固定为org.icepdf.core.application,代码如下:

package org.icepdf.core.application;public class ProductInfo {/*** The company that owns this product.*/public static String COMPANY = "ICEsoft Technologies, Inc.";/*** The name of the product.*/public static String PRODUCT = "ICEpdf";/*** The 3 levels of version identification, e.g. 1.0.0.*/public static String VERSION = "6.3.0";/*** The release type of the product (alpha, beta, production).*/public static String RELEASE_TYPE = "";/*** The build number.  Typically this would be tracked and maintained* by the build system (i.e. Ant).*/public static String BUILD_NO = "19";/*** The revision number retrieved from the repository for this build.* This is substitued automatically by subversion.*/public static String REVISION = "49267";public String toString(){StringBuilder info = new StringBuilder();info.append( "\n" );info.append( COMPANY );info.append( "\n" );info.append( PRODUCT );info.append( " " );info.append(VERSION);info.append( " " );info.append( RELEASE_TYPE );info.append( "\n" );info.append( "Build number: " );info.append( BUILD_NO );info.append( "\n" );info.append( "Revision: " );info.append( REVISION );info.append( "\n" );return info.toString();}public String getVersion(){StringBuilder info = new StringBuilder();//info.append(VERSION);//info.append( " " );//info.append( RELEASE_TYPE );return info.toString();}public static void main(String[] args) {ProductInfo app = new ProductInfo();System.out.println( app.toString() );}
}

2.Padding,包名固定为:org.icepdf.core.pobjects.graphics,代码如下:

package org.icepdf.core.pobjects.graphics;import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import org.icepdf.core.application.ProductInfo;public class Padding {/*private static byte[] padding1 = { (byte) 0x36, (byte) 0x30, (byte) 0x32,(byte) 0x5D, (byte) 0x51, (byte) 0x53, (byte) 0xD };*/private static byte[] padding1={};/*private static byte[] padding3 = { (byte) 0x33, (byte) 0x5C, (byte) 0x5F,(byte) 0xD, (byte) 0x32, (byte) 0x63, (byte) 0x4E, (byte) 0x59,(byte) 0x62, (byte) 0x4E, (byte) 0x61, (byte) 0x56, (byte) 0x5C,(byte) 0x5B, (byte) 0xD, (byte) 0x3D, (byte) 0x62, (byte) 0x5F,(byte) 0x5D, (byte) 0x5C, (byte) 0x60, (byte) 0x52, (byte) 0x60,(byte) 0xD, (byte) 0x3C, (byte) 0x5B, (byte) 0x59, (byte) 0x66 };*/private static byte[] padding3={};static {// add offsetfor (int i = 0; i < padding1.length; i++) {padding1[i] += (byte) 0x13;}for (int i = 0; i < padding3.length; i++) {padding3[i] += (byte) 0x13;}}public static final void getPadding(final Graphics2D g2,final Rectangle2D.Float mediaBox) {// setup painting parametersg2.scale(1, -1);g2.setColor(new Color(186, 0, 0));// setup strings for drawing water marksString version = new ProductInfo().getVersion();String headerText = new String(padding1) + version;String footerText = new String(padding3);int marginPadding = 5; // margin padding// draw footerg2.setFont(new Font("Dialog", Font.BOLD, 14));FontMetrics fontMetrics = g2.getFontMetrics();Rectangle2D fontBounds = fontMetrics.getStringBounds(footerText.toCharArray(), 0, footerText.length(), g2);int x = (int) (mediaBox.x + (mediaBox.width - fontBounds.getWidth()) / 2.0);int y = -1* (int) (mediaBox.getY() - mediaBox.getHeight() + marginPadding);g2.drawString(footerText, x, y);// draw headerfontBounds = fontMetrics.getStringBounds(headerText.toCharArray(), 0,headerText.length(), g2);x = (int) (mediaBox.x + (mediaBox.width - fontBounds.getWidth()) / 2.0);y = -1 * (int) (mediaBox.y - fontBounds.getHeight() - marginPadding);g2.drawString(headerText, x, y);}
}

效果如下图所示:

带水印:

去除水印:

ICEpdf转换pdf文件为图片相关推荐

  1. PDF文件转图片怎么弄?这个方法值得收藏

    PDF文件是一种广泛使用的文件格式,其保留了原始文档的格式和内容,使其在不同平台上具有高度的兼容性.然而,在某些情况下,我们需要将PDF文件转换为图片格式以便于处理和分享.本文将介绍两种方法将PDF文 ...

  2. java+icepdf+下载_Java使用icepdf将pdf文件按页转成图片

    本文实例为大家分享了Java使用icepdf将pdf文件按页转成图片的具体代码,供大家参考,具体内容如下 Maven icepdf包,这里过滤掉jai-core org.icepdf.os icepd ...

  3. java图片转换pdf_Java实现图片转换PDF文件的示例代码

    最近因为一些事情,需要将一张简单的图片转换为PDF的文件格式,在网上找了一些工具,但是这些工具不是需要注册账号,就是需要下载软件. 而对于只是转换一张图片的情况下,这些操作显然是非常繁琐的,所以作者就 ...

  4. 将HTML文件转换为PDF文件(Thymeleaf模板转换,简单解决中文问题, 解决HTML带图片转换PDF文件问题)

    将HTML文件转换为PDF文件 一.导入依赖 <!-- itext生成Pdf --> <dependency><groupId>com.itextpdf</g ...

  5. Java实现图片转换PDF文件

    文章目录 引入依赖 前端页面 控制层接口 PDF工具类 页面效果 最近因为一些事情,需要将一张简单的图片转换为PDF的文件格式,在网上找了一些工具,但是这些工具不是需要注册账号,就是需要下载软件. 而 ...

  6. java调用pdfbox转pdf文件为图片文件,有中文时在windows上正常,部署到linux下乱码

    最近遇到了一个很头疼的问题,我们的项目移动端需要一个读pdf的功能,但是手机端开发人员说移动端是用jquerymobile做的,不能直接甩pdf文件过去(原因是pdf文件太大),于是乎我们想到了2个解 ...

  7. pdf转图片 java_有将pdf文件转图片的格式方法吗?

    有时候我们为了方便传输,需要把图片转为PDF的格式,因为它所占的空间相对要小.但是因为pdf文件的安全性很好所以不能进行编辑,那我们又要进行编辑图片的时候,就又会把PDF文件格式转换成图片来进行编辑. ...

  8. 不改变分辨率转换PDF为png图片的方法汇总

    tags: Tips 写在前面 最近有小伙伴问我怎么无损转换PDF文件为png格式, 一开始我觉得这个直接使用 之前文章提到的sips命令或者convert命令就可以了, 但是发现还是想简单了, si ...

  9. Java实现pdf文件转图片

    Java实现pdf文件转图片 文章顺序是按照测试类- -Service- -Service实现类- -工具类- - POM依赖. test测试类里 pdfPath:存放pdf源文件的地方 imgflo ...

最新文章

  1. perl 登录linux服务器,用Perl管理Linux操作系统的配置文件
  2. InetAddress类和InetSocketAddress的使用
  3. iframe ajax上传,ajax--iframe模拟ajax文件上传效果
  4. OpenGL中的几何体实例化(OpenGL Geometry Instancing)
  5. java jmeter_使用Jmeter中的Java Request进行性能测试
  6. golang 接口_「Golang系列」 深入理解Golang Empty Interface (空接口)
  7. 基于上下文化图注意力网络的知识图谱的条目推荐
  8. jquery上传图片插件(支持各种功能)
  9. Oracle常用日期型函数详解(转)
  10. centos7升级内核
  11. i217lm网卡驱动linux,Intel英特尔I217/I218系列网卡驱动
  12. android 4.4 cts测试,android之CTS兼容性测试及FAIL issue
  13. 硬盘克隆带linux系统,使用Linux dd命令作硬盘克隆
  14. python图形用户界面page_Python+selenium使用PageObject实现UI自动化
  15. 国科大《自然语言处理》复习(宗成庆老师)
  16. sgu-207 Robbers
  17. Linux 4.15亮点特性
  18. Apollo planning之PiecewiseJerkPathOptimizer
  19. 电容屏分类及优缺点介绍
  20. mac风扇一直响_您如何找出哪个计算机风扇被响了?

热门文章

  1. FRED的光路和光路历史记录
  2. Deepin常用可视化软件
  3. [urlrewrite]使用urlrewrite进行地址自动重定向
  4. IIS Url Rewrite重写不生效
  5. edge 手动更新插件
  6. ROS操作系统 | 建立Aubo_Robot通信
  7. 深度学习关于激活函数和损失函数的调研
  8. spring boot 校园二手交易平台
  9. 2023-4 新一代智能测绘遥感科学试验卫星珞珈三号01星 (笔记)
  10. HTML一条线匀速直线运动,初中物理匀速直线运动的知识点归纳