**In html file add script tag**
<head>
<script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
</head>
<body>
<button id="prev" onclick="goPrevious()">Previous</button>
<button id="next" onclick="goNext()">Next</button>
<span>Page: <span id="page_num"></span>
<span id="page_count"></span></span>
</div>
<div>
<canvas id="the-canvas" width="700" style="border:1px solid black"></canvas>
</div>
</body>
并在客户端(pdf.java)使用 JSNI 调用 java 脚本函数,并将 pdf.js 文件粘贴到公共文件夹中并调用 .gwt.xml
**I am just follow this link http://jsbin.com/pdfjs-prevnext-v2/1/edit**
public void onModuleLoad() {
alert1();
}
private native void alert1 ()
/*-{
var url = 'http://cdn.mozilla.net/pdfjs/tracemonkey.pdf';
PDFJS.disableWorker = true;
var pdfDoc = null,
pageNum = 1,
scale = 0.8,
canvas = document.getElementById('the-canvas'),
ctx = canvas.getContext('2d');
function renderPage(num) {
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport(canvas.width / page.getViewport(1.0).width);
canvas.height = viewport.height;
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
page.render(renderContext);
});
document.getElementById('page_num').textContent = pageNum;
document.getElementById('page_count').textContent = pdfDoc.numPages;
}
function goPrevious() {
if (pageNum <= 1) return;
pageNum--;
renderPage(pageNum);
}
function goNext() {
if (pageNum >= pdfDoc.numPages) return;
pageNum++;
renderPage(pageNum);
}
PDFJS.getDocument(url).then(function getPdfHelloWorld(_pdfDoc) {
pdfDoc = _pdfDoc;
renderPage(pageNum);
});
}-*/;
11:27:17.679 [错误] [pdf] 无法加载模块入口点类 com.ruchi.client.Pdf(有关详细信息,请参阅相关异常)com.google.gwt.core.client.JavaScriptException: (ReferenceError): PDFJS is未在 com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 在 com.google.gwt 的 com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248) 定义.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) 在 com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289) 在 com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid (JavaScriptHost.java:107) 在 com.ruchi.client.Pdf.alert1(Pdf.java) 在 com.ruchi.client.Pdf.onModuleLoad(Pdf.java:27) 在 sun.reflect。com.google 上 java.lang.reflect.Method.invoke(Unknown Source) 上 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 上 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 上的 NativeMethodAccessorImpl.invoke0(Native Method)。 gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) 在 com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) 在 com.google.gwt.dev.shell.BrowserChannelServer。 processConnection(BrowserChannelServer.java:525) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Unknown Source)DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev .shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) 在 com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) 在 com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer .java:363)在 java.lang.Thread.run(未知来源)DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev .shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) 在 com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) 在 com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer .java:363)在 java.lang.Thread.run(未知来源)shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Unknown Source)shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Unknown Source)
plz suggest me what i do....