兴安出门证样式优化

This commit is contained in:
zc
2025-08-01 17:41:21 +08:00
parent 1ffda051bc
commit 34ffc7438e
3 changed files with 52 additions and 7 deletions

View File

@@ -588,8 +588,8 @@ public class VisCarryStuffController extends BaseController {
PdfWriter writer = PdfWriter.getInstance(document, baos);
// 添加水印事件处理器
PdfWatermark pdfWatermark = new PdfWatermark(watermarkUrl);
writer.setPageEvent(pdfWatermark);
// PdfWatermark pdfWatermark = new PdfWatermark(watermarkUrl);
// writer.setPageEvent(pdfWatermark);
document.open();
@@ -649,16 +649,61 @@ public class VisCarryStuffController extends BaseController {
}
document.add(dataTable);
document.add(new Paragraph("\n")); // 增加空行间距
// 生成二维码图片
// 创建底部表格2列左边二维码+文字,右边水印+文字)
PdfPTable footerTable = new PdfPTable(2);
footerTable.setWidthPercentage(80); // 调整表格宽度为80%
footerTable.setHorizontalAlignment(Element.ALIGN_CENTER); // 表格整体居中
footerTable.setSpacingBefore(20f);
// 左边列:二维码和文字(水平排列)
PdfPTable qrColumn = new PdfPTable(2);
qrColumn.setWidths(new float[]{1, 2});
qrColumn.setWidthPercentage(100);
// 添加二维码文字(左)并设置垂直居中
Paragraph qrText = new Paragraph("出门证二维码:", contentFont);
PdfPCell qrTextCell = new PdfPCell(qrText);
qrTextCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
qrTextCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 文字水平居中
qrTextCell.setBorder(Rectangle.NO_BORDER);
qrTextCell.setPaddingRight(-100); // 减小右边距
qrColumn.addCell(qrTextCell);
// 生成二维码图片(右)
CheckCodeVo checkCodeVo = visCarryStuffService.selectStuffCheckCode(id);
if (ObjectUtil.isNotNull(checkCodeVo) && StrUtil.isNotBlank(checkCodeVo.getCode())) {
BarcodeQRCode qrCode = new BarcodeQRCode(checkCodeVo.getCode(), 120, 120, null);
Image qrCodeImage = qrCode.getImage();
qrCodeImage.scaleAbsolute(100, 100);
qrCodeImage.setAlignment(Element.ALIGN_CENTER);
qrColumn.addCell(createCell(qrCodeImage, Element.ALIGN_CENTER)); // 图片居中
}
// 右边列:水印和文字(水平排列)
PdfPTable watermarkColumn = new PdfPTable(2);
watermarkColumn.setWidths(new float[]{1, 2});
watermarkColumn.setWidthPercentage(100);
// 添加水印文字(左)并设置垂直居中
Paragraph watermarkText = new Paragraph("出厂许可授权章:", contentFont);
PdfPCell watermarkTextCell = new PdfPCell(watermarkText);
watermarkTextCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
watermarkTextCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 文字水平居中
watermarkTextCell.setBorder(Rectangle.NO_BORDER);
watermarkTextCell.setPaddingRight(-80); // 减小右边距
watermarkColumn.addCell(watermarkTextCell);
// 添加水印图片(右)
Image watermarkImage = Image.getInstance(watermarkUrl);
watermarkImage.scaleAbsolute(90, 90);
watermarkColumn.addCell(createCell(watermarkImage, Element.ALIGN_CENTER)); // 图片居中
// 将左右列添加到底部表格
footerTable.addCell(createCell(qrColumn, Element.ALIGN_CENTER)); // 左列居中
footerTable.addCell(createCell(watermarkColumn, Element.ALIGN_CENTER)); // 右列居中
document.add(footerTable);
document.close();