最新word转pdf模板导出 可分页 带图片 http://t.csdn.cn/JmWZb
1:jar包
<!-- itextpdf-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.4.3</version>
</dependency>
2:制作一个pdf模板 创建表单–编辑域
3:工具类:
/**
* pdf模板导出
*
* @param map
* @param out
* @throws Exception
*/
public static void creatPdf(Map<String, Object> map, OutputStream out) throws Exception {
try {
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 输出流
// String outPutPath = "/Users/xxx/Desktop/files/pdf模板导出.pdf";
// FileOutputStream out = new FileOutputStream(filePath);
// 读取pdf模板路径
PdfReader reader = new PdfReader(String.valueOf(map.get("tempPath")));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, bos);
stamper.setFormFlattening(true);
AcroFields form = stamper.getAcroFields();
// 文字类的内容处理
Map<String, String> datemap = (Map<String, String>) map.get("dataMap");
form.addSubstitutionFont(bf);
for (String key : datemap.keySet()) {
String value = datemap.get(key);
form.setField(key, value);
}
// 图片类的内容处理
Map<String, String> imgmap = (Map<String, String>) map.get("imgMap");
for (String key : imgmap.keySet()) {
String value = imgmap.get(key);
String imgpath