java根据模板生成PDF

更新时间:2023-07-31 06:48:24 阅读: 评论:0

java根据模板⽣成PDF
⾸先你的制作⼀个pdf模板:
1.先⽤word做出模板界⾯
画单元格的时候需要考虑值的长度,像这⾥的状态可能会很长
2.⽂件另存为pdf格式⽂件
使⽤福昕PDF 打开,添加⽂本,以及需要添加值的地⽅,设置⽂本域,这个就是属性值职位有哪些
保存以后会⽣成PDF封⾯,需要去掉。
在线分封PDF
代码
@GetMapping("/downOrderDashboard/{orderNo}")
@ApiAuthority
public ResponEntity<byte[]> downOrderDashboard(@PathVariable String orderNo,
HttpServletRespon respon,
HttpServletRequest request) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = rialNumberService.downOrderDashboard(orderNo, request);        HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.tContentDispositionFormData("attachment", de("orderDB.pdf", "UTF-8"));        httpHeaders.tContentType(MediaType.parMediaType("application/pdf"));
byte[] bytes = ByteArray();
return new ResponEntity<byte[]>(bytes, httpHeaders,
HttpStatus.CREATED);
/*respon.tContentType("application/pdf");
respon.tContentLength(byteArrayOutputStream.size());
ServletOutputStream out = OutputStream();
byteArrayOutputStream.writeTo(out);
out.flush();*/
玩游戏的作文}
public ByteArrayOutputStream downOrderDashboard(String orderNo, HttpServletRequest request) {
log.info("orderNo=" + orderNo);
祛湿寒的最佳方法
ByteArrayOutputStream outputstream = null;
OrderDBDTO orderDashBoard = getOrderDashBoard(orderNo);
log.info("orderDashBoard" + String());青春年少
try {
//InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("classpath:pdf/orderDB.pdf");
ClassPathResource classPathResource = new ClassPathResource("pdf/orderDB.pdf");
InputStream inputStream =InputStream();
//File file = File("classpath:pdf/orderDB.pdf");
//String currentPath = ServletContext().getRealPath("\\");
//String TemplatePDF = currentPath + "resources\\"+ "pdf\\" + "orderDB.pdf";
log.info("inputStream"+inputStream);
PdfReader reader = new PdfReader(inputStream);
s开头的英文//new AbsolutePath());
outputstream = new ByteArrayOutputStream(4096);
PdfStamper stamp = new PdfStamper(reader, outputstream);
PdfContentByte under = UnderContent(1); /*使⽤中⽂字体*/
BaFont bf = ateFont("STSong-Light", "UniGB-UCS2-H", BaFont.NOT_EMBEDDED);
// Font FontChine = new Font(bf, 10, Font.NORMAL);
AcroFields form = AcroFields();
form.addSubstitutionFont(bf);  //简宋体
form.tField("productionOrderNo", ProductionOrderNo());
OrderStatusType[] values = OrderStatusType.values();
for (OrderStatusType value : values) {
Status().ResourceKey())){
form.tField("state",ResourceKey() );
}
}
form.tField("batchNo", BatchNo());
form.tField("lineName", LineName());
form.tField("productionDate", ProductionDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
心理咨询案例报告
form.tField("expiryDate", ExpiryDate().format(DateTimeFormatter.ISO_LOCAL_DATE));荷叶的诗句
List<OrderSn> orderSnList = OrderSnList();
for (int i = 0; i < orderSnList.size(); i++) {
form.tField("aggregationLevel"+(i+1), (i).getAggreLevelName());
form.tField("productCount"+(i+1), (i).getProductCount()+"");
form.tField("breakCount"+(i+1), (i).getBreakCount()+"");
form.tField("sampleCount"+(i+1), (i).getSampleCount()+"");
}
stamp.tFormFlattening(true);
stamp.clo();
reader.clo();
} catch (DocumentException e1) {
log.Message());
e1.printStackTrace();
} catch (IOException e2) {
log.Message());
漫说
e2.printStackTrace();
}
return outputstream;
}

本文发布于:2023-07-31 06:48:24,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1102813.html

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

标签:需要   模板   本域   考虑   状态   玩游戏   案例
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图