我不确定我是否完全理解你的问题,但这是我在 PDFViewer 中为外部配置文件所做的,希望这会在一定程度上有所帮助:
<script type="text/javascript">
$(function () {
var customData = { serviceUrl: 'services/PDFWebService.asmx', token: '<%=initialDoc.Value %>', isReadonly: '<%=IsReadonly?"yes":"no" %>' };
var myWebViewer = new PDFTron.WebViewer({
path: "Resources/js/PDFTron",
mobileRedirect: false, // Disable redirect in mobile view.
stream: true,
config: 'Resources/js/PDFViewerConfig.js',
documentType: "pdf",
custom: JSON.stringify(customData),
l: '<%=LicenseKey%>',
initialDoc: customData.serviceUrl + '/GetFile?token=' + customData.token
}, document.getElementById('viewer'));
});
我的 PDFViewerConfig.js 是:
(function () {
$(document).on('viewerLoaded', function () {
customData = JSON.parse(window.ControlUtils.getCustomData());
SetupCustomizations();
});
$(document).on('documentLoaded', function () {
setDisabled("#btnSave");
setDisabled("#btnReset");
setDisabled("#btnPushUp");
});
$(document).on('pageChanged', function (event) {
var currentPageNumber = readerControl.getCurrentPageNumber();
var totalPages = readerControl.docViewer.getDocument().getPageCount();
if (currentPageNumber == totalPages) {
setDisabled("#btnPushDown");
setEnabled("#btnPushUp");
}
else if (currentPageNumber == 1) {
setDisabled("#btnPushUp");
setEnabled("#btnPushDown");
}
else {
setEnabled("#btnPushUp");
setEnabled("#btnPushDown");
}
});
})();
function SetupCustomizations() {
if (customData && customData.isReadonly != "yes") {
var removeButton = $('<span aria-disabled="false" role="button" tabindex="0" class="glyphicons remove" title="remove page"></span>');
var saveButton = $('<span aria-disabled="true" role="button" tabindex="0" id="btnSave" class="glyphicons floppy_disk disabled" title="save changes"></span>');
var resetButton = $('<span aria-disabled="true" role="button" tabindex="0" id="btnReset" class="glyphicons restart disabled" title="reset to original"></span>');
var rotateRightButton = $('<span aria-disabled="false" role="button" tabindex="0" class="glyphicons share" title="rotate right"></span>');
var rotateLeftButton = $('<span aria-disabled="false" role="button" tabindex="0" class="glyphicons unshare" title="rotate left"></span>');
var pushDownButton = $('<span aria-disabled="false" role="button" tabindex="0" id="btnPushDown" class="glyphicons down_arrow" title="move current page down"></span>');
var pushUpButton = $('<span aria-disabled="true" role="button" tabindex="0" id="btnPushUp" class="glyphicons up_arrow disabled" title="move current page up"></span>');
removeButton.on('click', onRemove);
removeButton.on('keydown', onRemove);
saveButton.on('click', onSave);
saveButton.on('keydown', onSave);
resetButton.on('click', onReset);
resetButton.on('keydown', onReset);
rotateRightButton.on('click', onRotateRight);
rotateRightButton.on('keydown', onRotateRight);
rotateLeftButton.on('click', onRotateLeft);
rotateLeftButton.on('keydown', onRotateLeft);
pushDownButton.on('click', onPushDown);
pushDownButton.on('keydown', onPushDown);
pushUpButton.on('click', onPushUp);
pushUpButton.on('keydown', onPushUp);
var newButtonsPlaceholder = $("#downloadButton").parent();
newButtonsPlaceholder.prepend(removeButton);
newButtonsPlaceholder.prepend(rotateLeftButton);
newButtonsPlaceholder.prepend(rotateRightButton);
newButtonsPlaceholder.prepend(pushDownButton);
newButtonsPlaceholder.prepend(pushUpButton);
newButtonsPlaceholder.prepend(saveButton);
newButtonsPlaceholder.prepend(resetButton);
}
//508
$("#ui-id-3").attr("tabindex", "0");
$("#prevPage").attr("tabindex", "0");
$("#nextPage").attr("tabindex", "0");
$("#printButton").attr("tabindex", "0");
$("#fullScreenButton").attr("tabindex", "0");
$("#downloadButton").attr("tabindex", "0");
$("#zoomIn").attr("tabindex", "0");
$("#zoomOut").attr("tabindex", "0");
$("#fitWidth").attr("tabindex", "0");
$("#fitPage").attr("tabindex", "0");
$("#prevPage").attr("role", "button");
$("#nextPage").attr("role", "button");
$("#printButton").attr("role", "button");
$("#fullScreenButton").attr("role", "button");
$("#zoomIn").attr("role", "button");
$("#zoomOut").attr("role", "button");
removeExtraButtons();
}