1.使用itextpdf
gradle引入依赖
compile ("com.itextpdf:itextpdf:5.5.13")
compile ("com.itextpdf:itext-asian:5.2.0")
compile ("com.itextpdf.tool:xmlworker:5.5.13")
参考:
https://www.cnblogs.com/ssslinppp/p/4976922.html
https://www.cnblogs.com/liyh321/p/14072375.html
解决自定义字体ttc ,加",1"是新宋体 ",0"是宋体
https://www.cnblogs.com/oskyhg/p/7248438.html
2.itextpdf5.x实现合同签署盖章预览功能
https://blog.csdn.net/qq_34905631/article/details/129345804
3.stream流分组问题
https://blog.csdn.net/m0_46434219/article/details/109068536#:~:text=Collecto,%E5%8F%AF%E4%BB%A5%E5%81%9A%E8%81%9A%E5%90%88%E8%BF%90%E7%AE%97%E3%80%82
4.itextpdf生成虚线问题
class CustomCellSlant implements PdfPCellEvent {
private PdfPCell cell;
private Rectangle position;
private PdfContentByte[] canvases;
@Override
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
this.cell = cell;
this.position = position;
this.canvases = canvases;
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
cb.saveState();
cb.setLineWidth(1f);
//第一个参数是设置虚线的单个线的长度,如果为0的话就看不到了线了,第2个参数参数是设置线之间的距离,当等于0时就为实线了
cb.setLineDash(new float[] {5.0f, 2.0f}, 0);
cb.moveTo(position.getLeft(), position.getBottom());
cb.lineTo(position.getRight(), position.getBottom());
cb.stroke();
cb.restoreState();
}
}
5.springboot获取resource下的静态资源
//获取resource/static/font下的中文字体库
String font = this.getClass().getResource("/static/font/SIMSUN.TTC").getPath();
//用流的方式获取resource/static/images/logo.png
InputStream inputStream = this.getClass().getResourceAsStream("/static/images/logo.png");