diff --git a/jodconverter-web/src/main/config/application.properties b/jodconverter-web/src/main/config/application.properties index 42907c9c..9d563ac8 100644 --- a/jodconverter-web/src/main/config/application.properties +++ b/jodconverter-web/src/main/config/application.properties @@ -53,6 +53,9 @@ simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log media = ${KK_MEDIA:mp3,wav,mp4,flv} #office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换) office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image} +#是否关闭office预览切换开关,默认为false,可配置为true关闭 +office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false} + #是否禁止下载转换生成的pdf文件 pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true} diff --git a/jodconverter-web/src/main/config/freemarker_implicit.ftl b/jodconverter-web/src/main/config/freemarker_implicit.ftl index 690c2a12..ba502ddd 100644 --- a/jodconverter-web/src/main/config/freemarker_implicit.ftl +++ b/jodconverter-web/src/main/config/freemarker_implicit.ftl @@ -1,5 +1,6 @@ [#ftl] [#-- @implicitly included --] +[#-- @ftlvariable name="switchDisabled" type="String" --] [#-- @ftlvariable name="imgurls" type="String" --] [#-- @ftlvariable name="watermarkAngle" type="String" --] [#-- @ftlvariable name="watermarkHeight" type="String" --] diff --git a/jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java b/jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java index 3c124c2b..351b2035 100644 --- a/jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java +++ b/jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java @@ -20,6 +20,7 @@ public class ConfigConstants { private static String[] SIM_TEXT = {}; private static String[] MEDIA = {}; private static String OFFICE_PREVIEW_TYPE; + private static String OFFICE_PREVIEW_SWITCH_DISABLED; private static String FTP_USERNAME; private static String FTP_PASSWORD; private static String FTP_CONTROL_ENCODING; @@ -32,6 +33,7 @@ public class ConfigConstants { 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"; public static final String DEFAULT_MEDIA_TYPE = "mp3,wav,mp4,flv"; public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image"; + public static final String DEFAULT_OFFICE_PREVIEW_SWITCH_DISABLED = "false"; public static final String DEFAULT_FTP_USERNAME = null; public static final String DEFAULT_FTP_PASSWORD = null; public static final String DEFAULT_FTP_CONTROL_ENCODING = "UTF-8"; @@ -202,4 +204,12 @@ public class ConfigConstants { PDF_DOWNLOAD_DISABLE = pdfDownloadDisable; } + public static String getOfficePreviewSwitchDisabled() { + return OFFICE_PREVIEW_SWITCH_DISABLED; + } + + @Value("${office.preview.switch.disabled:true}") + public static void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) { + OFFICE_PREVIEW_SWITCH_DISABLED = officePreviewSwitchDisabled; + } } diff --git a/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java b/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java index 5582c00f..7bd74b35 100644 --- a/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java +++ b/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java @@ -38,6 +38,7 @@ public class ConfigRefreshComponent { String[] textArray; String[] mediaArray; String officePreviewType; + String officePreviewSwitchDisabled; String ftpUsername; String ftpPassword; String ftpControlEncoding; @@ -54,6 +55,7 @@ public class ConfigRefreshComponent { text = properties.getProperty("simText", ConfigConstants.DEFAULT_TXT_TYPE); media = properties.getProperty("media", ConfigConstants.DEFAULT_MEDIA_TYPE); officePreviewType = properties.getProperty("office.preview.type", ConfigConstants.DEFAULT_OFFICE_PREVIEW_TYPE); + officePreviewSwitchDisabled = properties.getProperty("office.preview.switch.disabled", ConfigConstants.DEFAULT_OFFICE_PREVIEW_TYPE); ftpUsername = properties.getProperty("ftp.username", ConfigConstants.DEFAULT_FTP_USERNAME); ftpPassword = properties.getProperty("ftp.password", ConfigConstants.DEFAULT_FTP_PASSWORD); ftpControlEncoding = properties.getProperty("ftp.control.encoding", ConfigConstants.DEFAULT_FTP_CONTROL_ENCODING); @@ -71,6 +73,7 @@ public class ConfigRefreshComponent { ConfigConstants.setFtpControlEncodingValue(ftpControlEncoding); ConfigConstants.setBaseUrlValue(baseUrl); ConfigConstants.setTrustHostValue(trustHost); + ConfigConstants.setOfficePreviewSwitchDisabled(officePreviewSwitchDisabled); ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable); setWatermarkConfig(properties); bufferedReader.close(); diff --git a/jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java b/jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java index 00511783..5a38baad 100644 --- a/jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java +++ b/jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java @@ -54,6 +54,7 @@ public class OfficeFilePreviewImpl implements FilePreview { boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx"); String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf"); String outFilePath = FILE_DIR + pdfName; + model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); // 判断之前是否已转换过,如果转换过,直接返回,否则执行转换 if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { String filePath; diff --git a/jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java b/jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java index 830b8024..18829e0a 100644 --- a/jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java +++ b/jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java @@ -44,6 +44,7 @@ public class PdfFilePreviewImpl implements FilePreview { String baseUrl = BaseUrlFilter.getBaseUrl(); String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf"; String outFilePath = FILE_DIR + pdfName; + model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_ALL_IMAGES.equals(officePreviewType)) { //当文件不存在时,就去下载 if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { diff --git a/jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java b/jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java index 01145891..229863a4 100644 --- a/jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java +++ b/jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java @@ -1,5 +1,6 @@ package cn.keking.service.impl; +import cn.keking.config.ConfigConstants; import cn.keking.model.FileAttribute; import cn.keking.model.ReturnResponse; import cn.keking.service.FilePreview; @@ -33,6 +34,7 @@ public class PictureFilePreviewImpl implements FilePreview { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { String fileKey = (String) RequestContextHolder.currentRequestAttributes().getAttribute("fileKey",0); List imgUrls = Lists.newArrayList(url); + model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); try { imgUrls.clear(); imgUrls.addAll(fileUtils.getImgCache(fileKey)); diff --git a/jodconverter-web/src/main/resources/web/officePicture.ftl b/jodconverter-web/src/main/resources/web/officePicture.ftl index 8f71774e..abc1202e 100644 --- a/jodconverter-web/src/main/resources/web/officePicture.ftl +++ b/jodconverter-web/src/main/resources/web/officePicture.ftl @@ -34,7 +34,9 @@ -使用PDF预览 +<#if "false" == switchDisabled> + 使用PDF预览 +