PDFTron自定义脚本中应该包含哪些内容
What should go in a PDFTron custom script?
PDFTron可以选择提供一个自定义的Javascript文件来修改查看器,但我不确定这个文件中应该包含什么,而且我在网上找不到任何示例。
该网站有以下描述:
查看器选项-默认情况下,PWS Cloud文档加载在WebViewer的基本托管版本中。您可以通过加载外部JavaScript配置文件来自定义查看器的外观、品牌和自定义功能。
当我提供此文件时,window.WebViewerUniversalInstance为null,document.getElementById('DocumentViewer')也返回null对象。
有人能给我指个正确的方向吗?我迷路了。
感谢
此JavaScript文件在查看器的内部html页面(ReaderControl.html)的上下文中运行,允许您直接在查看器中修改内容,因此WebViewerUniversalInstance将为null(因为它不在内部页面中)。然而,我用var ele = document.getElementById('DocumentViewer');
制作了一个小的测试文件,ele不为空,所以我不太确定为什么这对你不起作用。
总之,一些你可以做的事情的例子。对于自定义操作,你可能想在"viewerLoaded"或"documentLoaded"事件中运行代码。对于UI更改,您不需要在任何一个事件中都有代码。
例如,如果你想隐藏打印按钮,你可以把它放在你的文件中:
$('#printButton').hide();
对于修改与UI相关的东西,我建议右键单击,检查元素以找到要修改的东西的ids/类。或者,您可以下载WebViewer并查看ReaderControl.html。
以下是在viewerLoaded事件中执行某些操作的示例:
$(document).on('viewerLoaded', function() {
readerControl.docViewer.SetMargin(0);
});
下面是在documentLoaded事件中执行某些操作的示例:
$(document).on('documentLoaded', function() {
readerControl.setCurrentPageNumber(2);
readerControl.rotateClockwise();
readerControl.setZoomLevel(2);
});
你可以做很多很多事情,你可以在这里查看文档:http://www.pdftron.com/webviewer/demo/lib/html5/doc/
您可能感兴趣的一些对象:
- readerControl:在viewerLoaded之后可用
- DocumentViewer:加载视图后可用(readerControl.docViewer)
- 文档:在documentLoaded之后可用(docViewer.GetDocument())
如果您有更多问题,可以随时在WebViewer论坛上提问:https://groups.google.com/forum/#!论坛/pdfnet webviewer
我不确定我是否完全理解您的问题,但以下是我在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();
}
- 选项中包含数据的自定义标记
- 将 d3 演示中的圆圈和文本替换为包含自定义 HTML 和 ko 绑定的 foreignObject
- Angular2中列表组件的自定义模板(不包含ng内容的transclusion)
- 如何使用自定义角度指令包含子元素
- 这些事件处理程序中的哪一个应该在窗口关闭时触发自定义函数
- 操作无法使用自定义控件上的呈现属性集,该控件包含操作按钮
- jquery 可拖动自定义包含
- 在 AMP 中包含自定义 JavaScript 的最佳方式
- 在自定义标记中查找包含特定值的元素,并带有空格分隔的值
- Angular2:仅包含数字的字段的自定义验证
- 在应用脚本中,如何在自定义函数中包含可选参数
- 包含查询字符串值的安卓自定义网址方案
- jQuery 选择
,自定义属性包含“:” - JavaScript:为什么getOwnPropertyDescriptor()包含自定义的继承属性
- 如何在Magento电子商务网站版本1.3.2.4中包含带有脚本的自定义js文件
- 最小化包含自定义过滤器的AngularJS脚本
- 有没有一种优雅的方法可以将javascript文件包含在自定义指令javascript文件中
- 如何在Rails应用程序中包含带有自定义css和js文件的静态页面
- 在express.js / node.js中包含headers +自定义服务器端.js的正确方法
- 如何使用unescape()在变量中包含html自定义字符?