作者:mobiledu2502931987 | 来源:互联网 | 2023-06-08 12:21
本文主要内容是:用java在pdf模板中加入数据,图片。废话不多说,举个非常简单的例子:首先创建word文档,导出PDF。用软件adobeacrobat打开,操作步骤如图:
本文主要内容是:用java在pdf模板中加入数据,图片。
废话不多说,举个非常简单的例子:
首先创建word文档,导出PDF。
用 软件adobe acrobat打开,操作步骤如图:
;
int pageNo = form.getFieldPositions("img").get(0).page;
Rectangle signRect = form.getFieldPositions("img").get(0).position;
float x = signRect.getLeft();
float y = signRect.getBottom();
// 读图片
Image image = Image.getInstance(imgpath);
// 获取操作的页面
PdfContentByte under = ps.getOverContent(pageNo);
// 根据域的大小缩放图片
image.scaleToFit(signRect.getWidth(), signRect.getHeight());
// 添加图片
image.setAbsolutePosition(x, y);
under.addImage(image);
//-------------------------------------------------------------
System.out.println("===============PDF导出成功=============");
} catch (Exception e) {
System.out.println("===============PDF导出失败=============");
e.printStackTrace();
} finally {
try {
ps.close();
reader.close();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
}
在浏览器上访问
www.localhost:8080/exportpdf
好了 pdf下载成功
效果图
感谢您的阅读