Merge pull request #317 from zzzhouuu/master

feat: 通过配置控制PDF.js viewer toolbar & secondaryToolbar功能按钮
pull/35/head
gitchenjh 2021-12-10 17:31:25 +08:00 committed by GitHub
commit 2ed294bd65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 9 deletions

View File

@ -71,8 +71,16 @@ office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
#officefalsetrue #officefalsetrue
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false} 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
pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:false} 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} file.upload.disable = ${KK_FILE_UPLOAD_ENABLED:false}

View File

@ -35,7 +35,11 @@ public class ConfigConstants {
private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator; private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
private static String localPreviewDir; private static String localPreviewDir;
private static CopyOnWriteArraySet<String> trustHostSet; private static CopyOnWriteArraySet<String> trustHostSet;
private static String pdfPresentationModeDisable;
private static String pdfOpenFileDisable;
private static String pdfPrintDisable;
private static String pdfDownloadDisable; private static String pdfDownloadDisable;
private static String pdfBookmarkDisable;
private static Boolean fileUploadDisable; private static Boolean fileUploadDisable;
private static String tifPreviewType; private static String tifPreviewType;
@ -51,7 +55,11 @@ public class ConfigConstants {
public static final String DEFAULT_FILE_DIR_VALUE = "default"; public static final String DEFAULT_FILE_DIR_VALUE = "default";
public static final String DEFAULT_LOCAL_PREVIEW_DIR_VALUE = "default"; public static final String DEFAULT_LOCAL_PREVIEW_DIR_VALUE = "default";
public static final String DEFAULT_TRUST_HOST = "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_DOWNLOAD_DISABLE = "true";
public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true";
public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false"; public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false";
public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif"; public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif";
@ -249,11 +257,46 @@ public class ConfigConstants {
ConfigConstants.trustHostSet = trustHostSet; 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() { public static String getPdfDownloadDisable() {
return pdfDownloadDisable; return pdfDownloadDisable;
} }
@Value("${pdf.download.disable:true}") @Value("${pdf.download.disable:true}")
public void setPdfDownloadDisable(String pdfDownloadDisable) { public void setPdfDownloadDisable(String pdfDownloadDisable) {
setPdfDownloadDisableValue(pdfDownloadDisable); setPdfDownloadDisableValue(pdfDownloadDisable);
@ -262,6 +305,17 @@ public class ConfigConstants {
ConfigConstants.pdfDownloadDisable = pdfDownloadDisable; 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() { public static String getOfficePreviewSwitchDisabled() {
return officePreviewSwitchDisabled; return officePreviewSwitchDisabled;
} }

View File

@ -47,7 +47,11 @@ public class ConfigRefreshComponent {
String configFilePath = ConfigUtils.getCustomizedConfigPath(); String configFilePath = ConfigUtils.getCustomizedConfigPath();
String baseUrl; String baseUrl;
String trustHost; String trustHost;
String pdfPresentationModeDisable;
String pdfOpenFileDisable;
String pdfPrintDisable;
String pdfDownloadDisable; String pdfDownloadDisable;
String pdfBookmarkDisable;
boolean fileUploadDisable; boolean fileUploadDisable;
String tifPreviewType; String tifPreviewType;
@ -68,7 +72,11 @@ public class ConfigRefreshComponent {
mediaArray = media.split(","); mediaArray = media.split(",");
baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL); baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL);
trustHost = properties.getProperty("trust.host", ConfigConstants.DEFAULT_TRUST_HOST); 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); 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)); fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE));
tifPreviewType = properties.getProperty("tif.preview.type", ConfigConstants.DEFAULT_TIF_PREVIEW_TYPE); tifPreviewType = properties.getProperty("tif.preview.type", ConfigConstants.DEFAULT_TIF_PREVIEW_TYPE);
@ -82,7 +90,11 @@ public class ConfigRefreshComponent {
ConfigConstants.setBaseUrlValue(baseUrl); ConfigConstants.setBaseUrlValue(baseUrl);
ConfigConstants.setTrustHostValue(trustHost); ConfigConstants.setTrustHostValue(trustHost);
ConfigConstants.setOfficePreviewSwitchDisabledValue(officePreviewSwitchDisabled); ConfigConstants.setOfficePreviewSwitchDisabledValue(officePreviewSwitchDisabled);
ConfigConstants.setPdfPresentationModeDisableValue(pdfPresentationModeDisable);
ConfigConstants.setPdfOpenFileDisableValue(pdfOpenFileDisable);
ConfigConstants.setPdfPrintDisableValue(pdfPrintDisable);
ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable); ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
ConfigConstants.setPdfBookmarkDisableValue(pdfBookmarkDisable);
ConfigConstants.setFileUploadDisableValue(fileUploadDisable); ConfigConstants.setFileUploadDisableValue(fileUploadDisable);
ConfigConstants.setTifPreviewTypeValue(tifPreviewType); ConfigConstants.setTifPreviewTypeValue(tifPreviewType);
setWatermarkConfig(properties); setWatermarkConfig(properties);

View File

@ -31,7 +31,11 @@ public class AttributeSetFilter implements Filter {
*/ */
private void setFileAttribute(ServletRequest 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("pdfDownloadDisable", ConfigConstants.getPdfDownloadDisable());
request.setAttribute("pdfBookmarkDisable", ConfigConstants.getPdfBookmarkDisable());
request.setAttribute("fileKey", httpRequest.getParameter("fileKey")); request.setAttribute("fileKey", httpRequest.getParameter("fileKey"));
request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable()); request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable());

View File

@ -2240,13 +2240,21 @@ function reportPageStatsPDFBug({
} }
function webViewerInitialized() { function webViewerInitialized() {
const appConfig = PDFViewerApplication.appConfig; var appConfig = PDFViewerApplication.appConfig;
let file; var file;
let disableDownload; var disablePresentationMode;
const queryString = document.location.search.substring(1); var disableOpenFile;
const params = (0, _ui_utils.parseQueryString)(queryString); 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"); 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'; disableDownload = 'disabledownload' in params ? params.disabledownload : 'false';
disableBookmark = 'disablebookmark' in params ? params.disablebookmark : 'false';
validateFileURL(file); validateFileURL(file);
const fileInput = document.createElement("input"); const fileInput = document.createElement("input");
fileInput.id = appConfig.openFileInputName; fileInput.id = appConfig.openFileInputName;
@ -2329,8 +2337,30 @@ function webViewerInitialized() {
PDFViewerApplication._documentError(msg, reason); PDFViewerApplication._documentError(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) { if ('true' === disableDownload) {
document.getElementById("download").style.display='none'; 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';
} }
} }

View File

@ -26,7 +26,7 @@
if (!url.startsWith(baseUrl)) { if (!url.startsWith(baseUrl)) {
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(url); 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; document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
/** /**
* *