diff --git a/server/src/main/config/application.properties b/server/src/main/config/application.properties index fd79f6d5..6aa403df 100644 --- a/server/src/main/config/application.properties +++ b/server/src/main/config/application.properties @@ -65,8 +65,16 @@ office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image} #是否关闭office预览切换开关,默认为false,可配置为true关闭 office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false} +#是否禁止演示模式 +pdf.presentationMode.disable = ${KK_PDF_PRESENTATION_MODE_DISABLE:true} +#是否禁止打开文件 +pdf.openFile.disable = ${KK_PDF_OPEN_FILE_DISABLE:true} +#是否禁止打印转换生成的pdf文件 +pdf.print.disable = ${KK_PDF_PRINT_DISABLE:true} #是否禁止下载转换生成的pdf文件 pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true} +#是否禁止bookmark +pdf.bookmark.disable = ${KK_PDF_BOOKMARK_DISABLE:true} #是否禁用首页文件上传 file.upload.disable = ${KK_FILE_UPLOAD_ENABLED:false} diff --git a/server/src/main/java/cn/keking/config/ConfigConstants.java b/server/src/main/java/cn/keking/config/ConfigConstants.java index 3ebd818a..40d2964a 100644 --- a/server/src/main/java/cn/keking/config/ConfigConstants.java +++ b/server/src/main/java/cn/keking/config/ConfigConstants.java @@ -34,7 +34,11 @@ public class ConfigConstants { private static String baseUrl; private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator; private static CopyOnWriteArraySet trustHostSet; + private static String pdfPresentationModeDisable; + private static String pdfOpenFileDisable; + private static String pdfPrintDisable; private static String pdfDownloadDisable; + private static String pdfBookmarkDisable; private static Boolean fileUploadDisable; public static final String DEFAULT_CACHE_ENABLED = "true"; @@ -48,7 +52,11 @@ 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_PRESENTATION_MODE_DISABLE = "true"; + public static final String DEFAULT_PDF_OPEN_FILE_DISABLE = "true"; + public static final String DEFAULT_PDF_PRINT_DISABLE = "true"; public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true"; + public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true"; public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false"; @@ -228,11 +236,46 @@ public class ConfigConstants { ConfigConstants.trustHostSet = trustHostSet; } + public static String getPdfPresentationModeDisable() { + return pdfPresentationModeDisable; + } + + @Value("${pdf.presentationMode.disable:true}") + public void setPdfPresentationModeDisable(String pdfPresentationModeDisable) { + setPdfPresentationModeDisableValue(pdfPresentationModeDisable); + } + + public static void setPdfPresentationModeDisableValue(String pdfPresentationModeDisable) { + ConfigConstants.pdfPresentationModeDisable = pdfPresentationModeDisable; + } + + public static String getPdfOpenFileDisable() { + return pdfOpenFileDisable; + } + + @Value("${pdf.openFile.disable:true}") + public static void setPdfOpenFileDisable(String pdfOpenFileDisable) { + setPdfOpenFileDisableValue(pdfOpenFileDisable); + } + public static void setPdfOpenFileDisableValue(String pdfOpenFileDisable) { + ConfigConstants.pdfOpenFileDisable = pdfOpenFileDisable; + } + + public static String getPdfPrintDisable() { + return pdfPrintDisable; + } + @Value("${pdf.print.disable:true}") + public void setPdfPrintDisable(String pdfPrintDisable) { + setPdfPrintDisableValue(pdfPrintDisable); + } + public static void setPdfPrintDisableValue(String pdfPrintDisable) { + ConfigConstants.pdfPrintDisable = pdfPrintDisable; + } + public static String getPdfDownloadDisable() { return pdfDownloadDisable; } - @Value("${pdf.download.disable:true}") public void setPdfDownloadDisable(String pdfDownloadDisable) { setPdfDownloadDisableValue(pdfDownloadDisable); @@ -241,6 +284,17 @@ public class ConfigConstants { ConfigConstants.pdfDownloadDisable = pdfDownloadDisable; } + public static String getPdfBookmarkDisable() { + return pdfBookmarkDisable; + } + @Value("${pdf.bookmark.disable:true}") + public void setPdfBookmarkDisable(String pdfBookmarkDisable) { + setPdfBookmarkDisableValue(pdfBookmarkDisable); + } + public static void setPdfBookmarkDisableValue(String pdfBookmarkDisable) { + ConfigConstants.pdfBookmarkDisable = pdfBookmarkDisable; + } + public static String getOfficePreviewSwitchDisabled() { return officePreviewSwitchDisabled; } diff --git a/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java b/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java index 7e53a052..6fb78349 100644 --- a/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java +++ b/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java @@ -47,7 +47,11 @@ public class ConfigRefreshComponent { String configFilePath = ConfigUtils.getCustomizedConfigPath(); String baseUrl; String trustHost; + String pdfPresentationModeDisable; + String pdfOpenFileDisable; + String pdfPrintDisable; String pdfDownloadDisable; + String pdfBookmarkDisable; boolean fileUploadDisable; while (true) { FileReader fileReader = new FileReader(configFilePath); @@ -66,7 +70,11 @@ public class ConfigRefreshComponent { mediaArray = media.split(","); baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL); trustHost = properties.getProperty("trust.host", ConfigConstants.DEFAULT_TRUST_HOST); + pdfPresentationModeDisable = properties.getProperty("pdf.presentationMode.disable", ConfigConstants.DEFAULT_PDF_PRESENTATION_MODE_DISABLE); + pdfOpenFileDisable = properties.getProperty("pdf.openFile.disable", ConfigConstants.DEFAULT_PDF_OPEN_FILE_DISABLE); + pdfPrintDisable = properties.getProperty("pdf.print.disable", ConfigConstants.DEFAULT_PDF_PRINT_DISABLE); pdfDownloadDisable = properties.getProperty("pdf.download.disable", ConfigConstants.DEFAULT_PDF_DOWNLOAD_DISABLE); + pdfBookmarkDisable = properties.getProperty("pdf.bookmark.disable", ConfigConstants.DEFAULT_PDF_BOOKMARK_DISABLE); fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE)); ConfigConstants.setCacheEnabledValueValue(cacheEnabled); ConfigConstants.setSimTextValue(textArray); @@ -78,7 +86,11 @@ public class ConfigRefreshComponent { ConfigConstants.setBaseUrlValue(baseUrl); ConfigConstants.setTrustHostValue(trustHost); ConfigConstants.setOfficePreviewSwitchDisabledValue(officePreviewSwitchDisabled); + ConfigConstants.setPdfPresentationModeDisableValue(pdfPresentationModeDisable); + ConfigConstants.setPdfOpenFileDisableValue(pdfOpenFileDisable); + ConfigConstants.setPdfPrintDisableValue(pdfPrintDisable); ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable); + ConfigConstants.setPdfBookmarkDisableValue(pdfBookmarkDisable); ConfigConstants.setFileUploadDisableValue(fileUploadDisable); setWatermarkConfig(properties); bufferedReader.close(); diff --git a/server/src/main/java/cn/keking/web/filter/AttributeSetFilter.java b/server/src/main/java/cn/keking/web/filter/AttributeSetFilter.java index 0411fba2..5c5667bd 100644 --- a/server/src/main/java/cn/keking/web/filter/AttributeSetFilter.java +++ b/server/src/main/java/cn/keking/web/filter/AttributeSetFilter.java @@ -30,8 +30,12 @@ public class AttributeSetFilter implements Filter { * @param request request */ private void setFileAttribute(ServletRequest request){ - HttpServletRequest httpRequest = (HttpServletRequest)request; + HttpServletRequest httpRequest = (HttpServletRequest) request; + request.setAttribute("pdfPresentationModeDisable", ConfigConstants.getPdfPresentationModeDisable()); + request.setAttribute("pdfOpenFileDisable", ConfigConstants.getPdfOpenFileDisable()); + request.setAttribute("pdfPrintDisable", ConfigConstants.getPdfPrintDisable()); request.setAttribute("pdfDownloadDisable", ConfigConstants.getPdfDownloadDisable()); + request.setAttribute("pdfBookmarkDisable", ConfigConstants.getPdfBookmarkDisable()); request.setAttribute("fileKey", httpRequest.getParameter("fileKey")); request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable()); diff --git a/server/src/main/resources/static/pdfjs/web/viewer.js b/server/src/main/resources/static/pdfjs/web/viewer.js index 1fef2f58..20def755 100644 --- a/server/src/main/resources/static/pdfjs/web/viewer.js +++ b/server/src/main/resources/static/pdfjs/web/viewer.js @@ -2089,11 +2089,19 @@ function loadAndEnablePDFBug(enabledTabs) { function webViewerInitialized() { var appConfig = PDFViewerApplication.appConfig; var file; + var disablePresentationMode; + var disableOpenFile; + var disablePrint; var disableDownload; + var disableBookmark; var queryString = document.location.search.substring(1); var params = (0, _ui_utils.parseQueryString)(queryString); file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl"); + disablePresentationMode = 'disablepresentationmode' in params ? params.disablepresentationmode : 'false'; + disableOpenFile = 'disableopenfile' in params ? params.disableopenfile : 'false'; + disablePrint = 'disableprint' in params ? params.disableprint : 'false'; disableDownload = 'disabledownload' in params ? params.disabledownload : 'false'; + disableBookmark = 'disablebookmark' in params ? params.disablebookmark : 'false'; validateFileURL(file); var fileInput = document.createElement("input"); fileInput.id = appConfig.openFileInputName; @@ -2176,8 +2184,30 @@ function webViewerInitialized() { PDFViewerApplication.error(msg, reason); }); } + + if ('true' === disablePresentationMode) { + document.getElementById("presentationMode").style.display='none'; + document.getElementById("secondaryPresentationMode").style.display='none'; + } + + if ('true' === disableOpenFile) { + document.getElementById("openFile").style.display='none'; + document.getElementById("secondaryOpenFile").style.display='none'; + } + + if ('true' === disablePrint) { + document.getElementById("print").style.display='none'; + document.getElementById("secondaryPrint").style.display='none'; + } + if ('true' === disableDownload) { document.getElementById("download").style.display='none'; + document.getElementById("secondaryDownload").style.display='none'; + } + + if ('true' === disableBookmark) { + document.getElementById("viewBookmark").style.display='none'; + document.getElementById("secondaryViewBookmark").style.display='none'; } } diff --git a/server/src/main/resources/web/pdf.ftl b/server/src/main/resources/web/pdf.ftl index fa0167e7..e39667f2 100644 --- a/server/src/main/resources/web/pdf.ftl +++ b/server/src/main/resources/web/pdf.ftl @@ -26,7 +26,7 @@ if (!url.startsWith(baseUrl)) { url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(url); } - document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disabledownload=${pdfDownloadDisable}"; + document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}"; document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10; /** * 页面变化调整高度