赞
踩
可以主页关注小程序【白哥Java】回复【PDF编辑软件】即可获取 或者直接联系博主也可
主页如下:
此处流程为文本域流程 图片或其他大致相同
生成模板PDF样式如下:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
public static String editPdfAndGetBase64(String srcPdfPath, String destPdfPath) throws Exception {
PdfReader reader = new PdfReader("C:\\Users\\Administrator\\Downloads\\附2:电子处方文件参考模板-副本.pdf");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields form = stamper.getAcroFields();
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
form.addSubstitutionFont(bf);
form.setField("patientName", "周大炮");
form.setField("age", "24岁");
form.setField("prescriptionType", "普通\n处方");
form.setField("hisRegistorNo", "263002");
form.setField("hisPrescriptionNo", "HE920394223");
form.setField("recipeDate", "2024-08-14");
form.setField("department", "内分泌内科");
form.setField("sex", "男");
form.setField("icdName", "蚊媒介的病毒性发热,其他特指的");
form.setField("drugs","1.瑞格列奈片 2mg*30片/盒 4盒"+"\n"+" 用法用量:口服 每天3次 一次2片"+"\n");
stamper.setFormFlattening(true);
stamper.close();
reader.close();
// 将ByteArrayOutputStream的内容写入文件
try (FileOutputStream fos = new FileOutputStream("D:\\处方流转\\12.pdf")) {
fos.write(baos.toByteArray());
}
// 将ByteArrayOutputStream的内容转换为Base64字符串
byte[] pdfBytes = baos.toByteArray();
String encode = Base64Utils.encode(pdfBytes);
// 返回Base64字符串
return encode;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。