2014-10-27 124 views
1

PDFTron可以选择提供自定义Javascript文件来修改查看器,但我不确定该文件中应该包含哪些内容,并且我无法在Web上找到任何示例。PDFTron自定义脚本中应该包含哪些内容?

该网站有如下描述:

查看器选项 - 默认情况下,PWS云文件被加载在Web查看的基本托管版本。您可以通过加载外部JavaScript配置文件来自定义查看器的外观,品牌和自定义功能。

当我提供此文件,window.WebViewerUniversalInstance为空,并且的document.getElementById( '的DocumentViewer')也返回一个空对象。

有人能指点我在这里正确的方向,我迷路了。

感谢

回答

4

这个JavaScript文件是在观众的内部HTML页面(ReaderControl.html)允许您直接在浏览器修改东西,所以WebViewerUniversalInstance将是空的(如,在页内不的上下文中运行)。不过,我用var ele = document.getElementById('DocumentViewer');做了一个小测试文件,ele不是null,所以我不太清楚为什么这不适合你。

无论如何,你可以做一些事情的例子。对于自定义操作,您可能需要在“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:可用之后viewerloaded(readerControl.docViewer)
  • Document:documentLoaded(docViewer后可用。GetDocument())

如果您有更多的问题,你可以随时要求在Web查看论坛:https://groups.google.com/forum/#!forum/pdfnet-webviewer

+0

如果在Pdftron上托管,是否有任何方法可以为观众提供价值?我们正试图用已完成的搜索打开查看器。做搜索部分是好的,并且已经掌握了如何通常使用Javascript来与查看器一起工作,但是从我们的网站向观众提供价值是一种痛苦,因为跨域请求阻塞等等。可以为观众提供一个价值,也许作为URL上的一个参数? – JMK 2014-10-31 13:19:46

+0

你可以在你的服务器上启用CORS来处理你正在做的请求(http://enable-cors.org/server.html)吗?我只是在我的服务器上启用了一个小测试,然后做了一些简单的$ .get(“myserver.com/test.php”,function(result){...})。然后在回调中,我开始搜索,似乎所有的工作。 – mparizeau 2014-11-07 19:20:07

+1

嗨@mparizeau您是否考虑过公开一些更常用的功能,例如通过URL进行搜索。这将避免消费者需要考虑CORS。会很有帮助。 – richardwhatever 2014-11-10 12:45:55

1

我不知道我完全理解你的问题,但这里是我做了在外部配置文件PDF查看器,希望这将有助于在一定程度上:

<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(); 
} 
相关问题