wangliang 4 years ago
parent
commit
aaeae4eb65

+ 0 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -131,10 +131,6 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 String destUrl = SystemConstant.PDF_TEMP_FILES_DIR + File.separator + pdfDirName;
                 HtmlToPdfUtil.convert(localHtmlFile.getPath(), destUrl, PageSizeEnum.A3);
                 File pdfFile = new File(destUrl);
-                if (!pdfFile.getParentFile().exists()) {
-                    pdfFile.getParentFile().mkdirs();
-                    pdfFile.createNewFile();
-                }
                 int pageCount = PdfUtil.addPdfPage(pdfFile);
                 localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pageCount));
                 fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
@@ -241,10 +237,6 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             String destUrl = SystemConstant.PDF_TEMP_FILES_DIR + File.separator + pdfDirName;
             HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
             File pdfFile = new File(destUrl);
-            if (!pdfFile.getParentFile().exists()) {
-                pdfFile.getParentFile().mkdirs();
-                pdfFile.createNewFile();
-            }
             String fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
             int pageCount = 0;
             if (oss) {//上传至oss

+ 8 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/HtmlToPdfUtil.java

@@ -7,6 +7,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.io.IOException;
 
 /**
  * @Description: htmltopdf
@@ -26,12 +27,11 @@ public class HtmlToPdfUtil {
      * @param pageSizeEnum
      * @return
      */
-    public static boolean convert(String srcPath, String destPath, PageSizeEnum pageSizeEnum) {
+    public static boolean convert(String srcPath, String destPath, PageSizeEnum pageSizeEnum) throws IOException {
         File file = new File(destPath);
-        File parent = file.getParentFile();
-        // 如果pdf保存路径不存在,则创建路径
-        if (!parent.exists()) {
-            parent.mkdirs();
+        if (!file.getParentFile().exists()) {
+            file.getParentFile().mkdirs();
+            file.createNewFile();
         }
         StringBuilder cmd = new StringBuilder();
 //        if (System.getProperty("os.name").indexOf("Windows") == -1) {
@@ -43,10 +43,11 @@ public class HtmlToPdfUtil {
         cmd.append(" ");
         cmd.append(" --page-size ").append(pageSizeEnum.name()).append(" ");
         cmd.append(" --disable-smart-shrinking ");
-        cmd.append(" --orientation Landscape ");
+        if (pageSizeEnum == PageSizeEnum.A3) {
+            cmd.append(" --orientation Landscape ");
+        }
 //        cmd.append(" --page-width 1200px ");
 //        cmd.append(" --page-width 1200px ");
-//        cmd.append(" --dpi 1191*842 ");
         cmd.append("  --margin-top 0 ");
         cmd.append("  --margin-bottom 0 ");
         cmd.append("  --margin-left 0 ");

+ 0 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/SysController.java

@@ -255,7 +255,6 @@ public class SysController {
     @ApiResponses({@ApiResponse(code = 200, message = "学校信息", response = EditResult.class)})
     @Aac(auth = BOOL.FALSE)
     public Result queryBySchoolCode(@ApiParam(value = "机构code", required = true) @RequestParam String code) {
-//        HtmlToPdfUtil.convert("/Users/king/Downloads/测试附件/3120ee49668e4bf48fd8c161a2abb73b的副本.html", "/Users/king/Downloads/测试附件/new_test1.pdf", PageSizeEnum.A3);
         if (!Objects.equals(code.toUpperCase(), RoleTypeEnum.ADMIN.name())) {
             BasicSchool basicSchool = cacheService.schoolCache(code);
             if (Objects.isNull(basicSchool)) {

+ 1 - 1
distributed-print/src/main/resources/application.properties

@@ -12,7 +12,7 @@ spring.application.name=distributed-print
 #\u6570\u636E\u6E90\u914D\u7F6E
 db.host=localhost
 db.port=3306
-db.name=distributed_print
+db.name=distributed_print_test
 db.username=root
 db.password=123456789