Ver código fonte

office 功能调整 支持批注 转换页码限制 生成水印等等

gaoxiongzaq 1 ano atrás
pai
commit
b5e711bf87

+ 19 - 3
server/src/main/config/application.properties

@@ -131,14 +131,30 @@ beian = ${KK_BEIAN:default}
 #禁止上传类型
 prohibit = ${KK_PROHIBIT:exe,dll,dat}
 #启用验证码删除文件 默认关闭
-delete.captcha= ${KK_DELETE_CAPTCHA:false}
+delete.captcha= ${KK_DELETE_CAPTCHA:true}
 #删除密码
 delete.password = ${KK_DELETE_PASSWORD:123456}
 #删除 转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间
-delete.source.file = ${KK_DELETE_SOURCE_FILE:true}
+delete.source.file = ${KK_DELETE_SOURCE_FILE:false}
 #配置PDF文件生成图片的像素大小,dpi 越高,图片质量越清晰,同时也会消耗更多的计算资源。
 pdf2jpg.dpi = ${KK_PDF2JPG_DPI:144}
 #xlsx格式前端解析
 office.type.web = ${KK_OFFICE_TYPE_WEB:web}
 #Cad类型图片浏览模式:tif(利用前端js插件浏览);svg(转换为svg显示);pdf(转换为pdf后显示,便于打印)
-cad.preview.type = ${KK_CAD_PREVIEW_TYPE:pdf}
+cad.preview.type = ${KK_CAD_PREVIEW_TYPE:svg}
+
+#OFFICE转换模块设置
+#生成限制 默认不限制 使用方法 (1-5)
+office.pagerange = ${KK_office_PageRange:false}
+#生成水印 默认不启用 使用方法 (kkFileView)
+office.watermark  = ${KK_office_Watermark:false}
+#OFFICE JPEG图片压缩
+office.quality = ${KK_office_Quality:80}
+#图像分辨率限制
+office.maximageresolution = ${KK_office_MaxImageResolution:150}
+#导出书签
+office.exportbookmarks = ${KK_office_ExportBookmarks:true}
+#批注作为PDF的注释
+office.exportnotes = ${KK_office_ExportNotes:true}
+#加密文档 生成的PDF文档 添加密码(密码为加密文档的密码)
+office.documentopenpasswords = ${KK_office_DocumentOpenPassword:true}

+ 98 - 0
server/src/main/java/cn/keking/config/ConfigConstants.java

