如何获取pdf文件中内容的末尾的位置? pdf水印 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用代码在合同中处理 然后导出pdf啊 /** * * @Title: createWaterMarkSpread2PDF * @Description: 针对PDF添加水印图片,并根据间隙计算,平铺 居中显示 * @param srcFilePath 源文件 * @param savePath 保存文件 * @param waterMarkPath 水印图片 * @param spaceX 横向间隙 * @param spaceY 纵向间隙 * @return * @throws IOException * @throws DocumentException */ public static void createWaterMarkSpread2PDF(String srcFilePath, String savePath, String waterMarkPath,float spaceX,float spaceY) throws IOException, DocumentException{ PdfReader pdfReader = null; PdfStamper pdfStamper = null; try{ pdfReader = new PdfReader(srcFilePath); pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(savePath));; int pageCount = pdfReader.getNumberOfPages()+1;//获取PDF页数 Image image = Image.getInstance(waterMarkPath); Rectangle size = pdfReader.getPageSize(1); float pdfY = size.top();//PDF页面高度 float pdfX = size.right();//PDF页面宽度 Dimension dim = ImageUtil.getDim4Image(waterMarkPath); PageSpreadSize pss = getPageSpreadSize(size, dim, spaceX, spaceY); PdfContentByte content=null; float heightWithSpace = (float)dim.getHeight()+(Float.isNaN(spaceY)||spaceY<=0?0:spaceY/2); float widthWithSpace = (float)dim.getWidth()+(Float.isNaN(spaceX)||spaceX<=0?0:spaceX/2); boolean isSpread = isImageSpread(pss);//是否平铺 //起始位置信息 float startX = isSpread?(pdfX-widthWithSpace*pss.getSizeX())/2:(float)(pdfX/2-dim.getWidth()/2); float startY = isSpread?pdfY -(pdfY-heightWithSpace*pss.getSizeY())/2:((float)(pdfY/2-dim.getHeight()/2)); //给每页增加水印 for (int i = 1; i < pageCount; i++) { content = pdfStamper.getOverContent(i); float posY = pdfY;//Y坐标绝对路径 if(!isSpread){ image.setAbsolutePosition(startX, startY); content.addImage(image); } else{ //行 for(int pi=1; pi<=pss.getSizeY(); pi++){ posY = startY - pi*heightWithSpace; float posX=0f; //X坐标绝对路径 //列 for(int py=1; py<=pss.getSizeX(); py++){ posX = startX+(py-1)*widthWithSpace; image.setAbsolutePosition(posX, posY); content.addImage(image); } } } content = null;//便于及时回收 } }finally{ if(pdfStamper!=null){ pdfStamper.close(); pdfStamper = null; pdfReader = null; } } } 新手求教,一个JSP做猜数字游戏的排行榜 QBC查询时间段问题,急!!!! 做一个简单的javabean(判断输入三边是否能构成三角),运行出错:Cannot find any information on property '*' ,还请哪位高人讲解,不盛感激 求帮 急啊 struts问题啊 使用struts,用户登录有必要采用md5之类的算法加密吗? 帮帮忙吧。 有谁成功配置过mvnforum! 初学者问题,javabean计数器高分求解 请教各位高手,有关EJB的问题 图片按钮传action的问题 如何在js定义这个全局变量?
/**
*
* @Title: createWaterMarkSpread2PDF
* @Description: 针对PDF添加水印图片,并根据间隙计算,平铺 居中显示
* @param srcFilePath 源文件
* @param savePath 保存文件
* @param waterMarkPath 水印图片
* @param spaceX 横向间隙
* @param spaceY 纵向间隙
* @return
* @throws IOException
* @throws DocumentException
*/
public static void createWaterMarkSpread2PDF(String srcFilePath, String savePath, String waterMarkPath,float spaceX,float spaceY) throws IOException, DocumentException{
PdfReader pdfReader = null;
PdfStamper pdfStamper = null;
try{
pdfReader = new PdfReader(srcFilePath);
pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(savePath));;
int pageCount = pdfReader.getNumberOfPages()+1;//获取PDF页数
Image image = Image.getInstance(waterMarkPath);
Rectangle size = pdfReader.getPageSize(1);
float pdfY = size.top();//PDF页面高度
float pdfX = size.right();//PDF页面宽度
Dimension dim = ImageUtil.getDim4Image(waterMarkPath);
PageSpreadSize pss = getPageSpreadSize(size, dim, spaceX, spaceY);
PdfContentByte content=null;
float heightWithSpace = (float)dim.getHeight()+(Float.isNaN(spaceY)||spaceY<=0?0:spaceY/2);
float widthWithSpace = (float)dim.getWidth()+(Float.isNaN(spaceX)||spaceX<=0?0:spaceX/2);
boolean isSpread = isImageSpread(pss);//是否平铺
//起始位置信息
float startX = isSpread?(pdfX-widthWithSpace*pss.getSizeX())/2:(float)(pdfX/2-dim.getWidth()/2);
float startY = isSpread?pdfY -(pdfY-heightWithSpace*pss.getSizeY())/2:((float)(pdfY/2-dim.getHeight()/2));
//给每页增加水印
for (int i = 1; i < pageCount; i++) {
content = pdfStamper.getOverContent(i);
float posY = pdfY;//Y坐标绝对路径
if(!isSpread){
image.setAbsolutePosition(startX, startY);
content.addImage(image);
}
else{
//行
for(int pi=1; pi<=pss.getSizeY(); pi++){
posY = startY - pi*heightWithSpace;
float posX=0f; //X坐标绝对路径
//列
for(int py=1; py<=pss.getSizeX(); py++){
posX = startX+(py-1)*widthWithSpace;
image.setAbsolutePosition(posX, posY);
content.addImage(image);
}
}
}
content = null;//便于及时回收
}
}finally{
if(pdfStamper!=null){
pdfStamper.close();
pdfStamper = null;
pdfReader = null;
}
}
}