| | |
| | | * @Date: 2025/9/29 |
| | | **/ |
| | | public class PdfUtil { |
| | | public static void addBlankPageAtBeginning(String sourcePath, String targetPath) throws IOException { |
| | | public static void addBlankPageAtBeginning(String sourcePath, String targetPath, String name) throws IOException { |
| | | // 读取源PDF文档 |
| | | PdfReader reader = new PdfReader(sourcePath); |
| | | PdfWriter writer = new PdfWriter(targetPath); |
| | |
| | | // 设置字体和大小,并移动到指定位置 |
| | | canvas.beginText() |
| | | .setFontAndSize(PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"), 14) |
| | | .moveText(100, 700) |
| | | .showText("请打印移交此版本数据") |
| | | .moveText(100, 700) // 调整起始Y坐标使内容更靠近页面顶部 |
| | | .showText("资料名称:" + name) |
| | | .moveText(0, -20) // 每次向下移动一定距离以换行 |
| | | .showText("接收时间:2025-11-04") |
| | | .moveText(0, -20) |
| | | .showText("移交纸质资料时请移交此版本数据") |
| | | .endText(); |
| | | // 关闭文档 |
| | | pdfDoc.close(); |
| | | reader.close(); |
| | | |