From 38553de8fe4a824919563db827019909caa65f9c Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期三, 24 十二月 2025 10:34:59 +0800
Subject: [PATCH] 修改了对应代码

---
 archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java |  609 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 593 insertions(+), 16 deletions(-)

diff --git a/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java b/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
index 723b026..41e1fe2 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
@@ -7,27 +7,47 @@
 import com.itextpdf.text.Font;
 import com.itextpdf.text.Image;
 import com.itextpdf.text.Rectangle;
-import com.itextpdf.text.pdf.BaseFont;
-import com.itextpdf.text.pdf.PdfPCell;
-import com.itextpdf.text.pdf.PdfPTable;
-import com.itextpdf.text.pdf.PdfWriter;
+import com.itextpdf.text.pdf.*;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.domain.ArchiveRecords;
+import com.ruoyi.domain.vo.DocumentMaterialFileStyle;
+import com.ruoyi.domain.vo.DocumentMaterialsVo;
+import com.ruoyi.domain.vo.DocumentMaterialsVoSmall;
+import com.ruoyi.service.IArchiveRecordsService;
+import com.ruoyi.service.IDocumentMaterialsService;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.imageio.ImageIO;
 import java.awt.*;
+import java.awt.Color;
 import java.awt.image.BufferedImage;
 import java.io.*;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
 
 @Service
 public class pdfGenerateService {
     @Autowired
     private BarcodeService barcodeService;
+    @Autowired
+    private IDocumentMaterialsService documentMaterialsService;
+
+    @Autowired
+    private IArchiveRecordsService iArchiveRecordsService;
     //鐢熶骇浜岀淮鐮�
     public byte[] createQrCodeN(String content, int width, int height) throws IOException {
         QrConfig config = new QrConfig(width, height);
 
-        config.setMargin(3);
+        config.setMargin(0);
         // 楂樼籂閿欑骇鍒�
         config.setErrorCorrection(ErrorCorrectionLevel.H);
         // 璁剧疆鍓嶆櫙鑹诧紝鏃簩缁寸爜棰滆壊锛堣嚜琛岄�夋嫨棰滆壊淇敼锛�
@@ -50,17 +70,521 @@
 
         return os.toByteArray();
     }
+    private void handleXSSFImages(XSSFSheet sheet, Document pdfDoc) throws Exception {
+        XSSFDrawing drawing = sheet.getDrawingPatriarch();
+        if (drawing == null) return;
+
+        for (XSSFShape shape : drawing.getShapes()) {
+            if (shape instanceof XSSFPicture) {
+                XSSFPicture pic = (XSSFPicture)shape;
+                XSSFClientAnchor anchor = pic.getPreferredSize();
+
+                // 鑾峰彇鍥剧墖鏁版嵁
+                byte[] bytes = pic.getPictureData().getData();
+                Image pdfImage = Image.getInstance(bytes);
+
+                // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
+                float imageWidth = pdfImage.getWidth();
+                float imageHeight = pdfImage.getHeight();
+                float scale = Math.min(
+                        (PageSize.A4.getWidth() - 100) / imageWidth,
+                        (PageSize.A4.getHeight() - 100) / imageHeight
+                );
+                pdfImage.scaleAbsolute(imageWidth * scale, imageHeight * scale);
+
+                // 娣诲姞鍥剧墖鍒癙DF
+                pdfDoc.add(pdfImage);
+                pdfDoc.add(Chunk.NEWLINE);
+            }
+        }
+    }
 
 
-    public void generatePdf(String pdfPath) throws IOException, DocumentException {
+
+
+    private static String getCellValue(Cell cell,FormulaEvaluator evaluator) {
+        //  System.out.println(cell);
+        if (cell == null) return "";
+        CellValue cellValue = evaluator.evaluate(cell);
+        if(cellValue==null)
+            return "";
+        //  System.out.println(cellValue.getCellType());
+        switch (cellValue.getCellType()) {
+            case STRING:
+                return cell.getStringCellValue();
+            case NUMERIC:
+                // 鑾峰彇鏁板�煎苟杞负鏁村瀷
+                double numericValue = cell.getNumericCellValue();
+                // 鍒ゆ柇鏄惁涓烘暣鏁�
+                if (numericValue == (int)numericValue) {
+                    if((int)numericValue==0)
+                        return "";
+                    else
+                        return String.valueOf((int)numericValue);
+                } else {
+                    return String.valueOf(numericValue); // 鎴栬�呮牴鎹渶瑕佽繑鍥炲洓鑸嶄簲鍏ョ殑鏁村瀷
+                }
+
+            case BOOLEAN:
+                return String.valueOf(cell.getBooleanCellValue());
+            case FORMULA:
+
+                return cell.getCellFormula()+"";
+            case BLANK:
+                return "";
+            default:
+                return "";
+        }
+    }
+    private int getRealLastCellNum(Row row) {
+        int lastCellNum = 0;
+        for (int i = 0; i < row.getLastCellNum(); i++) {
+            Cell cell = row.getCell(i);
+            if (cell != null && cell.getCellType() != CellType.BLANK) {
+                lastCellNum = i + 1;
+            }
+        }
+        return lastCellNum;
+    }
+
+    //
+    void generateSimpleExample()
+    {
+
+//        try {
+//            // 1. 璇诲彇Excel鏂囦欢
+//            String excelPath = RuoYiConfig.getProfile() + "/download/"+"鍗峰収鐩綍.xls";
+//            String pdfPath = RuoYiConfig.getProfile() + "/download/"+"1.pdf";
+//
+//            Workbook workbook = WorkbookFactory.create(new File(excelPath));
+//            FileOutputStream fos = new FileOutputStream(pdfPath);
+//            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
+//
+//
+//            // 鑾峰彇绗竴涓伐浣滆〃
+//            Sheet sheet = workbook.getSheetAt(1);
+//
+//            // 鍒涘缓PDF鏂囨。瀵硅薄
+//            Document document = new Document(PageSize.A2, 50, 50, 50, 50);
+//
+//            // 鍒涘缓PDF杈撳嚭娴�
+//            PdfWriter writer = PdfWriter.getInstance(document, fos);
+//            // 4. 澶勭悊宸ヤ綔琛ㄤ腑鐨勫浘鐗�
+//            if (workbook instanceof XSSFWorkbook) {
+//                handleXSSFImages((XSSFSheet)sheet, document);
+//            }
+//            // 鎵撳紑PDF鏂囨。
+//            document.open();
+//
+//            // 鍒涘缓PDF琛ㄦ牸瀵硅薄
+//            System.out.println(sheet.getRow(0).getLastCellNum()+"--00");
+//            PdfPTable table = new PdfPTable(sheet.getRow(0).getLastCellNum());
+//            table.setHeaderRows(1);
+//
+//            // 璁剧疆琛ㄦ牸瀹藉害
+//            table.setWidthPercentage(100);
+//
+//            // 璁剧疆琛ㄦ牸鏍囬
+//            Paragraph title = new Paragraph(sheet.getSheetName(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 16, Font.BOLD));
+//            title.setAlignment(Element.ALIGN_CENTER);
+//            document.add(title);
+//            // System.out.println(sheet.)
+//            // 娣诲姞琛ㄦ牸鍐呭
+//            for (Row row : sheet) {
+//                {
+//                    if (row == null) continue;
+//                    System.out.println(getRealLastCellNum(row)+"---987");
+////                            if(row.getRowNum()==0)
+////                                continue;
+//                    if(row.getRowNum()==2)
+//                    {
+//                        PdfPCell pdfCell = ImageSet(100);
+//                        pdfCell.setColspan(7);
+//                        pdfCell.setRowspan(3);
+//                        pdfCell.setBorderWidth(1f);
+//                        pdfCell.setBorderColor(BaseColor.BLACK);
+//                        pdfCell.setPadding(5f);
+//                        pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+//                        pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+//                        table.addCell(pdfCell);
+//                        System.out.println("{{{{{{{{{{{{{");
+//                        continue;
+//                    }
+//                    for (int i = 0; i < 7; i++)
+//                    {
+//
+//                        Cell cell = row.getCell(i);
+//                        if(row.getRowNum()==3)
+//                        {
+//                            PdfPCell pdfCell = new PdfPCell(new Paragraph("鍗峰唴鐩綍", new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
+//                            pdfCell.setColspan(7);
+//                            pdfCell.setBorderWidth(1f);
+//                            pdfCell.setBorderColor(BaseColor.BLACK);
+//                            pdfCell.setPadding(5f);
+//                            pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+//                            pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+//                            table.addCell(pdfCell);
+//                            System.out.println("{{{{{{{{{{{{{");
+//                            break;
+//                        }
+//                        if(cell==null) {
+//
+//                            table.addCell("");
+//                            continue;
+//                        }
+//                        PdfPCell pdfCell = new PdfPCell(new Paragraph(getCellValue(cell, evaluator), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
+//
+//                        if(row.getRowNum()!=1) {
+//                            pdfCell.setBorderWidth(1f);
+//                            pdfCell.setBorderColor(BaseColor.BLACK);
+//                            pdfCell.setPadding(5f);
+//                            pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+//                            pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+//                        }
+//                        if (cell.getRowIndex() == 5) {
+//                            pdfCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
+//                        }
+//
+//                        table.addCell(pdfCell);
+//
+//                    }
+//                }
+//            }
+//
+//            // 娣诲姞琛ㄦ牸鍒癙DF鏂囨。
+//            table.setSpacingBefore(20f);
+//            table.setSpacingAfter(20f);
+//            table.setKeepTogether(true);
+//            document.add(table);
+//
+//            // 鍏抽棴PDF鏂囨。
+//            document.close();
+//
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+
+    }
+
+
+    // 鑷畾涔夐〉闈簨浠剁被锛岀敤浜庡湪姣忎釜鏂伴〉闈㈡坊鍔犲嵎鍐呭皝闈㈠拰鍗峰彿
+    private class DirectoryHeaderPageEvent extends PdfPageEventHelper {
+        private String volumeNumber;
+        private BaseFont bfChinese;
+        private Font chineseFont;
+        private Font chineseFont1;
+        private Image barcodeImage;
+        
+        public DirectoryHeaderPageEvent(String volumeNumber, BaseFont bfChinese, Font chineseFont, Font chineseFont1, Image barcodeImage) {
+            this.volumeNumber = volumeNumber;
+            this.bfChinese = bfChinese;
+            this.chineseFont = chineseFont;
+            this.chineseFont1 = chineseFont1;
+            this.barcodeImage = barcodeImage;
+        }
+        
+        @Override
+        public void onStartPage(PdfWriter writer, Document document) {
+            try {
+                PdfContentByte cb = writer.getDirectContent();
+                float pageWidth = document.getPageSize().getWidth();
+                float pageHeight = document.getPageSize().getHeight();
+                
+                // 1. 娣诲姞鏉″舰鐮侊紙灞呬腑鏄剧ず锛岄〉闈㈤《閮級
+                float barcodeWidth = barcodeImage.getScaledWidth();
+                float barcodeHeight = barcodeImage.getScaledHeight();
+                float barcodeX = (pageWidth - barcodeWidth) / 2;
+                float barcodeY = pageHeight - 50 - barcodeHeight; // 椤甸潰椤堕儴涓嬫柟50鐐�
+                barcodeImage.setAbsolutePosition(barcodeX, barcodeY);
+                cb.addImage(barcodeImage);
+                
+                // 2. 娣诲姞鍗峰唴鐩綍鏍囬锛堝眳涓樉绀猴紝鏉″舰鐮佷笅鏂癸級
+                String title = "鍗�    鍐�    鐩�    褰�";
+                float titleX = pageWidth / 2;
+                float titleY = pageHeight - 100; // 椤甸潰椤堕儴涓嬫柟100鐐�
+                cb.beginText();
+                // 鍒涘缓骞惰缃爣棰樹负鍔犵矖瀛椾綋
+                Font boldTitleFont = new Font(bfChinese, 16, Font.BOLD);
+                cb.setFontAndSize(boldTitleFont.getBaseFont(), boldTitleFont.getSize());
+                cb.setColorFill(BaseColor.BLACK);
+                cb.showTextAligned(PdfContentByte.ALIGN_CENTER, title, titleX, titleY, 0);
+                cb.endText();
+                
+                // 3. 娣诲姞鍗峰彿锛堝眳鍙虫樉绀猴紝鏍囬涓嬫柟锛�
+                String label = "鍗峰彿锛�";
+                String value = volumeNumber;
+                float recordInfoX = pageWidth - 30;
+                float recordInfoY = pageHeight - 130; // 椤甸潰椤堕儴涓嬫柟130鐐�
+                
+                // 鍏堢粯鍒舵爣绛�"鍗峰彿锛�"
+                cb.beginText();
+                // 璁剧疆鍔犵矖瀛椾綋锛岄�氳繃Font.BOLD鍙傛暟
+                Font boldFont = new Font(bfChinese, 16, Font.BOLD);
+                cb.setFontAndSize(boldFont.getBaseFont(), boldFont.getSize());
+                cb.setColorFill(BaseColor.BLACK);
+                cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, label + value, recordInfoX, recordInfoY, 0);
+                cb.endText();
+                
+                // 璁$畻鍊肩殑浣嶇疆骞剁粯鍒朵笅鍒掔嚎
+                float labelWidth = bfChinese.getWidthPoint(label, 12);
+                float valueWidth = bfChinese.getWidthPoint(value, 12);
+                float underlineStartX = recordInfoX - valueWidth;
+                float underlineEndX = recordInfoX;
+                float underlineY = recordInfoY - 2;
+                
+                cb.setColorStroke(BaseColor.BLACK);
+                cb.setLineWidth(0.5f);
+                cb.moveTo(underlineStartX, underlineY);
+                cb.lineTo(underlineEndX, underlineY);
+                cb.stroke();
+                
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    
+    //瀵煎嚭鍗峰唴鐩綍鐨刾df
+    public void generateFileDirectoryPdf(String pdfPath,List<DocumentMaterialsVo> dvss) throws DocumentException, IOException {
+        Document document = new Document();
+        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
+        
+        // 璁剧疆涓枃瀛椾綋
+        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+        Font chineseFont = new Font(bfChinese, 12);
+        Font chineseFont1 = new Font(bfChinese, 16, Font.BOLD);
+        
+        // 鑾峰彇鍗峰彿
+        String volumeNumber = dvss.get(0).getRecordId();
+        
+        // 鍒涘缓鏉″舰鐮�
+        Image barcodeImage = Image.getInstance(barcodeService.generateBarcodeImage(volumeNumber));
+        barcodeImage.scaleToFit(80, 40); // 璁剧疆鏉″舰鐮佸ぇ灏�
+        
+        // 娉ㄥ唽椤甸潰浜嬩欢
+        DirectoryHeaderPageEvent pageEvent = new DirectoryHeaderPageEvent(volumeNumber, bfChinese, chineseFont1, chineseFont1, barcodeImage);
+        writer.setPageEvent(pageEvent);
+        
+        // 璁剧疆閫傚綋鐨勮竟璺濓紝涓哄嵎鍐呭皝闈€�佹潯褰㈢爜鍜屽嵎鍙烽鐣欑┖闂�
+        // setMargins(left, right, top, bottom) - 鍙傛暟椤哄簭锛氬乏銆佸彸銆佷笂銆佷笅
+        // 澧炲ぇ涓婅竟璺濅负160锛岀‘淇濋〉鐪夊唴瀹规湁瓒冲绌洪棿
+        document.setMargins(30, 30, 160, 30);
+        document.open();
+        
+        // 杩欓噷涓嶅啀闇�瑕佸湪绗竴椤垫墜鍔ㄦ坊鍔犲嵎鍐呭皝闈㈠唴瀹癸紝椤甸潰浜嬩欢浼氬鐞�
+        
+        // 娣诲姞涓�涓┖鐧芥钀斤紝纭繚琛ㄦ牸鍐呭涓嶄細涓庨《閮ㄥ厓绱犻噸鍙�
+        Paragraph blankParagraph = new Paragraph("");
+        document.add(blankParagraph);
+        
+        // 鍒涘缓琛ㄦ牸锛�7鍒楋級
+        PdfPTable table = new PdfPTable(7);
+
+        // 璁剧疆琛ㄦ牸瀹藉害锛堝崰椤甸潰瀹藉害鐨�80%锛屽眳涓樉绀猴級
+        table.setWidthPercentage(90);
+        table.setHorizontalAlignment(Element.ALIGN_CENTER);
+        
+        // 璁剧疆鍒楀姣斾緥锛岀4鍒楋紙鏂囦欢棰樺悕锛夊拰绗�2鍒楋紙鏂囦欢缂栧彿锛夎缃緱鏇村
+        float[] columnWidths = {10f, 16f, 14f, 30f, 10f, 10f, 10f}; // 璋冩暣鍒楀姣斾緥锛屽鍔犳枃浠剁紪鍙峰垪鐨勫搴�
+        table.setWidths(columnWidths);
+        // 璁剧疆琛ㄥご琛屾暟锛岃繖鏍峰垎椤垫椂姣忛〉閮戒細鑷姩閲嶅琛ㄥご
+        table.setHeaderRows(1);
+        
+        // 娣诲姞琛ㄥご
+        String[] headers = {"搴忓彿", "鏂囦欢缂栧彿", "璐d换鑰�", "鏂囦欢棰樺悕", "鏃ユ湡", "椤靛彿", "澶囨敞"};
+        for (String header : headers) {
+            PdfPCell cell = new PdfPCell(new Paragraph(header,
+                    chineseFont1));
+            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+            cell.setBackgroundColor(new BaseColor(200, 200, 200));
+            table.addCell(cell);
+        }
+
+        // 娣诲姞琛ㄦ牸鏁版嵁
+//        Object[][] data = {
+//              //  {1, "鍟嗗搧A", 2, 100.00, 200.00},
+//             //   {2, "鍟嗗搧B", 1, 250.50, 250.50},
+//             //   {3, "鍟嗗搧C", 3, 80.00, 240.00}
+//        };
+//        data.
+      //  for (Object[] row : data) {
+            for (DocumentMaterialsVo cellData : dvss) {
+                //搴忓彿
+                PdfPCell cell = new PdfPCell(new Paragraph(cellData.getNum().toString(),
+                        chineseFont));
+                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+                table.addCell(cell);
+
+
+                //鏂囦欢缂栧彿锛堟。鍙凤級
+                PdfPCell cell1 = new PdfPCell(new Paragraph(cellData.getDocumentNumber()==null?"":cellData.getDocumentNumber().toString(),
+                        new Font(bfChinese, 12)));
+                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
+                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                table.addCell(cell1);
+
+
+                //搴忓彿
+                PdfPCell cell2 = new PdfPCell(new Paragraph(cellData.getCreator()==null?"":cellData.getCreator().toString(),
+                        chineseFont));
+                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
+                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                table.addCell(cell2);
+
+
+                //搴忓彿
+                PdfPCell cell3 = new PdfPCell(new Paragraph(cellData.getTitle()==null?"":cellData.getTitle().toString(),
+                        chineseFont));
+                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
+                table.addCell(cell3);
+
+                //搴忓彿
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+               // String dateString = sdf.format(date);
+                PdfPCell cell4 = new PdfPCell(new Paragraph(cellData.getDate()==null?"":sdf.format(cellData.getDate()),
+                        chineseFont));
+                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
+                table.addCell(cell4);
+
+
+                //搴忓彿
+                PdfPCell cell5 = new PdfPCell(new Paragraph(cellData.getPageNumber()==null?"": cellData.getPageNumber().toString(),
+                        chineseFont));
+                cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
+                cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                table.addCell(cell5);
+
+                //搴忓彿
+                PdfPCell cell6 = new PdfPCell(new Paragraph(cellData.getRemarks()==null?"":cellData.getRemarks().toString(),
+                        chineseFont));
+                cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
+
+                cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
+                table.addCell(cell6);
+            }
+      //  }
+
+        document.add(table);
+        document.close();
+    }
+    //璁剧疆澶囪�冭〃
+   public void generateFileStyleInfo(String pdfPath, String volumeNumber, Long id) throws IOException, DocumentException {
+       Document document = new Document();
+       PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
+       document.open();
+
+// 鍒涘缓PDF鏂囨。
+       List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id));
+       if(dmfs.isEmpty())
+           return;
+
+
+       System.out.println(dmfs);
+       PdfWriter.getInstance(document, new FileOutputStream("09-澶囪�冭〃"+".pdf"));
+       document.open();
+       // 璁剧疆涓枃瀛椾綋
+
+       BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+       Font chineseFont = new Font(bfChinese, 16, Font.BOLD);
+       // 娣诲姞鏍囬
+       Paragraph title = new Paragraph("鍗峰唴澶囪�冭〃", chineseFont);
+       title.setAlignment(Element.ALIGN_CENTER);
+       document.add(title);
+
+       // 娣诲姞鍐呭
+     //  String volumeNumber = "D3.4.1-05-2024-0002";
+       
+       // 鍒涘缓鍗峰彿娈佃惤锛屼娇鐢–hunk鏉ュ崟鐙鐞嗗嵎鍙峰�煎苟娣诲姞涓嬪垝绾�
+       Paragraph recordInfo = new Paragraph();
+       Chunk labelChunk = new Chunk("鍗峰彿锛�", chineseFont);
+       Chunk valueChunk = new Chunk(volumeNumber, chineseFont);
+       valueChunk.setUnderline(0.5f, -2f); // 娣诲姞涓嬪垝绾匡紝0.5f鏄嚎瀹斤紝-2f鏄嚎涓庢枃瀛楃殑璺濈
+       
+       recordInfo.add(labelChunk);
+       recordInfo.add(valueChunk);
+       recordInfo.setAlignment(Element.ALIGN_RIGHT);
+       document.add(recordInfo);
+       int pcc = dmfs.size()<=1?0: dmfs.get(1).getCnt();
+       int oth = dmfs.size()<=2?0: dmfs.get(2).getCnt();
+       int allCnt = dmfs.get(0).getCnt() + pcc + oth;
+       document.add(new Paragraph("          鏈� 妗� 鍗� 鍏� 鏈� 鏂� 浠� 鏉� 鏂� " + allCnt + " 椤�"+"锛屽叾涓細鏂囧瓧鏉愭枡 " +
+               pcc + " 椤�"+"锛屽浘鏍锋潗鏂� " + oth + " 椤�"+"锛岀収鐗� " + dmfs.get(0).getCnt() + " 寮�", chineseFont));
+
+
+       document.add(new Paragraph("璇存槑: ", chineseFont));
+       // 鏂规硶2锛氫娇鐢ㄥ甫鎹㈣绗︾殑Paragraph
+       for(int i = 0; i < 10; i++) {
+           Paragraph withNewLine = new Paragraph("\n");
+           document.add(withNewLine);
+       }
+
+
+       String tis1 = "绔嬪嵎浜猴細浠囩縺锛堝箍宸炵泩瀹舵。妗堢鐞嗘湁闄愬叕鍙革級";
+       Paragraph par1 = new Paragraph(tis1, chineseFont);
+       par1.setAlignment(Element.ALIGN_RIGHT);
+       document.add(par1);
+       //鎷垮埌褰撳墠鏃堕棿
+       // 鑾峰彇褰撳墠鏃ユ湡
+       LocalDate currentDate = LocalDate.now();
+
+       // 鎵撳嵃骞淬�佹湀銆佹棩
+//       System.out.println("Year: " + currentDate.getYear());
+//       System.out.println("Month: " + currentDate.getMonthValue()); // 鏈堜唤鏄粠1寮�濮嬬殑
+//       System.out.println("Day of Month: " + currentDate.getDayOfMonth());
+       Paragraph withNewLine = new Paragraph("\n");
+       document.add(withNewLine);
+       String cdt = currentDate.getYear()+"骞�"+currentDate.getMonthValue()+"鏈�"+currentDate.getDayOfMonth()+"鏃�";
+
+
+       Paragraph par3 = new Paragraph(cdt, chineseFont);
+       par3.setAlignment(Element.ALIGN_RIGHT);
+       document.add(par3);
+       String tis2 = "瀹℃牳浜猴細鏇剧憺鑾癸紙骞垮窞鐩堝妗f绠$悊鏈夐檺鍏徃锛�";
+       document.add(withNewLine);
+
+       Paragraph par2 = new Paragraph(tis2, chineseFont);
+       par2.setAlignment(Element.ALIGN_RIGHT);
+       document.add(par2);
+       document.add(withNewLine);
+       document.add(par3);
+
+       document.close();
+
+   }
+
+    public void generatePdf(String pdfPath, Long id) throws IOException, DocumentException {
 
         Document document = new Document();
         PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
         document.open();
 
-        String [] tits = {"妗�        鍙�:","妗f棣�(瀹�)鍙�:","缂�  寰�  鍙�: ","鍙�  鏂�  鍙�:",
-                "妗�  鍗�  棰�  鍚�:","缂�  鍒�  鏃�  鏈�:","缂�  鍒�  鍗�  浣�:","淇�  绠�  鏈�  闄�:","瀵�     绾�:"};
-        String [] cons = {"D3.4.1-05-2024-0002","","","绌楄鍒掕祫婧愬缓璇併��2024銆�2033鍙�","骞垮窞甯傝嚜鏉ユ按鏈夐檺鍏徃鐧戒簯鍖烘睙楂橀晣姹熼珮闀囨斂搴滆タ渚с�佹睙搴滆矾鍖椾晶鐧戒簯鍖烘睙楂橀晣姹熼珮闀囨斂搴滆タ渚с�佹睙搴滆矾鍖椾晶鏂拌渚涙按绠″伐绋�","2024-04-23","骞垮窞甯傝鍒掑拰鑷劧璧勬簮灞�鐧戒簯鍖哄垎灞�","姘镐箙",""};
+        String [] tits = {"妗e彿锛�","妗f棣�(瀹�)鍙凤細","缂╁井鍙凤細","鍙戞枃鍙凤細",
+                "妗堝嵎棰樺悕锛�","缂栧埗鏃ユ湡锛�","缂栧埗鍗曚綅锛�","淇濈鏈熼檺锛�","瀵嗙骇锛�"};
+        ArchiveRecords ard = iArchiveRecordsService.selectArchiveRecordsById(id);
+
+
+        String formattedDate = "";
+        if(ard.getPreparationDate()!=null) {
+            LocalDate date = ard.getPreparationDate().toInstant()
+                    .atZone(ZoneId.systemDefault())
+                    .toLocalDate();
+            ;
+            System.out.println("褰撳墠鏃ユ湡: " + date);
+
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+      formattedDate = date.format(formatter);
+        }
+
+        String [] cons = {ard.getRecordId(),ard.getArchiveRoomNumber(),ard.getMicrofilmNumber(),ard.getInquiryNumber(),ard.getCaseTitle(),formattedDate,ard.getPreparationUnit(),
+                ard.getRetentionPeriod(),ard.getSecurityClassification()};
 
         //鎶婂浘鐗囧姞鍏ュ埌pdf褰撲腑
         Image img = Image.getInstance(createQrCodeN(cons[0], 80, 80));
@@ -81,7 +605,7 @@
         float[] columnWidths = {35f, 65f}; // 绗竴鍒�30%锛岀浜屽垪70%
         PdfPTable table = new PdfPTable(columnWidths);
 //        PdfPTable table = new PdfPTable(2);
-        table.setWidthPercentage(80); // 澧炲ぇ琛ㄦ牸瀹藉害鐧惧垎姣�
+        table.setWidthPercentage(78); // 鍑忓皬琛ㄦ牸瀹藉害鐧惧垎姣斾娇涓ゅ垪鏇寸揣鍑�
         table.setHorizontalAlignment(Element.ALIGN_LEFT); // 璁剧疆琛ㄦ牸鏁翠綋灞呬腑
         table.setSpacingBefore(30f); // 璁剧疆琛ㄦ牸鍓嶉棿璺�
         table.setSpacingAfter(90f); // 璁剧疆琛ㄦ牸鍚庨棿璺�
@@ -105,12 +629,64 @@
 
 
 
+        // 鍏堣绠楁墍鏈夋爣棰樼殑鏈�闀块暱搴�
+        int maxTitleLength = 0;
+        for (String tit : tits) {
+            maxTitleLength = Math.max(maxTitleLength, tit.length()-1);
+        }
+        
         for(int i = 0; i < tits.length; i++) {
             // 浣跨敤PdfPTable瀹炵幇绮剧‘瀵归綈
 
             // 绗竴琛岋細妗e彿
-            PdfPCell labelCell1 = new PdfPCell(new Phrase(tits[i], chineseFont));
-            labelCell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // 璁剧疆鍙冲榻�
+            // 瀹炵幇瀵归綈锛氬湪鏂囧瓧涔嬮棿濉厖绌烘牸锛屼娇鎵�鏈夋爣棰樻�婚暱搴︾浉鍚�
+            String originalText = tits[i];
+            
+            // 璁$畻闇�瑕佹坊鍔犵殑绌烘牸鏁�
+            int spacesToAdd = maxTitleLength - originalText.length();
+            
+            String formattedText = originalText;
+            if (spacesToAdd > 0) {
+                // 鍦ㄥ啋鍙峰墠鐨勬枃瀛椾箣闂村潎鍖�鍒嗛厤濉厖绌烘牸
+                if (originalText.contains("锛�")) {
+                    int colonIndex = originalText.indexOf("锛�");
+                    String textBeforeColon = originalText.substring(0, colonIndex);
+                    String textAfterColon = originalText.substring(colonIndex);
+                    
+                    // 濡傛灉鍐掑彿鍓嶅彧鏈変竴涓瓧绗︼紝鐩存帴鍦ㄥ悗闈㈠姞绌烘牸
+                    if (textBeforeColon.length() == 1) {
+                        String fullWidthSpaces = StringUtils.repeat("銆�", spacesToAdd);
+                        formattedText = textBeforeColon + fullWidthSpaces + textAfterColon;
+                    } else if (textBeforeColon.length() > 1) {
+                        // 鍦ㄦ枃瀛椾箣闂村潎鍖�鍒嗛厤绌烘牸
+                        StringBuilder sb = new StringBuilder();
+                        int chars = textBeforeColon.length();
+                        int spacesPerGap = spacesToAdd / (chars - 1);
+                        int extraSpaces = spacesToAdd % (chars - 1);
+                        
+                        for (int j = 0; j < chars; j++) {
+                            sb.append(textBeforeColon.charAt(j));
+                            if (j < chars - 1) {
+                                // 娣诲姞鍩烘湰绌烘牸
+                                sb.append(StringUtils.repeat("銆�", spacesPerGap));
+                                // 鍒嗛厤鍓╀綑绌烘牸
+                                if (j < extraSpaces) {
+                                    sb.append("銆�");
+                                }
+                            }
+                        }
+                        sb.append(textAfterColon);
+                        formattedText = sb.toString();
+                    }
+                } else {
+                    // 濡傛灉娌℃湁鍐掑彿锛岀洿鎺ュ湪鏈熬鍔犵┖鏍硷紙搴旇涓嶄細鍑虹幇杩欑鎯呭喌锛�
+                    String fullWidthSpaces = StringUtils.repeat("銆�", spacesToAdd);
+                    formattedText = originalText + fullWidthSpaces;
+                }
+            }
+            
+            PdfPCell labelCell1 = new PdfPCell(new Phrase(formattedText, chineseFont));
+            labelCell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // 鍗曞厓鏍煎彸瀵归綈
 
             labelCell1.setBorder(Rectangle.NO_BORDER);
 //            PdfPCell valueCell1 = new PdfPCell(new Phrase(cons[i], chineseFont));
@@ -119,17 +695,18 @@
             labelCell1.setPaddingTop(10f);    // 涓婂唴杈硅窛10鍗曚綅
             labelCell1.setPaddingBottom(10f); // 涓嬪唴杈硅窛10鍗曚綅
             labelCell1.setPaddingLeft(15f);   // 宸﹀唴杈硅窛15鍗曚綅
-            labelCell1.setPaddingRight(15f);  // 鍙冲唴杈硅窛15鍗曚綅
+            labelCell1.setPaddingRight(0f);  // 鍙冲唴杈硅窛15鍗曚綅
 
 
             PdfPCell valueCell1 = new PdfPCell(new Phrase(cons[i], chineseFont));
             valueCell1.setBorder(Rectangle.NO_BORDER);
-            valueCell1.setUseBorderPadding(true);
+            valueCell1.setUseBorderPadding(false); // 绂佺敤杈规鍐呰竟璺濊绠�
             valueCell1.setBorderWidthBottom(0.5f); // 璁剧疆搴曢儴杈规浣滀负涓嬪垝绾�
             valueCell1.setMinimumHeight(30);
             valueCell1.setPaddingTop(10f);    // 涓婂唴杈硅窛10鍗曚綅
             valueCell1.setPaddingBottom(10f); // 涓嬪唴杈硅窛10鍗曚綅
-            valueCell1.setPaddingLeft(15f);   // 宸﹀唴杈硅窛15鍗曚綅
+            valueCell1.setPaddingLeft(0f);   // 宸﹀唴杈硅窛0鍗曚綅
+            valueCell1.setExtraParagraphSpace(0f); // 绉婚櫎娈佃惤棰濆绌洪棿
             valueCell1.setPaddingRight(15f);  // 鍙冲唴杈硅窛15鍗曚綅
             table.addCell(labelCell1);
             table.addCell(valueCell1);
@@ -144,7 +721,7 @@
                 PdfPCell pdfPCell1 = new PdfPCell(img1);
                 pdfPCell1.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗�
 
-                pdfPCell1.setMinimumHeight(40);
+                pdfPCell1.setMinimumHeight(20);
                 pdfPCell1.setUseAscender(true); // 璁剧疆鍙互灞呬腑
                 pdfPCell1.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 璁剧疆姘村钩灞呬腑
                 pdfPCell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 璁剧疆鍨傜洿灞呬腑

--
Gitblit v1.9.1