From 5de5db24efe1b25896c37f395124a207584bcb38 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期四, 01 一月 2026 21:25:54 +0800
Subject: [PATCH] 修改了对应代码

---
 archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java |   47 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 43 insertions(+), 4 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 41e1fe2..46f710a 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
@@ -43,23 +43,62 @@
 
     @Autowired
     private IArchiveRecordsService iArchiveRecordsService;
+    private static BufferedImage trimWhiteBorder(BufferedImage img) {
+        int width = img.getWidth();
+        int height = img.getHeight();
+
+        int minX = width, minY = height, maxX = 0, maxY = 0;
+
+        // 鏌ユ壘闈炵櫧鑹插儚绱犵殑杈圭晫
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                int rgb = img.getRGB(x, y);
+                // 濡傛灉涓嶆槸鐧借壊
+                if ((rgb & 0x00FFFFFF) != 0x00FFFFFF) {
+                    if (x < minX) minX = x;
+                    if (x > maxX) maxX = x;
+                    if (y < minY) minY = y;
+                    if (y > maxY) maxY = y;
+                }
+            }
+        }
+
+        // 濡傛灉鍏ㄦ槸鐧借壊锛岃繑鍥炲師鍥�
+        if (minX > maxX || minY > maxY) {
+            return img;
+        }
+
+        // 瑁佸壀
+        int newWidth = maxX - minX + 1;
+        int newHeight = maxY - minY + 1;
+
+        // 娣诲姞1鍍忕礌瀹夊叏杈硅窛锛堝彲閫夛級
+        minX = Math.max(0, minX - 1);
+        minY = Math.max(0, minY - 1);
+        newWidth = Math.min(width - minX, newWidth + 2);
+        newHeight = Math.min(height - minY, newHeight + 2);
+
+        return img.getSubimage(minX, minY, newWidth, newHeight);
+    }
     //鐢熶骇浜岀淮鐮�
     public byte[] createQrCodeN(String content, int width, int height) throws IOException {
         QrConfig config = new QrConfig(width, height);
 
-        config.setMargin(0);
+        config.setMargin(2);
         // 楂樼籂閿欑骇鍒�
         config.setErrorCorrection(ErrorCorrectionLevel.H);
         // 璁剧疆鍓嶆櫙鑹诧紝鏃簩缁寸爜棰滆壊锛堣嚜琛岄�夋嫨棰滆壊淇敼锛�
-        config.setForeColor(new Color(11, 11, 11).getRGB());
-// 璁剧疆鑳屾櫙鑹诧紙鐏拌壊锛夐渶瑕佽儗鏅壊鏃跺�欐墦寮�閾炬帴
-        config.setBackColor(new Color(242,242,242).getRGB());
+        config.setForeColor(java.awt.Color.BLACK);
+        config.setBackColor(java.awt.Color.WHITE);
 
 
         BufferedImage bufferedImage = QrCodeUtil.generate(//
                 content, //浜岀淮鐮佸唴瀹�
                 config
         );
+
+        // 姝ラ2锛氭墜鍔ㄨ鍓櫧杈�
+        bufferedImage = trimWhiteBorder(bufferedImage);
         System.out.println(bufferedImage);
         System.out.println("---02340230949394");
         ByteArrayOutputStream os = new ByteArrayOutputStream();

--
Gitblit v1.9.1