Explorar el Código

htmlconvert指定utf8编码

wangliang hace 2 años
padre
commit
eff01f018e

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DownloadServiceImpl.java

@@ -38,6 +38,7 @@ import org.springframework.util.FileCopyUtils;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 
 @Service
@@ -173,7 +174,7 @@ public class DownloadServiceImpl implements DownloadService {
                         htmlFile.createNewFile();
                     }
                     // 生成html文件
-                    FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+                    FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
                     fileList.add(htmlFile);
                     // 转pdf文件
                     File pdfFile = new File(cardPdfPath);

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -60,6 +60,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -1056,7 +1057,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                         htmlFile.createNewFile();
                     }
                     // 生成html文件
-                    FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+                    FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
                     fileList.add(htmlFile);
                     // 转pdf文件
                     File pdfFile = new File(cardPdfPath);

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -51,6 +51,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import java.io.*;
 import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -337,7 +338,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             fileTempList.add(htmlFileTemp);
             fileTempList.add(pdfFileTemp);
 
-            FileCopyUtils.copy(htmlContent.getBytes(), htmlFileTemp);
+            FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFileTemp);
             boolean oss = dictionaryConfig.sysDomain().isOss();
             StringJoiner stringJoiner = new StringJoiner("");
             StringJoiner pdfStringJoiner = new StringJoiner("");
@@ -387,7 +388,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
                     UploadFileEnum.HTML, UploadFileEnum.PDF
             });
-            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), fileName, SystemConstant.HTML_PREFIX, new BigDecimal(htmlContent.getBytes().length), htmlFileMd5, userId);
+            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), fileName, SystemConstant.HTML_PREFIX, new BigDecimal(htmlContent.getBytes(StandardCharsets.UTF_8).length), htmlFileMd5, userId);
             basicAttachment.setPages(pdfDto.getActualPageCount());
             basicAttachmentService.save(basicAttachment);
         } catch (Exception e) {
@@ -416,7 +417,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
         BasicAttachment basicAttachment = null;
         File htmlFile = null, pdfFile = null;
         try {
-            byte[] bytes = htmlContent.getBytes();
+            byte[] bytes = htmlContent.getBytes(StandardCharsets.UTF_8);
             int size = bytes.length;
             boolean oss = dictionaryConfig.sysDomain().isOss();
             StringJoiner stringJoiner = new StringJoiner("");
@@ -443,7 +444,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             htmlFile = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
             pdfFile = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
 
-            FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+            FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
 
             String htmlFileMd5 = DigestUtils.md5Hex(new FileInputStream(htmlFile));
             String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -58,6 +58,7 @@ import org.springframework.util.LinkedMultiValueMap;
 import javax.annotation.Resource;
 import java.io.*;
 import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -1206,7 +1207,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         }
                         ExamCardDetail examCardDetail = examCardDetailService.getByCardId(cardId);
                         String htmlContent = examCardDetail.getHtmlContent();
-                        byte[] bytes = htmlContent.getBytes();
+                        byte[] bytes = htmlContent.getBytes(StandardCharsets.UTF_8);
 
                         // 题卡路径
                         String cardPath = firstPath + File.separator + "题卡" + File.separator + examCard.getTitle();
@@ -1319,7 +1320,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             localFile.createNewFile();
                         }
                         // 生成html文件
-                        FileCopyUtils.copy(htmlContent.getBytes(), localFile);
+                        FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), localFile);
                         sourceFileList.add(localFile);
                         // 转pdf文件
                         File file = new File(cardPdfPath);
@@ -1978,7 +1979,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                     htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
                                 }
 
-                                byte[] bytes = htmlContent.getBytes();
+                                byte[] bytes = htmlContent.getBytes(StandardCharsets.UTF_8);
                                 String cardName = "题卡-";
                                 if (namedByCourseInfo) {
                                     cardName = cardName + course;
@@ -2046,7 +2047,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                     htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
                                 }
 
-                                byte[] bytes = htmlContent.getBytes();
+                                byte[] bytes = htmlContent.getBytes(StandardCharsets.UTF_8);
                                 String cardName = "题卡-";
                                 if (namedByCourseInfo) {
                                     cardName = cardName + course;

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/HtmlToJpgUtil.java

@@ -23,6 +23,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
@@ -68,7 +69,7 @@ public class HtmlToJpgUtil {
         try {
             File htmlFile = new File(htmlPath);
             // 生成html文件
-            FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+            FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
             // 转pdf文件
             File pdfFile = new File(pdfPath);
             HtmlToPdfUtil.convert(htmlPath, pdfPath, pageSizeEnum);