commit
43dbc3a84d
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<!-- In production, only one script (pdf.js) is necessary -->
|
<!-- In production, only one script (pdf.js) is necessary -->
|
||||||
|
<!-- In production, change the content of PDFJS.workerSrc below -->
|
||||||
<script type="text/javascript" src="../../src/core.js"></script>
|
<script type="text/javascript" src="../../src/core.js"></script>
|
||||||
<script type="text/javascript" src="../../src/util.js"></script>
|
<script type="text/javascript" src="../../src/util.js"></script>
|
||||||
<script type="text/javascript" src="../../src/canvas.js"></script>
|
<script type="text/javascript" src="../../src/canvas.js"></script>
|
||||||
@ -22,6 +23,11 @@
|
|||||||
<script type="text/javascript" src="../../src/stream.js"></script>
|
<script type="text/javascript" src="../../src/stream.js"></script>
|
||||||
<script type="text/javascript" src="../../src/worker.js"></script>
|
<script type="text/javascript" src="../../src/worker.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
// Specify the main script used to create a new PDF.JS web worker.
|
||||||
|
// In production, change this to point to the combined `pdf.js` file.
|
||||||
|
PDFJS.workerSrc = '../../src/worker_loader.js';
|
||||||
|
</script>
|
||||||
<script type="text/javascript" src="hello.js"></script>
|
<script type="text/javascript" src="hello.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
13
src/core.js
13
src/core.js
@ -472,7 +472,18 @@ var PDFDoc = (function pdfDoc() {
|
|||||||
this.pageCache = [];
|
this.pageCache = [];
|
||||||
|
|
||||||
if (useWorker) {
|
if (useWorker) {
|
||||||
var worker = new Worker('../src/worker_loader.js');
|
var workerSrc = PDFJS.workerSrc;
|
||||||
|
if (typeof workerSrc === 'undefined') {
|
||||||
|
throw 'No PDFJS.workerSrc specified';
|
||||||
|
}
|
||||||
|
|
||||||
|
var worker = new Worker(workerSrc);
|
||||||
|
|
||||||
|
// Tell the worker the file it was created from.
|
||||||
|
worker.postMessage({
|
||||||
|
action: 'workerSrc',
|
||||||
|
data: workerSrc
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||||
var worker = {
|
var worker = {
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
var PDFJS = {};
|
var PDFJS = {};
|
||||||
|
|
||||||
(function pdfjsWrapper() {
|
(function pdfjsWrapper() {
|
||||||
|
|
||||||
// Use strict in our context only - users might not want it
|
// Use strict in our context only - users might not want it
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Files are inserted below - see Makefile
|
// Files are inserted below - see Makefile
|
||||||
/* PDFJSSCRIPT_INCLUDE_ALL */
|
/* PDFJSSCRIPT_INCLUDE_ALL */
|
||||||
|
|
||||||
})();
|
}).call((typeof window === 'undefined') ? this : window);
|
||||||
|
|
||||||
|
@ -47,6 +47,13 @@ var WorkerProcessorHandler = {
|
|||||||
setup: function wphSetup(handler) {
|
setup: function wphSetup(handler) {
|
||||||
var pdfDoc = null;
|
var pdfDoc = null;
|
||||||
|
|
||||||
|
handler.on('workerSrc', function wphSetupWorkerSrc(data) {
|
||||||
|
// In development, the `workerSrc` message is handled in the
|
||||||
|
// `worker_loader.js` file. In production the workerProcessHandler is
|
||||||
|
// called for this. This servers as a dummy to prevent calling an
|
||||||
|
// undefined action `workerSrc`.
|
||||||
|
});
|
||||||
|
|
||||||
handler.on('doc', function wphSetupDoc(data) {
|
handler.on('doc', function wphSetupDoc(data) {
|
||||||
// Create only the model of the PDFDoc, which is enough for
|
// Create only the model of the PDFDoc, which is enough for
|
||||||
// processing the content of the pdf.
|
// processing the content of the pdf.
|
||||||
@ -176,8 +183,7 @@ var workerConsole = {
|
|||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
globalScope.console = workerConsole;
|
globalScope.console = workerConsole;
|
||||||
|
|
||||||
// Listen for messages from the main thread.
|
var handler = new MessageHandler('worker_processor', this);
|
||||||
var handler = new MessageHandler('worker_processor', globalScope);
|
|
||||||
WorkerProcessorHandler.setup(handler);
|
WorkerProcessorHandler.setup(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,22 +3,50 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
importScripts('../src/core.js');
|
function onMessageLoader(evt) {
|
||||||
importScripts('../src/util.js');
|
// Reset the `onmessage` function as it was only set to call
|
||||||
importScripts('../src/canvas.js');
|
// this function the first time a message is passed to the worker
|
||||||
importScripts('../src/obj.js');
|
// but shouldn't get called anytime afterwards.
|
||||||
importScripts('../src/function.js');
|
this.onmessage = null;
|
||||||
importScripts('../src/charsets.js');
|
|
||||||
importScripts('../src/cidmaps.js');
|
|
||||||
importScripts('../src/colorspace.js');
|
|
||||||
importScripts('../src/crypto.js');
|
|
||||||
importScripts('../src/evaluator.js');
|
|
||||||
importScripts('../src/fonts.js');
|
|
||||||
importScripts('../src/glyphlist.js');
|
|
||||||
importScripts('../src/image.js');
|
|
||||||
importScripts('../src/metrics.js');
|
|
||||||
importScripts('../src/parser.js');
|
|
||||||
importScripts('../src/pattern.js');
|
|
||||||
importScripts('../src/stream.js');
|
|
||||||
importScripts('../src/worker.js');
|
|
||||||
|
|
||||||
|
if (evt.data.action !== 'workerSrc') {
|
||||||
|
throw 'Worker expects first message to be `workerSrc`';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content of `PDFJS.workerSrc` as defined on the main thread.
|
||||||
|
var workerSrc = evt.data.data;
|
||||||
|
|
||||||
|
// Extract the directory that contains the source files to load.
|
||||||
|
// Assuming the source files have the same relative possition as the
|
||||||
|
// `workerSrc` file.
|
||||||
|
var dir = workerSrc.substring(0, workerSrc.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
|
// List of files to include;
|
||||||
|
var files = [
|
||||||
|
'core.js',
|
||||||
|
'util.js',
|
||||||
|
'canvas.js',
|
||||||
|
'obj.js',
|
||||||
|
'function.js',
|
||||||
|
'charsets.js',
|
||||||
|
'cidmaps.js',
|
||||||
|
'colorspace.js',
|
||||||
|
'crypto.js',
|
||||||
|
'evaluator.js',
|
||||||
|
'fonts.js',
|
||||||
|
'glyphlist.js',
|
||||||
|
'image.js',
|
||||||
|
'metrics.js',
|
||||||
|
'parser.js',
|
||||||
|
'pattern.js',
|
||||||
|
'stream.js',
|
||||||
|
'worker.js'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Load all the files.
|
||||||
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
importScripts(dir + files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onmessage = onMessageLoader.bind(this);
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
<script type="text/javascript" src="/src/stream.js"></script>
|
<script type="text/javascript" src="/src/stream.js"></script>
|
||||||
<script type="text/javascript" src="/src/worker.js"></script>
|
<script type="text/javascript" src="/src/worker.js"></script>
|
||||||
<script type="text/javascript" src="driver.js"></script>
|
<script type="text/javascript" src="driver.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
PDFJS.workerSrc = '/src/worker_loader.js';
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
<!-- This snippet is used in production, see Makefile -->
|
<!-- This snippet is used in production, see Makefile -->
|
||||||
<script type="text/javascript" src="../build/pdf.js"></script>
|
<script type="text/javascript" src="../build/pdf.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
// This specifies the location of the pdf.js file.
|
||||||
|
PDFJS.workerSrc = "../build/pdf.js";
|
||||||
|
</script>
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Simple pdf.js page viewer</title>
|
<title>Simple pdf.js page viewer</title>
|
||||||
<link rel="stylesheet" href="viewer.css"/>
|
<link rel="stylesheet" href="viewer.css"/>
|
||||||
|
|
||||||
<script type="text/javascript" src="compatibility.js"></script>
|
<script type="text/javascript" src="compatibility.js"></script>
|
||||||
|
|
||||||
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
|
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
|
||||||
|
|
||||||
<script type="text/javascript" src="../src/core.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
<script type="text/javascript" src="../src/core.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
<script type="text/javascript" src="../src/util.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
<script type="text/javascript" src="../src/util.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
<script type="text/javascript" src="../src/canvas.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
<script type="text/javascript" src="../src/canvas.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
@ -26,6 +26,8 @@
|
|||||||
<script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
<script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
|
|
||||||
|
<script type="text/javascript">PDFJS.workerSrc = '../src/worker_loader.js';</script> <!-- PDFJSSCRIPT_REMOVE -->
|
||||||
|
|
||||||
<script type="text/javascript" src="viewer.js"></script>
|
<script type="text/javascript" src="viewer.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user