소스 검색

语音转录

hejinbo 2 년 전
부모
커밋
07d80398ae

+ 22
- 20
ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java 파일 보기

4
 import com.documents4j.api.IConverter;
4
 import com.documents4j.api.IConverter;
5
 import com.documents4j.job.LocalConverter;
5
 import com.documents4j.job.LocalConverter;
6
 import com.itextpdf.text.Document;
6
 import com.itextpdf.text.Document;
7
+import com.itextpdf.text.Font;
7
 import com.itextpdf.text.PageSize;
8
 import com.itextpdf.text.PageSize;
9
+import com.itextpdf.text.pdf.BaseFont;
8
 import com.itextpdf.text.pdf.PdfWriter;
10
 import com.itextpdf.text.pdf.PdfWriter;
11
+import com.itextpdf.tool.xml.XMLWorkerFontProvider;
9
 import com.itextpdf.tool.xml.XMLWorkerHelper;
12
 import com.itextpdf.tool.xml.XMLWorkerHelper;
13
+import com.ruoyi.common.config.RuoYiConfig;
14
+import com.tencentcloudapi.teo.v20220901.models.CC;
15
+import lombok.extern.slf4j.Slf4j;
10
 
16
 
11
 import java.io.*;
17
 import java.io.*;
12
 import java.nio.charset.Charset;
18
 import java.nio.charset.Charset;
13
 import java.nio.file.Files;
19
 import java.nio.file.Files;
14
 
20
 
21
+import static cn.hutool.core.util.ClassLoaderUtil.getClassLoader;
22
+
15
 /**
23
 /**
16
  * @author wangqiong
24
  * @author wangqiong
17
  * @description pdf转换工具类
25
  * @description pdf转换工具类
18
  * @date 2023-11-28 15:20
26
  * @date 2023-11-28 15:20
19
  */
27
  */
28
+@Slf4j
20
 public class PdfUtils {
29
 public class PdfUtils {
21
-    /**
30
+        /**
22
      * 将html字符串转为pdf
31
      * 将html字符串转为pdf
23
      * @param pdfFilePath 保存的路径
32
      * @param pdfFilePath 保存的路径
24
      * @param htmlcontent:必须是完整的html格式,比如<html><body>123</body></html>
33
      * @param htmlcontent:必须是完整的html格式,比如<html><body>123</body></html>
25
      */
34
      */
26
-    public static boolean htmlStringConvertToPDF(String pdfFilePath, String htmlcontent) {
35
+    public  boolean htmlStringConvertToPDF(String pdfFilePath, String htmlcontent) {
27
         Document document = new Document();
36
         Document document = new Document();
28
         PdfWriter writer = null;
37
         PdfWriter writer = null;
29
         try {
38
         try {
30
-            if(!new File(pdfFilePath).exists()){
31
-                new File(pdfFilePath).createNewFile();
32
-            }
39
+//            if(!new File(pdfFilePath).exists()){
40
+//                new File(pdfFilePath).createNewFile();
41
+//            }
33
             writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
42
             writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
34
             // 设置底部距离60,解决重叠问题
43
             // 设置底部距离60,解决重叠问题
44
+
35
             document.setPageSize(PageSize.A4);
45
             document.setPageSize(PageSize.A4);
36
             document.setMargins(50, 45, 50, 60);
46
             document.setMargins(50, 45, 50, 60);
37
             document.setMarginMirroring(false);
47
             document.setMarginMirroring(false);
38
             document.open();
48
             document.open();
39
-            XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("UTF-8")), null, Charset.forName("UTF-8"));
49
+            // 解决PDF中文不显示
50
+            String fontPath = "/D:/simsun.ttf"; //字体文件路径
51
+            XMLWorkerFontProvider provider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
52
+            provider.register(fontPath);//注册字体
53
+            log.error("注册字体");
54
+            XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("UTF-8")),  Charset.forName("UTF-8"), provider);
40
         } catch (Exception e) {
55
         } catch (Exception e) {
56
+            log.error("htmlStringConvertToPDF error", e.getMessage());
41
            return false;
57
            return false;
42
         } finally {
58
         } finally {
43
             if (null != document) {
59
             if (null != document) {
131
         return true;
147
         return true;
132
     }
148
     }
133
 
149
 
134
-    public static void main(String      [] args) {
135
-        try {
136
-
137
-            String pdfFile = "D:\\test13.pdf";
138
-            String htmlContent1 = "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2>";
139
-            String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋体\">" + "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
140
-            String htmlContent2 = "<html><body style=\\\"font-size:12.0pt; font-family:宋体\\\"><h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
141
-
142
-            htmlStringConvertToPDF(pdfFile,htmlContent2);
143
-//            parseHtml2PdfByFilePath(pdfFile,htmlFile);
144
-        } catch (Exception e) {
145
-            e.printStackTrace();
146
-        }
147
-    }
148
 }
150
 }

+ 3
- 2
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/VideoServiceImpl.java 파일 보기

329
         } catch (IOException e) {
329
         } catch (IOException e) {
330
             throw new RuntimeException(e);
330
             throw new RuntimeException(e);
331
         }
331
         }
332
-        String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋体\">" +reservedConferenceVO.getHtmlContent()+"</body></html>";
332
+        String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:SimSun;\">" +reservedConferenceVO.getHtmlContent()+"</body></html>";
333
         // html转pdf并上传到服务器
333
         // html转pdf并上传到服务器
334
-        boolean convertFlag = PdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent);
334
+        PdfUtils pdfUtils = new PdfUtils();
335
+        boolean convertFlag = pdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent);
335
 
336
 
336
         // 绑定案件
337
         // 绑定案件
337
         if(convertFlag){
338
         if(convertFlag){