Pu Zhibing
2026-01-12 bd1bf2bde1db1b2349104808a9214245256784e8
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/pdf/TripSheetGenerator.java
@@ -64,7 +64,7 @@
    private void addLogoAndTitle(Document document) throws DocumentException {
        try {
            document.setMargins(10, 50, 50, 50); // 左=0,右=50,上=50,下=50(单位:pt)
            document.setMargins(0, 50, 50, 50); // 左=0,右=50,上=50,下=50(单位:pt)
            Resource logoResource = new ClassPathResource("static/img/logo.png");
            if (logoResource.exists()) {
                Image logo = Image.getInstance(logoResource.getURL());
@@ -73,7 +73,7 @@
                // 1. 调整表格列宽:左列刚好容纳logo,右列仅够放下文字(缩小间距)
                // 列宽比例:左列100pt(logo宽度),右列80pt(文字宽度,足够放下“贵人家园”)
                PdfPTable layoutTable = new PdfPTable(new float[]{81f, 100f}); // 左列(Logo),右列100f(文字)
                layoutTable.setWidthPercentage(35);
                layoutTable.setWidthPercentage(25);
                layoutTable.setSpacingAfter(15f); // 与下方主标题的间距不变
                layoutTable.setHorizontalAlignment(Element.ALIGN_LEFT); // 整体左对齐,避免居中导致的空隙
@@ -142,7 +142,7 @@
        Font infoFont = getChineseFont(10, Font.NORMAL);
        // 申请时间现在的时间
        String applyTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
// 首先定义SimpleDateFormat(可以是类的静态成员)
        // 首先定义SimpleDateFormat(可以是类的静态成员)
        SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String tripTimeStart = first.getBoardingTime() != null
@@ -167,7 +167,7 @@
        line1Table.setWidthPercentage(100);
        line1Table.setSpacingAfter(5f);
        // 列宽比例:分隔条列固定为8pt,内容列按比例分配
        line1Table.setWidths(new float[]{4, 200, 4, 374});
        line1Table.setWidths(new float[]{1, 300, 1, 374});
        // 列1:申请时间前的蓝色分隔条(宽度由表格列宽控制)
        line1Table.addCell(createBlueSeparatorCell());
@@ -195,7 +195,7 @@
        line2Table.setWidthPercentage(100);
        line2Table.setSpacingAfter(15f);
        // 与第一行保持完全相同的列宽比例(确保分隔条对齐)
        line2Table.setWidths(new float[]{4, 200, 4, 374});
        line2Table.setWidths(new float[]{1, 300, 1, 374});
        // 列1:手机号前的蓝色分隔条
        line2Table.addCell(createBlueSeparatorCell());
@@ -243,6 +243,8 @@
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        return cell;
    }
    private void addOrderTable(Document document, List<TripOrderVo> orders) throws DocumentException {
        // 调整列宽:第1列(序号)加宽至1.5f
        float[] columnWidths = {1.5f, 2f, 2f, 3f, 2f, 3f, 3f, 2f};
@@ -259,13 +261,15 @@
        for (String header : headers) {
            PdfPCell cell = new PdfPCell(new Paragraph(header, headerFont));
            cell.setBackgroundColor(headerBg);
            cell.setPadding(5);
            cell.setPadding(8);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(Rectangle.NO_BORDER); // 无边框
            table.addCell(cell);
        }
           SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 格式可根据需求调整
        SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 格式可根据需求调整
        // 单元格样式(居中对齐,统一处理)
        Font cellFont = getChineseFont(9, Font.NORMAL);
        cellFont.setColor(new BaseColor(80, 80, 80));
        for (int i = 0; i < orders.size(); i++) {
            TripOrderVo order = orders.get(i);
            // 序号列:强制居中,内容为 i+1
@@ -289,6 +293,9 @@
            );
            moneyCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            moneyCell.setPadding(5);
            moneyCell.setBorder(Rectangle.NO_BORDER); // 无边框
            moneyCell.setBorderWidthBottom(0.5f);
            moneyCell.setBorderColorBottom(new BaseColor(190, 190, 190));
            table.addCell(moneyCell);
        }
@@ -297,9 +304,13 @@
    // 辅助方法:创建居中对齐的单元格
    private void addCenteredCell(PdfPTable table, String text, Font font) {
        PdfPCell cell = new PdfPCell(new Paragraph(text != null ? text : "", font));
        Paragraph elements = new Paragraph(text != null ? text : "", font);
        PdfPCell cell = new PdfPCell(elements);
        cell.setPadding(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorder(Rectangle.NO_BORDER); // 无边框
        cell.setBorderWidthBottom(0.5f);
        cell.setBorderColorBottom(new BaseColor(190, 190, 190));
        table.addCell(cell);
    }