javapdfreader去除水印_Java操作PDF,在PDF文件指定位置输出水印
javapdfreader去除⽔印_Java操作PDF,在PDF⽂件指定位置
输出⽔印
packagecom.alphajuns.util;BaseColor;DocumentException;importcom.itextpdf.t @Author AlphaJunS
邱泽唐嫣公开恋情* @Date 19:25 2020/3/7
* @Description ⽂档帮助类*/
public classPDFDocHelper {private static BaseFont base = null;//获取基础⽂字
public static BaseFont getBaseFont() throwsDocumentException, IOException {if (base == null) {try{
base= ateFont("/u01/,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
win7补丁>电脑自动开机
}catch(Throwable th) {
三国杀新标准版base= ateFont("C:\\WINDOWS\\Fonts\\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
}
}returnbase;
}//psw⽂件签名
public static String signPsw(String oldPswFilePath, List> reviews) throwsIOException, DocumentException {int pos = oldPswFilePath.lastIndexOf('.');//获取⽂件后缀
String suffix = oldPswFilePath.substring(pos + 1);//判断是否为pdf⽂件
if (!"pdf".LowerCase())) {throw new RuntimeException("Not supported PSW file");
}returnsignSinglePsw(oldPswFilePath, reviews);
}//单个psw⽂件签名
private static String signSinglePsw(String oldPswFilePath,List> reviews) throwsIOException, Docum
entException {
String newPswPath=oldPswFilePath;int pos = oldPswFilePath.lastIndexOf('.');//获取⽂件后缀名
信息管理与信息系统是学什么的String suffix = oldPswFilePath.substring(pos + 1);//⽣成新的⽂件路径
newPswPath = oldPswFilePath.substring(0, pos) + ".PSW." +suffix;
System.out.println("单个psw⽂件签名⽣成的新路径:" +newPswPath);
PdfReader reader= newPdfReader(oldPswFilePath);
FileOutputStream fout= newFileOutputStream(newPswPath);
PdfStamper stp= newPdfStamper(reader, fout);//总页数
三国武将
System.out.println("PDF总页数:" +NumberOfPages());for (int i = 0; i
i++;
PdfContentByte OverContent(i);
content.beginText();//设置字体及字号
content.setFontAndSize(getBaseFont(), 10);
Map review = (Map) (reviews.size() - 1);
addDeptReview(content, review);
}
stp.close();//将输出流关闭
fout.close();
reader.close();//⽂件读写结束
System.out.println("PSW⽂件读写完毕");returnnewPswPath;
}/*** @Author AlphaJunS
* @Date 18:48 2020/3/7
* @Description 添加⽔印
*@paramcontent
*@paramreview
*@returnvoid*/
private static void addDeptReview(PdfContentByte content, Mapreview) {if (Integer.parseInt(String.("type"))) == 1) {
content.setColorFill(BaseColor.BLUE);
}else{
content.setColorFill(BaseColor.RED);
}//设置⽔印位置和内容
String result = (String) ("result");
System.out.println("⽔印内容:" +result);
System.out.println("打印位置坐标:" + pswX[0] + "," + pswY[0]);
content.showTextAligned(Element.ALIGN_LEFT, result, pswX[0], pswY[0], 0);
}//打印⽔印坐标
private static float[] pswY = {128};private static float[] pswX = {337};
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。