Commit 21b5ea80 authored by 盖献康's avatar 盖献康

Merge branch 'gaixiankang' into 'dev'

企业留档文件 - bug(70966)

See merge request !265
parents 8ed11595 4e3ea177
...@@ -202,12 +202,17 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -202,12 +202,17 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 新建 // 新建
PdfBaseWriter document = new PdfBaseWriter(outputStream); PdfBaseWriter document = new PdfBaseWriter(outputStream);
document.setMargins(40, 40, 50,40);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
MyHeaderFooter headerFooter = new MyHeaderFooter();
headerText = data.getInspectionCenterName();
writer.setPageEvent(headerFooter);
// 打开 // 打开
document.open(); document.open();
// 内容 // 内容
// 封面 // 封面
document.setParagraph(data.getInspectionCenterName(), 12f, 0, 60,15f, 120f); document.setParagraph(" ", 30f, Element.ALIGN_CENTER, 0,60f, 40f);
document.setParagraph("企业留档文件", 30f, Element.ALIGN_CENTER, 0,15f, 180f); document.setParagraph("企业留档文件", 30f, Element.ALIGN_CENTER, 0,60f, 180f);
PdfPTable customTable = new PdfPTable(new float[]{15, 50}); PdfPTable customTable = new PdfPTable(new float[]{15, 50});
customTable.setWidthPercentage(70); customTable.setWidthPercentage(70);
document.writeNoBorderCell("检验依据:", Element.ALIGN_LEFT, 1, 1, customTable); document.writeNoBorderCell("检验依据:", Element.ALIGN_LEFT, 1, 1, customTable);
...@@ -222,7 +227,6 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -222,7 +227,6 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
document.setParagraph(data.getInspectionCenterName(), 20f, Element.ALIGN_CENTER, 0, 100f, 0f); document.setParagraph(data.getInspectionCenterName(), 20f, Element.ALIGN_CENTER, 0, 100f, 0f);
// 下一页 // 下一页
document.newPage(); document.newPage();
document.setParagraph(data.getInspectionCenterName(), 12f, 0, 30,15f, 20f);
// 创建表格 // 创建表格
List<String> list = Arrays.asList("文件名称", "文件目录", "标准章节", "标准要求", "审查要点"); List<String> list = Arrays.asList("文件名称", "文件目录", "标准章节", "标准要求", "审查要点");
float[] columnWidths = {30, 25, 25, 60, 60}; float[] columnWidths = {30, 25, 25, 60, 60};
...@@ -255,6 +259,31 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -255,6 +259,31 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
return uploadMinio(outputStream, "企业留档文件-" + getReportName()); return uploadMinio(outputStream, "企业留档文件-" + getReportName());
} }
private static String headerText;
public static class MyHeaderFooter extends PdfPageEventHelper {
// 一页加载完成触发,写入页眉和页脚
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfPTable table = new PdfPTable(1);
try {
table.setTotalWidth(PageSize.A4.getWidth() - 80);
table.setWidths(new int[] { 40 });
table.setLockedWidth(true);
table.getDefaultCell().setFixedHeight(-10);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.getDefaultCell().setBorderWidth(0.5f);
BaseFont font = BaseFont.createFont("/fonts/STSong.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
table.addCell(new Paragraph(headerText, new Font(font)));// 可以直接使用addCell(str),不过不能指定字体,中文无法显示
// 将页眉写到document中,位置可以指定,指定到下面就是页脚
table.writeSelectedRows(0, -1, 40, PageSize.A4.getHeight() - 20, writer.getDirectContent());
} catch (Exception de) {
throw new ExceptionConverter(de);
}
}
}
/** /**
* 获取企业留档文件数据 * 获取企业留档文件数据
* @param taskId * @param taskId
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment