java 实现pdf添加水印(多张页码时仍可实现添加水印效果)核心代码 extends PdfPageEventHelper方法,具体代码如下:
package com.sinosoft.compound.sci.service;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
import com.sinosoft.compound.util.PdfUtils;
/**
* 实现多页添加水印
* @author Administrator
*
*/
public class AddWaterMarkMorePages extends PdfPageEventHelper {
@Override
public void onStartPage(PdfWriter pdfWriter, Document document) {
PdfUtils.onEndPage(pdfWriter, document);
super.onStartPage(pdfWriter, document);
}
}
/**
* 项目简要情况附件声明
* @Date 2020年3月23日 上午11:28:43
* tag@param outputPath
* tag@param userCode
* tag@param sciProject
*/
public void createProjectBrief(String userCode, SciProject sciProject) {
String projectId=sciProject.getFdObjectid();//项目主键
String projectType=sciProject.getProjectType();//项目类型
String uuid=UUIDUtils.getUUID();//随机数、SciAttachment主键、上传sftp文件名
String fileName=uuid+Constants.PDF_TYPE;//文件名称
String allName=autoupload+projectId+"/"+fileName;//文件全名称
InputStream fileIn=null;
ByteArrayOutputStream baos=null;
SFTPClientUtils sftpUtils=null;
boolean falg=false;
try {
//生成PDF样式加数据填充
baos=this.newProjectSimpleInfoPdf(sciProject);
if(baos!=null){

这篇博客展示了如何使用Java实现PDF多页添加水印的功能。通过继承`PdfPageEventHelper`,并在`onStartPage`方法中调用`PdfUtils.onEndPage`来实现在每一页添加水印的效果。代码示例包括创建PDF文档,设置水印,并使用SFTPClientUtils进行文件上传。
最低0.47元/天 解锁文章
747





