问题描述

今天生成PDF缝骑章的时候遇到一个问题,那就是每一个文件第一页都会有这个错

会在页面的第一页加上Evaluation Warning : The document was created with Spire.PDF for Java.一段文字

该备注只会标记再报表的第一页的顶部。我们可以新增一页,并删掉第一页即可

解决思路1

使用aspose的License去验证

需要引用aspose包,引入操作我写了一个博客,地址如下

https://blog.csdn.net/weixin_46713508/article/details/125495770?spm=1001.2014.3001.5502

本地创建一个License.xml

<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>


然后编写方法

  public static boolean getLicense() {boolean result = false;try {InputStream is = ConvertPDFUtils.class.getClassLoader().getResourceAsStream("\\license.xml");License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}

在转换的方法里面加入这个方法,值得注意点是aopse里面有针对不同文件有不同的license,别引入错了

这是word的license
import com.aspose.words.License;
这是excel的license
import com.aspose.cells.License;
这是pdf的license
import com.aspose.pdf.License

比如下面这个word转pdf的例子

    public boolean wordConvertPdf(MultipartFile file, String outPath) throws Exception {// 验证Licenseif (!getLicense()) {return false;}try {// 原始word路径Document doc = new Document(file.getInputStream());// 输出路径File pdfFile = new File(outPath);// 文件输出流FileOutputStream fileOS = new FileOutputStream(pdfFile);doc.save(fileOS, SaveFormat.PDF);fileOS.close();return true;} catch (Exception e) {e.printStackTrace();return false;}}

解决思路2

通过网上找例子找到了解决办法,因为这段文字只出现在第一页,所以这里的处理方式是在文档创建时先添加一个空白页,最后再把空白页去掉

代码实现

核心代码

 //添加一个空白页,目的为了删除jar包添加的水印,后面再移除这一页pdf.getPages().add();//创建字体PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", Font.PLAIN, 10),true);//遍历文档中的页for (int i = 0; i < pdf.getPages().getCount(); i++) {Dimension2D pageSize = pdf.getPages().get(i).getSize();float y = (float) pageSize.getHeight() - 40;//初始化页码域PdfPageNumberField number = new PdfPageNumberField();//初始化总页数域PdfPageCountField count = new PdfPageCountField();//创建复合域PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.getBlack(), "第{0}页 共{1}页", number, count);//设置复合域内文字对齐方式compositeField.setStringFormat(new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Top));//测量文字大小Dimension2D textSize = font.measureString(compositeField.getText());//设置复合域的在PDF页面上的位置及大小compositeField.setBounds(new Rectangle2D.Float(((float) pageSize.getWidth() - (float) textSize.getWidth())/2, y, (float) textSize.getWidth(), (float) textSize.getHeight()));//将复合域添加到PDF页面compositeField.draw(pdf.getPages().get(i).getCanvas());}//移除第一个页pdf.getPages().remove(pdf.getPages().get(pdf.getPages().getCount()-1));

完整代码

package dmyz.util;import com.spire.pdf.*;
import com.spire.pdf.automaticfields.PdfCompositeField;
import com.spire.pdf.automaticfields.PdfPageCountField;
import com.spire.pdf.automaticfields.PdfPageNumberField;
import com.spire.pdf.graphics.*;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;/*** @Author  魏一鹤* @Description  骑缝章生成* @Date 17:03 2022/6/27
**/public class AcrossPageSeal {public static void main(String[] args) throws IOException {//要生成的文件模板PdfDocument pdf = new PdfDocument();pdf.loadFromFile("D:\\File\\test\\wyh\\3页.pdf");//添加一个空白页,目的为了删除jar包添加的水印,后面再移除这一页pdf.getPages().add();//创建字体PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", Font.PLAIN, 10),true);//遍历文档中的页for (int i = 0; i < pdf.getPages().getCount(); i++) {Dimension2D pageSize = pdf.getPages().get(i).getSize();float y = (float) pageSize.getHeight() - 40;//初始化页码域PdfPageNumberField number = new PdfPageNumberField();//初始化总页数域PdfPageCountField count = new PdfPageCountField();//创建复合域PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.getBlack(), "第{0}页 共{1}页", number, count);//设置复合域内文字对齐方式compositeField.setStringFormat(new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Top));//测量文字大小Dimension2D textSize = font.measureString(compositeField.getText());//设置复合域的在PDF页面上的位置及大小compositeField.setBounds(new Rectangle2D.Float(((float) pageSize.getWidth() - (float) textSize.getWidth())/2, y, (float) textSize.getWidth(), (float) textSize.getHeight()));//将复合域添加到PDF页面compositeField.draw(pdf.getPages().get(i).getCanvas());}//移除第一个页pdf.getPages().remove(pdf.getPages().get(pdf.getPages().getCount()-1));//获取分割后的印章图片BufferedImage[] images = GetImage(pdf.getPages().getCount());float x = 0;float y = 0;//实例化PdfUnitConvertor类PdfUnitConvertor convert = new PdfUnitConvertor();PdfPageBase pageBase;//将图片绘制到PDF页面上的指定位置for (int i = 0; i < pdf.getPages().getCount(); i++){BufferedImage image= images[ i ];pageBase = pdf.getPages().get(i);x = (float)pageBase.getSize().getWidth() - convert.convertUnits(image.getWidth(), PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel) + 40;y = (float) pageBase.getSize().getHeight()/ 2;pageBase.getCanvas().drawImage(PdfImage.fromImage(image), new Point2D.Float(x, y));}System.out.println("x = " + x);System.out.println("y = " + y);//最终生成缝骑章   的结果pdf.saveToFile("D:\\File\\test\\wyh\\Result.pdf");}//定义GetImage方法,根据PDF页数分割印章图片static BufferedImage[] GetImage(int num) throws IOException {String originalImg = "D:\\File\\test\\wyh\\魏一鹤的测试印章.png";BufferedImage image = ImageIO.read(new File(originalImg));int rows = 1;int cols = num;int chunks = rows * cols;int chunkWidth = image.getWidth() / cols;int chunkHeight = image.getHeight() / rows;int count = 0;BufferedImage[] imgs = new BufferedImage[ chunks ];for (int x = 0; x < rows; x++) {for (int y = 0; y < cols; y++) {imgs[ count ] = new BufferedImage(chunkWidth, chunkHeight, image.getType());Graphics2D gr = imgs[ count++ ].createGraphics();gr.drawImage(image, 0, 0, chunkWidth, chunkHeight,chunkWidth * y, chunkHeight * x,chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, Color.WHITE,null);gr.dispose();}}return imgs;}}

处理前

处理后

错误已经消息

PDF头部报错:Evaluation Warning : The document was created with Spire.PDF for Java.相关推荐

  1. 使用 Spire.Pdf 生成书签但是有 Evaluation Warning : The document was created with Spire.PDF for .NET.

    使用 Spire.Pdf 生成书签但是有 Evaluation Warning : The document was created with Spire.PDF for .NET.字样 这里用到了两 ...

  2. 【Spire.PDF】Evaluation Warning : The document was created with Spire.PDF for .NET.

    记录学习过程 创建日期:2019-04-10 用Spire.PDF生成报告时出现警告语 1.删除第一个页(最好的方法) 因为警告语只会在文档的第一页生成,所有删除文档第一页即可 PdfDocument ...

  3. cmd输入pip报错_安装pip报错:WARNING: Retrying (Retry(total=4,...

    安装pip报错:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) afte ...

  4. 安装MySQL报错:[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defau

    win10安装mysql5.7.23(免安装版本)过程中 在执行mysqld --initialize命令时 报错: [Warning] TIMESTAMP with implicit DEFAULT ...

  5. IEEE pdf eXpress 报错Font TimesNewRomanPSMT is not embedded

    IEEE pdf eXpress 报错Font TimesNewRomanPSMT is not embedded @date:2022/09/28 @author: SUFEHeisenberg 在 ...

  6. vscode git报错 git warning: redirecting to https://xxx.xxx.xxxx/xxx/xxx.git/

    背景:最近从websotrm转到vscode 刚开始两周开发没有问题,后面有两个常用的项目push到远程库或者拉去远程库的更新都会报错: vscode git报错 git warning: redir ...

  7. IEEE PDF Express 报错Font Helvetica, Times-Roman is not embedded

    一.IEEE PDF Express 报错 最悲惨的是同一个地方跌倒两次,去年这个时候,我就遇到了这个问题,经过百度的广泛搜索,终于解决了.然而今年我又遇到了同样的问题-立马哭唧唧,这才认识到了写博客 ...

  8. antd From 表单报错:warning.js:6 Warning: [antd: Switch] value is not validate prop, do you mean checke?

    同样的是适用于Checkbox组件 在使用 antd 时,form 表单中使用 switch 报错: warning.js:6 Warning: [antd: Switch] value is not ...

  9. ansa导出NASTRAN的nas文件报错:warning: MATERIAL(s) were not output(undefined)

    我在练习官方文档算例nastran fatigeu时,ansa导出NASTRAN的nas文件报错:warning: MATERIAL(s) were not output(undefined),计算的 ...

最新文章

  1. 《通往奴役之路》读书笔记及读后感作文4800字
  2. python风变编程是骗局吗-风变编程:花时间学Python,是对自己未来最好的投资
  3. IIS8 使用FastCGI配置PHP环境支持 过程详解
  4. [html] marquee详解
  5. 大作文_p2_v1.0
  6. LOAD_TYPE_VERSION_MISMATCH与TYPELOAD_NEW_VERSION错误分析
  7. boost::mpl模块bind相关的测试程序
  8. php 不同权限登录界面,PHP中如何实现不同权限进入不同页面_后端开发
  9. Java并发(理论知识)—— 线程安全性
  10. 推荐系统(recommender systems):预测电影评分--构造推荐系统的一种方法:协同过滤(collaborative filtering )...
  11. MCSA / Windows Server 2016 使用Hyper-V组件搭建实验环境
  12. springSecurity分离资源服务器分析
  13. c语言中calloc函数,C 库函数 – calloc()
  14. Android输入事件从读取到分发三:InputDispatcherThread线程分发事件的过程
  15. H264中4x4、8x8和16x16尺寸对应场景
  16. 将工件模型(stp,stl等)转为均匀稠密点云(pcd,ply)
  17. MarkDown Pad2的Windows秘钥
  18. MySQL sum()函数
  19. Oracle——根据拼音首字母模糊查询某个字段
  20. 重学计算机网络(二) - 曾记否,查IP地址

热门文章

  1. 报错Can‘t locate Fasta_reader.pm in @INC (you may need to install the Fasta_reader module)
  2. CSS---idclass选择器
  3. Buffer对象与Blob对象
  4. java程序员表情包,跳槽大厂必看!
  5. qt5.15.2在银河麒麟v10sp1上编译源码后安装运行
  6. 嵌入式linux界面开发,嵌入式Linux系统图形及图形用户界面
  7. Linux程式设计之三(转)
  8. iOS网络构架 与 web服务器 (三次握手)
  9. 电气控制与PLC之间的本质区别是什么?
  10. 救命sql语句----navicat for oracle 误操作恢复语句