@@ -51,6 +51,13 @@ public class ConfigConstants {
     private static String cadPreviewType;
     private static Boolean deleteSourceFile;
     private static Boolean deleteCaptcha;
+    private static String officePageRange;
+    private static String officeWatermark;
+    private static String officeQuality;
+    private static String officeMaxImageResolution;
+    private static Boolean officeExportBookmarks;
+    private static Boolean officeExportNotes;
+    private static Boolean officeDocumentOpenPasswords;
 
     public static final String DEFAULT_CACHE_ENABLED = "true";
     public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@@ -81,6 +88,15 @@ public class ConfigConstants {
     public static final String DEFAULT_DELETE_SOURCE_FILE = "true";
     public static final String DEFAULT_DELETE_CAPTCHA = "false";
 
+
+    public static final String DEFAULT_OFFICE_PAQERANQE = "false";
+    public static final String DEFAULT_OFFICE_WATERMARK = "false";
+    public static final String DEFAULT_OFFICE_QUALITY = "80";
+    public static final String DEFAULT_OFFICE_MAXIMAQERESOLUTION = "150";
+    public static final String DEFAULT_OFFICE_EXPORTBOOKMARKS = "true";
+    public static final String DEFAULT_OFFICE_EXPORTNOTES = "true";
+    public static final String DEFAULT_EOCUMENTOPENPASSWORDS = "true";
+
     public static Boolean isCacheEnabled() {
         return cacheEnabled;
     }
@@ -478,4 +494,86 @@ public class ConfigConstants {
     public static void setDeleteCaptchaValue(Boolean deleteCaptcha) {
         ConfigConstants.deleteCaptcha = deleteCaptcha;
     }
+
+    /**
+     * 以下为OFFICE转换模块设置
+     */
+
+    public static String getofficePageRange() {
+        return officePageRange;
+    }
+    @Value("${office.pagerange:false}")
+    public void setOfficePageRange(String officepagerange) {
+        setOfficePageRangeValue(officepagerange);
+    }
+    public static void setOfficePageRangeValue(String officepagerange) {
+        ConfigConstants.officePageRange = officepagerange;
+    }
+
+    public static String getofficeWatermark() {
+        return officeWatermark;
+    }
+    @Value("${office.watermark:false}")
+    public void setOfficeWatermark(String officewatermark) {
+        setOfficeWatermarkValue(officewatermark);
+    }
+    public static void setOfficeWatermarkValue(String officewatermark) {
+        ConfigConstants.officeWatermark = officewatermark;
+    }
+
+    public static String getofficeQuality() {
+        return officeQuality;
+    }
+    @Value("${office.Quality:80}")
+    public void setOfficeQuality(String officequality) {
+        setOfficeQualityValue(officequality);
+    }
+    public static void setOfficeQualityValue(String officequality) {
+        ConfigConstants.officeQuality = officequality;
+    }
+
+    public static String getofficeMaxImageResolution() {
+        return officeMaxImageResolution;
+    }
+    @Value("${office.maximageresolution:150}")
+    public void setofficeMaxImageResolution(String officemaximageresolution) {
+        setOfficeMaxImageResolutionValue(officemaximageresolution);
+    }
+    public static void setOfficeMaxImageResolutionValue(String officemaximageresolution) {
+        ConfigConstants.officeMaxImageResolution = officemaximageresolution;
+    }
+
+    public static Boolean getofficeExportBookmarks() {
+        return officeExportBookmarks;
+    }
+    @Value("${office.exportbookmarks:true}")
+    public void setofficeExportBookmarks(Boolean officeexportbookmarks) {
+        setOfficeExportBookmarksValue(officeexportbookmarks);
+    }
+    public static void setOfficeExportBookmarksValue(Boolean officeexportbookmarks) {
+        ConfigConstants.officeExportBookmarks = officeexportbookmarks;
+    }
+
+    public static Boolean getofficeExportNotes() {
+        return officeExportNotes;
+    }
+    @Value("${office.exportnotes:true}")
+    public void setExportNotes(Boolean officeofficeexportnotes) {
+        setOfficeExportNotesValue(officeofficeexportnotes);
+    }
+    public static void setOfficeExportNotesValue(Boolean officeofficeexportnotes) {
+        ConfigConstants.officeExportNotes = officeofficeexportnotes;
+    }
+
+    public static Boolean getofficeDocumentOpenPasswords() {
+        return officeDocumentOpenPasswords;
+    }
+    @Value("${office.documentopenpasswords:true}")
+    public void setDocumentOpenPasswords(Boolean officedocumentopenpasswords) {
+        setOfficeDocumentOpenPasswordsValue(officedocumentopenpasswords);
+    }
+    public static void setOfficeDocumentOpenPasswordsValue(Boolean officedocumentopenpasswords) {
+        ConfigConstants.officeDocumentOpenPasswords = officedocumentopenpasswords;
+    }
+
 }

+ 21 - 0
server/src/main/java/cn/keking/config/ConfigRefreshComponent.java

@@ -63,6 +63,13 @@ public class ConfigRefreshComponent {
                 String cadPreviewType;
                 boolean deleteSourceFile;
                 boolean deleteCaptcha;
+                String officPageRange;
+                String officWatermark;
+                String officQuality;
+                String officMaxImageResolution;
+                boolean officExportBookmarks;
+                boolean officeExportNotes;
+                boolean officeDocumentOpenPasswords;
                 while (true) {
                     FileReader fileReader = new FileReader(configFilePath);
                     BufferedReader bufferedReader = new BufferedReader(fileReader);
@@ -96,6 +103,13 @@ public class ConfigRefreshComponent {
                     officeTypeWeb = properties.getProperty("office.type.web", ConfigConstants.DEFAULT_OFFICE_TYPE_WEB);
                     deleteSourceFile =  Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_DELETE_SOURCE_FILE));
                     deleteCaptcha =  Boolean.parseBoolean(properties.getProperty("delete.captcha", ConfigConstants.DEFAULT_DELETE_CAPTCHA));
+                    officPageRange = properties.getProperty("office.pagerange", ConfigConstants.DEFAULT_OFFICE_PAQERANQE);
+                    officWatermark = properties.getProperty("office.watermark", ConfigConstants.DEFAULT_OFFICE_WATERMARK);
+                    officQuality = properties.getProperty("office.quality", ConfigConstants.DEFAULT_OFFICE_QUALITY);
+                    officMaxImageResolution = properties.getProperty("office.maximageresolution", ConfigConstants.DEFAULT_OFFICE_MAXIMAQERESOLUTION);
+                    officExportBookmarks = Boolean.parseBoolean(properties.getProperty("office.exportbookmarks", ConfigConstants.DEFAULT_OFFICE_EXPORTBOOKMARKS));
+                    officeExportNotes = Boolean.parseBoolean(properties.getProperty("office.exportnotes", ConfigConstants.DEFAULT_OFFICE_EXPORTNOTES));
+                    officeDocumentOpenPasswords =  Boolean.parseBoolean(properties.getProperty("office.documentopenpasswords", ConfigConstants.DEFAULT_EOCUMENTOPENPASSWORDS));
                     prohibitArray = prohibit.split(",");
 
                     ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
@@ -122,6 +136,13 @@ public class ConfigRefreshComponent {
                     ConfigConstants.setPasswordValue(password);
                     ConfigConstants.setPdf2JpgDpiValue(pdf2JpgDpi);
                     ConfigConstants.setOfficeTypeWebValue(officeTypeWeb);
+                    ConfigConstants.setOfficePageRangeValue(officPageRange);
+                    ConfigConstants.setOfficeWatermarkValue(officWatermark);
+                    ConfigConstants.setOfficeQualityValue(officQuality);
+                    ConfigConstants.setOfficeMaxImageResolutionValue(officMaxImageResolution);
+                    ConfigConstants.setOfficeExportBookmarksValue(officExportBookmarks);
+                    ConfigConstants.setOfficeExportNotesValue(officeExportNotes);
+                    ConfigConstants.setOfficeDocumentOpenPasswordsValue(officeDocumentOpenPasswords);
                     ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
                     ConfigConstants.setDeleteCaptchaValue(deleteCaptcha);
                     setWatermarkConfig(properties);

+ 24 - 2
server/src/main/java/cn/keking/service/OfficeToPdfService.java

@@ -1,5 +1,6 @@
 package cn.keking.service;
 
+import cn.keking.config.ConfigConstants;
 import cn.keking.model.FileAttribute;
 import com.sun.star.document.UpdateDocMode;
 import org.apache.commons.lang3.StringUtils;
@@ -33,15 +34,36 @@ public class OfficeToPdfService {
             logger.error("创建目录【{}】失败,请检查目录权限!",outputFilePath_end);
         }
         LocalConverter.Builder builder;
+        Map<String, Object> filterData = new HashMap<>();
+        filterData.put("EncryptFile", true);
+        if(!ConfigConstants.getofficePageRange().equals("false")){
+            filterData.put("PageRange", ConfigConstants.getofficePageRange()); //限制页面
+        }
+        if(!ConfigConstants.getofficeWatermark().equals("false")){
+            filterData.put("Watermark", ConfigConstants.getofficeWatermark());  //水印
+        }
+        filterData.put("Quality", ConfigConstants.getofficeQuality()); //图片压缩
+        filterData.put("MaxImageResolution", ConfigConstants.getofficeMaxImageResolution()); //DPI
+        if(ConfigConstants.getofficeExportBookmarks()){
+            filterData.put("ExportBookmarks", true); //导出书签
+        }
+        if(ConfigConstants.getofficeExportNotes()){
+            filterData.put("ExportNotes", true); //批注作为PDF的注释
+        }
+        if(!ConfigConstants.getofficeDocumentOpenPasswords()){
+            filterData.put("DocumentOpenPassword", fileAttribute.getFilePassword()); //给PDF添加密码
+        }
+        Map<String, Object> customProperties = new HashMap<>();
+        customProperties.put("FilterData", filterData);
         if (StringUtils.isNotBlank(fileAttribute.getFilePassword())) {
             Map<String, Object> loadProperties = new HashMap<>();
             loadProperties.put("Hidden", true);
             loadProperties.put("ReadOnly", true);
             loadProperties.put("UpdateDocMode", UpdateDocMode.NO_UPDATE);
             loadProperties.put("Password", fileAttribute.getFilePassword());
-            builder = LocalConverter.builder().loadProperties(loadProperties);
+            builder = LocalConverter.builder().loadProperties(loadProperties).storeProperties(customProperties);
         } else {
-            builder = LocalConverter.builder();
+            builder = LocalConverter.builder().storeProperties(customProperties);
         }
         builder.build().convert(inputFile).to(outputFile).execute();
     }