From 9e1a75cb81c360ab1d2046fd98bd73b643d2b503 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期二, 14 十月 2025 16:55:02 +0800
Subject: [PATCH] 修改了对应的代码

---
 archiveManager/src/main/java/com/ruoyi/service/impl/IArchiveDoublePdfGenerateServiceImpl.java |  132 +++++++++++++++++++++++++++++--------------
 1 files changed, 88 insertions(+), 44 deletions(-)

diff --git a/archiveManager/src/main/java/com/ruoyi/service/impl/IArchiveDoublePdfGenerateServiceImpl.java b/archiveManager/src/main/java/com/ruoyi/service/impl/IArchiveDoublePdfGenerateServiceImpl.java
index 248e725..6b4c30d 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/IArchiveDoublePdfGenerateServiceImpl.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/IArchiveDoublePdfGenerateServiceImpl.java
@@ -1,13 +1,13 @@
 package com.ruoyi.service.impl;
 
+import cn.hutool.json.JSONObject;
 import com.ruoyi.service.IArchiveDoublePdfGenerateService;
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.ParseException;
 import org.apache.http.client.ClientProtocolException;
 
-
+import cn.hutool.http.HttpRequest;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -15,6 +15,7 @@
 import org.apache.http.util.EntityUtils;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.nio.file.Files;
@@ -29,54 +30,97 @@
     private  String MUL_LAYER_PDF_DOWNLOAD_URL = OCRServer + "api/doc/download";
 
 
-
-
-    public void testConnection()
-    {
-        // 鑾峰緱Http瀹㈡埛绔�(鍙互鐞嗚В涓�:浣犲緱鍏堟湁涓�涓祻瑙堝櫒;娉ㄦ剰:瀹為檯涓奌ttpClient涓庢祻瑙堝櫒鏄笉涓�鏍风殑)
-        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
-        // 鍒涘缓Get璇锋眰
-        HttpGet httpGet = new HttpGet(OCRServer);
-
-        // 鍝嶅簲妯″瀷
-        CloseableHttpResponse response = null;
-        try {
-            // 鐢卞鎴风鎵ц(鍙戦��)Get璇锋眰
-            response = httpClient.execute(httpGet);
-            // 浠庡搷搴旀ā鍨嬩腑鑾峰彇鍝嶅簲瀹炰綋
-            HttpEntity responseEntity = response.getEntity();
-            System.out.println("鍝嶅簲鐘舵�佷负:" + response.getStatusLine());
-            if (responseEntity != null) {
-                System.out.println("鍝嶅簲鍐呭闀垮害涓�:" + responseEntity.getContentLength());
-                System.out.println("鍝嶅簲鍐呭涓�:" + EntityUtils.toString(responseEntity));
-            }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-        } catch (ParseException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                // 閲婃斁璧勬簮
-                if (httpClient != null) {
-                    httpClient.close();
-                }
-                if (response != null) {
-                    response.close();
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
+    public void unicodeEscapeToChinese (String unicodeEscapedString) {
+        // 瑙g爜Unicode杞箟搴忓垪
+        StringBuilder decodedString = new StringBuilder();
+        int i = 0;
+        while (i < unicodeEscapedString.length()) {
+            if (unicodeEscapedString.startsWith("\\u", i)) {
+                // 鎵惧埌涓�涓猆nicode杞箟搴忓垪
+                int codePoint = Integer.parseInt(unicodeEscapedString.substring(i + 2, i + 6), 16);
+                decodedString.appendCodePoint(codePoint);
+                i += 6; // 璺宠繃杩欎釜Unicode杞箟搴忓垪
+            } else {
+                // 涓嶆槸Unicode杞箟搴忓垪锛岀洿鎺ユ坊鍔犲瓧绗�
+                decodedString.append(unicodeEscapedString.charAt(i));
+                i++;
             }
         }
+        // 鎵撳嵃瑙g爜鍚庣殑瀛楃涓�
+        System.out.println(decodedString.toString());
+    }
+
+
+    public void testConnection() throws IOException {
+        File pdfFile = new File("34.pdf");
+        String base64 = java.util.Base64.getEncoder().encodeToString(Files.readAllBytes(pdfFile.toPath()));
+
+        JSONObject inputObject = new JSONObject();
+        inputObject.put("base64", base64);
+        //inputObject.put("options", new JSONObject().put("ocr.language", "models/config_chinese.txt"));
+
+        String response = HttpRequest.post(OCRServer+ "api/doc/result")
+                .body(inputObject.toString())
+                .contentType("application/json")
+                .execute()
+                .body();
+        unicodeEscapeToChinese(response);
+       // System.out.println("unicodeEscapeToChinese("\u672a\u586b\u5199id\u3002"));
+//        // 鑾峰緱Http瀹㈡埛绔�(鍙互鐞嗚В涓�:浣犲緱鍏堟湁涓�涓祻瑙堝櫒;娉ㄦ剰:瀹為檯涓奌ttpClient涓庢祻瑙堝櫒鏄笉涓�鏍风殑)
+//        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+//        // 鍒涘缓Get璇锋眰
+//        HttpGet httpGet = new HttpGet(OCRServer);
+//
+//        // 鍝嶅簲妯″瀷
+//        CloseableHttpResponse response = null;
+//        try {
+//            // 鐢卞鎴风鎵ц(鍙戦��)Get璇锋眰
+//            response = httpClient.execute(httpGet);
+//            // 浠庡搷搴旀ā鍨嬩腑鑾峰彇鍝嶅簲瀹炰綋
+//            HttpEntity responseEntity = response.getEntity();
+//            System.out.println("鍝嶅簲鐘舵�佷负:" + response.getStatusLine());
+//            if (responseEntity != null) {
+//                System.out.println("鍝嶅簲鍐呭闀垮害涓�:" + responseEntity.getContentLength());
+//                System.out.println("鍝嶅簲鍐呭涓�:" + EntityUtils.toString(responseEntity));
+//            }
+//        } catch (ClientProtocolException e) {
+//            e.printStackTrace();
+//        } catch (ParseException e) {
+//            e.printStackTrace();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            try {
+//                // 閲婃斁璧勬簮
+//                if (httpClient != null) {
+//                    httpClient.close();
+//                }
+//                if (response != null) {
+//                    response.close();
+//                }
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
+//        }
 
     }
 
     public void doublePdfGenerate() throws IOException {
-        // 鏋勫缓璇锋眰URL鍜屾枃浠惰矾寰�
-        String url = "http://127.0.0.1:1224/api/doc/upload";
-        String path = "娴嬭瘯鏂囦欢.pdf";
-        String options_json = "{\"doc.extractionMode\": \"fullPage\"}";
+      //  String ocrUrl = "http://localhost:32009/umi/api/ocr";
+        File pdfFile = new File("34.pdf");
+        String base64 = java.util.Base64.getEncoder().encodeToString(Files.readAllBytes(pdfFile.toPath()));
+
+        JSONObject inputObject = new JSONObject();
+        inputObject.put("base64", base64);
+        //inputObject.put("options", new JSONObject().put("ocr.language", "models/config_chinese.txt"));
+
+        String response = HttpRequest.post(OCRServer+"/umi/api/ocr")
+                .body(inputObject.toString())
+                .contentType("application/json")
+                .execute()
+                .body();
+
+        System.out.println("璇嗗埆缁撴灉: " + response);
 
 // 鍒涘缓HttpClient瀹炰緥
 //        HttpClient client = HttpClient.newHttpClient();

--
Gitblit v1.9.1