Bladeren bron

新功能点:新增配置是否可以下载转换完成的pdf文件

陈精华 4 jaren geleden
bovenliggende
commit
a535ebfe1d

+ 3 - 0
jodconverter-web/src/main/config/application.properties

@@ -53,6 +53,8 @@ simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,,ja
 media = ${KK_MEDIA:mp3,wav,mp4,flv}
 #office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换)
 office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
+#是否禁止下载转换生成的pdf文件
+pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true}
 
 #预览源为FTP时 FTP用户名,可在ftp url后面加参数ftp.username=ftpuser指定,不指定默认用配置的
 ftp.username = ${KK_FTP_USERNAME:ftpuser}
@@ -82,3 +84,4 @@ watermark.width = ${WATERMARK_WIDTH:180}
 watermark.height = ${WATERMARK_HEIGHT:80}
 #水印倾斜度数,要求设置在大于等于0,小于90
 watermark.angle = ${WATERMARK_ANGLE:10}
+

+ 16 - 0
jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java

@@ -27,6 +27,7 @@ public class ConfigConstants {
     private static String BASE_URL;
     private static String FILE_DIR = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
     private static CopyOnWriteArraySet<String> TRUST_HOST_SET;
+    private static String PDF_DOWNLOAD_DISABLE;
 
     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,,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@@ -38,6 +39,7 @@ public class ConfigConstants {
     public static final String DEFAULT_BASE_URL = "default";
     public static final String DEFAULT_FILE_DIR_VALUE = "default";
     public static final String DEFAULT_TRUST_HOST = "default";
+    public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
 
     public static Boolean isCacheEnabled() {
         return CACHE_ENABLED;
@@ -141,4 +143,18 @@ public class ConfigConstants {
     private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
         ConfigConstants.TRUST_HOST_SET = trustHostSet;
     }
+
+
+    public static String getPdfDownloadDisable() {
+        return PDF_DOWNLOAD_DISABLE;
+    }
+
+    public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
+        PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
+    }
+
+    @Value("${pdf.download.disable:true}")
+    public void setPdfDownloadDisable(String pdfDownloadDisable) {
+        PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
+    }
 }

+ 3 - 0
jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java

@@ -44,6 +44,7 @@ public class ConfigRefreshComponent {
                 String configFilePath = OfficeUtils.getCustomizedConfigPath();
                 String baseUrl;
                 String trustHost;
+                String pdfDownloadDisable;
                 while (true) {
                     FileReader fileReader = new FileReader(configFilePath);
                     BufferedReader bufferedReader = new BufferedReader(fileReader);
@@ -60,6 +61,7 @@ public class ConfigRefreshComponent {
                     mediaArray = media.split(",");
                     baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL);
                     trustHost = properties.getProperty("trust.host", ConfigConstants.DEFAULT_TRUST_HOST);
+                    pdfDownloadDisable = properties.getProperty("pdf.download.disable", ConfigConstants.DEFAULT_PDF_DOWNLOAD_DISABLE);
                     ConfigConstants.setCacheEnabled(cacheEnabled);
                     ConfigConstants.setSimText(textArray);
                     ConfigConstants.setMedia(mediaArray);
@@ -69,6 +71,7 @@ public class ConfigRefreshComponent {
                     ConfigConstants.setFtpControlEncoding(ftpControlEncoding);
                     ConfigConstants.setBaseUrl(baseUrl);
                     ConfigConstants.setTrustHost(trustHost);
+                    ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
                     setWatermarkConfig(properties);
                     bufferedReader.close();
                     fileReader.close();

+ 2 - 0
jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java

@@ -1,5 +1,6 @@
 package cn.keking.web.controller;
 
+import cn.keking.config.ConfigConstants;
 import cn.keking.hutool.URLUtil;
 import cn.keking.model.FileAttribute;
 import cn.keking.service.FilePreview;
@@ -51,6 +52,7 @@ public class OnlinePreviewController {
     public String onlinePreview(String url, Model model, HttpServletRequest req) {
         FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
         req.setAttribute("fileKey", req.getParameter("fileKey"));
+        model.addAttribute("pdfDownloadDisable", ConfigConstants.getPdfDownloadDisable());
         model.addAttribute("officePreviewType", req.getParameter("officePreviewType"));
         FilePreview filePreview = previewFactory.get(fileAttribute);
         logger.info("预览文件url:{},previewType:{}", url, fileAttribute.getType());

+ 5 - 0
jodconverter-web/src/main/resources/static/pdfjs/web/viewer.js

@@ -1932,10 +1932,12 @@ function webViewerInitialized() {
   var appConfig = PDFViewerApplication.appConfig;
   var file = void 0;
   var base = void 0;
+  var disableDownload = void 0;
   var queryString = document.location.search.substring(1);
   var params = (0, _ui_utils.parseQueryString)(queryString);
   file = 'file' in params ? params.file : appConfig.defaultUrl;
   base = 'base' in params ? params.base : appConfig.defaultUrl;
+  disableDownload = 'disabledownload' in params ? params.disabledownload : 'false';
   file = validateFileURL(file,base);
   var waitForBeforeOpening = [];
   var fileInput = document.createElement('input');
@@ -2036,6 +2038,9 @@ function webViewerInitialized() {
       PDFViewerApplication.error(msg, reason);
     });
   });
+  if ('true' === disableDownload) {
+    document.getElementById("download").style.display='none';
+  }
 }
 var webViewerOpenFileViaURL = void 0;
 {

+ 1 - 2
jodconverter-web/src/main/resources/web/pdf.ftl

@@ -26,11 +26,10 @@
 
     <img src="images/jpg.svg" width="63" height="63" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
 
-
 </body>
 <script src="js/watermark.js" type="text/javascript"></script>
 <script type="text/javascript">
-    document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?base=${baseUrl}&file="+encodeURIComponent('${finalUrl}');
+    document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?base=${baseUrl}&file="+encodeURIComponent('${finalUrl}')+"&disabledownload=${pdfDownloadDisable}";
     document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight-10;
     /**
      * 页面变化调整高度