|
|
|
@ -1,7 +1,250 @@
@@ -1,7 +1,250 @@
|
|
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
|
|
|
|
|
|
|
|
|
(function pdfApiWrapper() { |
|
|
|
|
PDFJS.getDocument = function getDocument(source) { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var transport = new WorkerTransport(promise); |
|
|
|
|
if (typeof source === 'string') { |
|
|
|
|
// fetch url
|
|
|
|
|
PDFJS.getPdf( |
|
|
|
|
{ |
|
|
|
|
url: source, |
|
|
|
|
progress: function getPDFProgress(evt) { |
|
|
|
|
if (evt.lengthComputable) |
|
|
|
|
promise.progress({ |
|
|
|
|
loaded: evt.loaded, |
|
|
|
|
total: evt.total |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
error: function getPDFError(e) { |
|
|
|
|
promise.reject('Unexpected server response of ' + |
|
|
|
|
e.target.status + '.'); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
function getPDFLoad(data) { |
|
|
|
|
transport.sendData(data); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// assuming the source is array, instantiating directly from it
|
|
|
|
|
transport.sendData(source); |
|
|
|
|
} |
|
|
|
|
return promise; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var PDFDocumentProxy = (function() { |
|
|
|
|
function PDFDocumentProxy(pdfInfo, transport) { |
|
|
|
|
this.pdfInfo = pdfInfo; |
|
|
|
|
this.transport = transport; |
|
|
|
|
} |
|
|
|
|
PDFDocumentProxy.prototype = { |
|
|
|
|
get numPages() { |
|
|
|
|
return this.pdfInfo.numPages; |
|
|
|
|
}, |
|
|
|
|
get fingerprint() { |
|
|
|
|
return this.pdfInfo.fingerprint; |
|
|
|
|
}, |
|
|
|
|
getPage: function(number) { |
|
|
|
|
return this.transport.getPage(number); |
|
|
|
|
}, |
|
|
|
|
getDestinations: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var destinations = this.pdfInfo.destinations; |
|
|
|
|
promise.resolve(destinations); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getOutline: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var outline = this.pdfInfo.outline; |
|
|
|
|
promise.resolve(outline); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getMetadata: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var info = this.pdfInfo.info; |
|
|
|
|
var metadata = this.pdfInfo.metadata; |
|
|
|
|
promise.resolve({ |
|
|
|
|
info: info, |
|
|
|
|
metadata: metadata ? new PDFJS.Metadata(metadata) : null |
|
|
|
|
}); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
destroy: function() { |
|
|
|
|
this.transport.destroy(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
return PDFDocumentProxy; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var PDFPageProxy = (function PDFPageProxyClosure() { |
|
|
|
|
function PDFPageProxy(pageInfo, transport) { |
|
|
|
|
this.pageInfo = pageInfo; |
|
|
|
|
this.transport = transport; |
|
|
|
|
this._stats = new StatTimer(); |
|
|
|
|
this.objs = transport.objs; |
|
|
|
|
} |
|
|
|
|
PDFPageProxy.prototype = { |
|
|
|
|
get pageNumber() { |
|
|
|
|
return this.pageInfo.pageIndex + 1; |
|
|
|
|
}, |
|
|
|
|
get rotate() { |
|
|
|
|
return this.pageInfo.rotate; |
|
|
|
|
}, |
|
|
|
|
get stats() { |
|
|
|
|
return this._stats; |
|
|
|
|
}, |
|
|
|
|
get ref() { |
|
|
|
|
return this.pageInfo.ref; |
|
|
|
|
}, |
|
|
|
|
get view() { |
|
|
|
|
return this.pageInfo.view; |
|
|
|
|
}, |
|
|
|
|
getViewport: function(scale, rotate) { |
|
|
|
|
if (arguments.length < 2) |
|
|
|
|
rotate = this.rotate; |
|
|
|
|
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0); |
|
|
|
|
}, |
|
|
|
|
getAnnotations: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var annotations = this.pageInfo.annotations; |
|
|
|
|
promise.resolve(annotations); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
render: function(renderContext) { |
|
|
|
|
var promise = new Promise(); |
|
|
|
|
var stats = this.stats; |
|
|
|
|
stats.time('Overall'); |
|
|
|
|
// If there is no displayReadyPromise yet, then the operatorList was never
|
|
|
|
|
// requested before. Make the request and create the promise.
|
|
|
|
|
if (!this.displayReadyPromise) { |
|
|
|
|
this.displayReadyPromise = new Promise(); |
|
|
|
|
|
|
|
|
|
this.stats.time('Page Request'); |
|
|
|
|
this.transport.messageHandler.send('RenderPageRequest', { |
|
|
|
|
pageIndex: this.pageNumber - 1 |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var callback = (function complete(error) { |
|
|
|
|
if (error) |
|
|
|
|
promise.reject(error); |
|
|
|
|
else |
|
|
|
|
promise.resolve(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Once the operatorList and fonts are loaded, do the actual rendering.
|
|
|
|
|
this.displayReadyPromise.then( |
|
|
|
|
function pageDisplayReadyPromise() { |
|
|
|
|
var gfx = new CanvasGraphics(renderContext.canvasContext, |
|
|
|
|
this.objs, renderContext.textLayer); |
|
|
|
|
try { |
|
|
|
|
this.display(gfx, renderContext.viewport, callback); |
|
|
|
|
} catch (e) { |
|
|
|
|
if (callback) |
|
|
|
|
callback(e); |
|
|
|
|
else |
|
|
|
|
error(e); |
|
|
|
|
} |
|
|
|
|
}.bind(this), |
|
|
|
|
function pageDisplayReadPromiseError(reason) { |
|
|
|
|
if (callback) |
|
|
|
|
callback(reason); |
|
|
|
|
else |
|
|
|
|
error(reason); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
startRenderingFromOperatorList: |
|
|
|
|
function PDFPageWrapper_startRenderingFromOperatorList(operatorList, |
|
|
|
|
fonts) { |
|
|
|
|
var self = this; |
|
|
|
|
this.operatorList = operatorList; |
|
|
|
|
|
|
|
|
|
var displayContinuation = function pageDisplayContinuation() { |
|
|
|
|
// Always defer call to display() to work around bug in
|
|
|
|
|
// Firefox error reporting from XHR callbacks.
|
|
|
|
|
setTimeout(function pageSetTimeout() { |
|
|
|
|
self.displayReadyPromise.resolve(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.ensureFonts(fonts, |
|
|
|
|
function pageStartRenderingFromOperatorListEnsureFonts() { |
|
|
|
|
displayContinuation(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
ensureFonts: function PDFPageWrapper_ensureFonts(fonts, callback) { |
|
|
|
|
this.stats.time('Font Loading'); |
|
|
|
|
// Convert the font names to the corresponding font obj.
|
|
|
|
|
for (var i = 0, ii = fonts.length; i < ii; i++) { |
|
|
|
|
fonts[i] = this.objs.objs[fonts[i]].data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load all the fonts
|
|
|
|
|
FontLoader.bind( |
|
|
|
|
fonts, |
|
|
|
|
function pageEnsureFontsFontObjs(fontObjs) { |
|
|
|
|
this.stats.timeEnd('Font Loading'); |
|
|
|
|
|
|
|
|
|
callback.call(this); |
|
|
|
|
}.bind(this) |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
display: function PDFPageWrapper_display(gfx, viewport, callback) { |
|
|
|
|
var stats = this.stats; |
|
|
|
|
stats.time('Rendering'); |
|
|
|
|
|
|
|
|
|
gfx.beginDrawing(viewport); |
|
|
|
|
|
|
|
|
|
var startIdx = 0; |
|
|
|
|
var length = this.operatorList.fnArray.length; |
|
|
|
|
var operatorList = this.operatorList; |
|
|
|
|
var stepper = null; |
|
|
|
|
if (PDFJS.pdfBug && StepperManager.enabled) { |
|
|
|
|
stepper = StepperManager.create(this.pageNumber); |
|
|
|
|
stepper.init(operatorList); |
|
|
|
|
stepper.nextBreakPoint = stepper.getNextBreakPoint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
function next() { |
|
|
|
|
startIdx = |
|
|
|
|
gfx.executeOperatorList(operatorList, startIdx, next, stepper); |
|
|
|
|
if (startIdx == length) { |
|
|
|
|
gfx.endDrawing(); |
|
|
|
|
stats.timeEnd('Rendering'); |
|
|
|
|
stats.timeEnd('Overall'); |
|
|
|
|
if (callback) callback(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
next(); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getTextContent: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var textContent = 'page text'; // not implemented
|
|
|
|
|
promise.resolve(textContent); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getOperationList: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var operationList = { // not implemented
|
|
|
|
|
dependencyFontsID: null, |
|
|
|
|
operatorList: null |
|
|
|
|
}; |
|
|
|
|
promise.resolve(operationList); |
|
|
|
|
return promise; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
return PDFPageProxy; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
|
function WorkerTransport(promise) { |
|
|
|
|
this.workerReadyPromise = promise; |
|
|
|
|
this.objs = new PDFObjects(); |
|
|
|
@ -92,22 +335,22 @@
@@ -92,22 +335,22 @@
|
|
|
|
|
function WorkerTransport_setupMessageHandler(messageHandler) { |
|
|
|
|
this.messageHandler = messageHandler; |
|
|
|
|
|
|
|
|
|
messageHandler.on('getdoc', function transportDoc(data) { |
|
|
|
|
messageHandler.on('GetDoc', function transportDoc(data) { |
|
|
|
|
var pdfInfo = data.pdfInfo; |
|
|
|
|
var pdfDocument = new PdfDocumentWrapper(pdfInfo, this); |
|
|
|
|
var pdfDocument = new PDFDocumentProxy(pdfInfo, this); |
|
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
|
this.workerReadyPromise.resolve(pdfDocument); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('getpage', function transportPage(data) { |
|
|
|
|
messageHandler.on('GetPage', function transportPage(data) { |
|
|
|
|
var pageInfo = data.pageInfo; |
|
|
|
|
var page = new PdfPageWrapper(pageInfo, this); |
|
|
|
|
var page = new PDFPageProxy(pageInfo, this); |
|
|
|
|
this.pageCache[pageInfo.pageIndex] = page; |
|
|
|
|
var promise = this.pagePromises[pageInfo.pageIndex]; |
|
|
|
|
promise.resolve(page); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('renderpage', function transportRender(data) { |
|
|
|
|
messageHandler.on('RenderPage', function transportRender(data) { |
|
|
|
|
var page = this.pageCache[data.pageIndex]; |
|
|
|
|
var depFonts = data.depFonts; |
|
|
|
|
|
|
|
|
@ -149,7 +392,7 @@
@@ -149,7 +392,7 @@
|
|
|
|
|
} |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('page_error', function transportError(data) { |
|
|
|
|
messageHandler.on('PageError', function transportError(data) { |
|
|
|
|
var page = this.pageCache[data.pageNum]; |
|
|
|
|
if (page.displayReadyPromise) |
|
|
|
|
page.displayReadyPromise.reject(data.error); |
|
|
|
@ -157,7 +400,7 @@
@@ -157,7 +400,7 @@
|
|
|
|
|
error(data.error); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('jpeg_decode', function(data, promise) { |
|
|
|
|
messageHandler.on('JpegDecode', function(data, promise) { |
|
|
|
|
var imageData = data[0]; |
|
|
|
|
var components = data[1]; |
|
|
|
|
if (components != 3 && components != 1) |
|
|
|
@ -194,7 +437,7 @@
@@ -194,7 +437,7 @@
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
sendData: function WorkerTransport_sendData(data) { |
|
|
|
|
this.messageHandler.send('getdoc_request', data); |
|
|
|
|
this.messageHandler.send('GetDocRequest', data); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getPage: function WorkerTransport_getPage(pageNumber, promise) { |
|
|
|
@ -203,245 +446,10 @@
@@ -203,245 +446,10 @@
|
|
|
|
|
return this.pagePromises[pageIndex]; |
|
|
|
|
var promise = new PDFJS.Promise('Page ' + pageNumber); |
|
|
|
|
this.pagePromises[pageIndex] = promise; |
|
|
|
|
this.messageHandler.send('getpage_request', { pageIndex: pageIndex }); |
|
|
|
|
return promise; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
function PdfPageWrapper(pageInfo, transport) { |
|
|
|
|
this.pageInfo = pageInfo; |
|
|
|
|
this.transport = transport; |
|
|
|
|
this._stats = new StatTimer(); |
|
|
|
|
this.objs = transport.objs; |
|
|
|
|
} |
|
|
|
|
PdfPageWrapper.prototype = { |
|
|
|
|
get pageNumber() { |
|
|
|
|
return this.pageInfo.pageIndex + 1; |
|
|
|
|
}, |
|
|
|
|
get rotate() { |
|
|
|
|
return this.pageInfo.rotate; |
|
|
|
|
}, |
|
|
|
|
get stats() { |
|
|
|
|
return this._stats; |
|
|
|
|
}, |
|
|
|
|
get ref() { |
|
|
|
|
return this.pageInfo.ref; |
|
|
|
|
}, |
|
|
|
|
get view() { |
|
|
|
|
return this.pageInfo.view; |
|
|
|
|
}, |
|
|
|
|
getViewport: function(scale, rotate) { |
|
|
|
|
if (arguments.length < 2) |
|
|
|
|
rotate = this.rotate; |
|
|
|
|
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0); |
|
|
|
|
}, |
|
|
|
|
getAnnotations: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var annotations = this.pageInfo.annotations; |
|
|
|
|
promise.resolve(annotations); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
render: function(renderContext) { |
|
|
|
|
var promise = new Promise(); |
|
|
|
|
var stats = this.stats; |
|
|
|
|
stats.time('Overall'); |
|
|
|
|
// If there is no displayReadyPromise yet, then the operatorList was never
|
|
|
|
|
// requested before. Make the request and create the promise.
|
|
|
|
|
if (!this.displayReadyPromise) { |
|
|
|
|
this.displayReadyPromise = new Promise(); |
|
|
|
|
|
|
|
|
|
this.stats.time('Page Request'); |
|
|
|
|
this.transport.messageHandler.send('renderpage_request', { |
|
|
|
|
pageIndex: this.pageNumber - 1 |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var callback = (function complete(error) { |
|
|
|
|
if (error) |
|
|
|
|
promise.reject(error); |
|
|
|
|
else |
|
|
|
|
promise.resolve(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Once the operatorList and fonts are loaded, do the actual rendering.
|
|
|
|
|
this.displayReadyPromise.then( |
|
|
|
|
function pageDisplayReadyPromise() { |
|
|
|
|
var gfx = new CanvasGraphics(renderContext.canvasContext, |
|
|
|
|
this.objs, renderContext.textLayer); |
|
|
|
|
try { |
|
|
|
|
this.display(gfx, renderContext.viewport, callback); |
|
|
|
|
} catch (e) { |
|
|
|
|
if (callback) |
|
|
|
|
callback(e); |
|
|
|
|
else |
|
|
|
|
error(e); |
|
|
|
|
} |
|
|
|
|
}.bind(this), |
|
|
|
|
function pageDisplayReadPromiseError(reason) { |
|
|
|
|
if (callback) |
|
|
|
|
callback(reason); |
|
|
|
|
else |
|
|
|
|
error(reason); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
startRenderingFromOperatorList: |
|
|
|
|
function PdfPageWrapper_startRenderingFromOperatorList(operatorList, |
|
|
|
|
fonts) { |
|
|
|
|
var self = this; |
|
|
|
|
this.operatorList = operatorList; |
|
|
|
|
|
|
|
|
|
var displayContinuation = function pageDisplayContinuation() { |
|
|
|
|
// Always defer call to display() to work around bug in
|
|
|
|
|
// Firefox error reporting from XHR callbacks.
|
|
|
|
|
setTimeout(function pageSetTimeout() { |
|
|
|
|
self.displayReadyPromise.resolve(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.ensureFonts(fonts, |
|
|
|
|
function pageStartRenderingFromOperatorListEnsureFonts() { |
|
|
|
|
displayContinuation(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
ensureFonts: function PdfPageWrapper_ensureFonts(fonts, callback) { |
|
|
|
|
this.stats.time('Font Loading'); |
|
|
|
|
// Convert the font names to the corresponding font obj.
|
|
|
|
|
for (var i = 0, ii = fonts.length; i < ii; i++) { |
|
|
|
|
fonts[i] = this.objs.objs[fonts[i]].data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load all the fonts
|
|
|
|
|
FontLoader.bind( |
|
|
|
|
fonts, |
|
|
|
|
function pageEnsureFontsFontObjs(fontObjs) { |
|
|
|
|
this.stats.timeEnd('Font Loading'); |
|
|
|
|
|
|
|
|
|
callback.call(this); |
|
|
|
|
}.bind(this) |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
display: function PdfPageWrapper_display(gfx, viewport, callback) { |
|
|
|
|
var stats = this.stats; |
|
|
|
|
stats.time('Rendering'); |
|
|
|
|
|
|
|
|
|
gfx.beginDrawing(viewport); |
|
|
|
|
|
|
|
|
|
var startIdx = 0; |
|
|
|
|
var length = this.operatorList.fnArray.length; |
|
|
|
|
var operatorList = this.operatorList; |
|
|
|
|
var stepper = null; |
|
|
|
|
if (PDFJS.pdfBug && StepperManager.enabled) { |
|
|
|
|
stepper = StepperManager.create(this.pageNumber); |
|
|
|
|
stepper.init(operatorList); |
|
|
|
|
stepper.nextBreakPoint = stepper.getNextBreakPoint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
function next() { |
|
|
|
|
startIdx = |
|
|
|
|
gfx.executeOperatorList(operatorList, startIdx, next, stepper); |
|
|
|
|
if (startIdx == length) { |
|
|
|
|
gfx.endDrawing(); |
|
|
|
|
stats.timeEnd('Rendering'); |
|
|
|
|
stats.timeEnd('Overall'); |
|
|
|
|
if (callback) callback(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
next(); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getTextContent: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var textContent = 'page text'; // not implemented
|
|
|
|
|
promise.resolve(textContent); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getOperationList: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var operationList = { // not implemented
|
|
|
|
|
dependencyFontsID: null, |
|
|
|
|
operatorList: null |
|
|
|
|
}; |
|
|
|
|
promise.resolve(operationList); |
|
|
|
|
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); |
|
|
|
|
return promise; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
return WorkerTransport; |
|
|
|
|
|
|
|
|
|
function PdfDocumentWrapper(pdfInfo, transport) { |
|
|
|
|
this.pdfInfo = pdfInfo; |
|
|
|
|
this.transport = transport; |
|
|
|
|
} |
|
|
|
|
PdfDocumentWrapper.prototype = { |
|
|
|
|
get numPages() { |
|
|
|
|
return this.pdfInfo.numPages; |
|
|
|
|
}, |
|
|
|
|
get fingerprint() { |
|
|
|
|
return this.pdfInfo.fingerprint; |
|
|
|
|
}, |
|
|
|
|
getPage: function(number) { |
|
|
|
|
return this.transport.getPage(number); |
|
|
|
|
}, |
|
|
|
|
getDestinations: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var destinations = this.pdfInfo.destinations; |
|
|
|
|
promise.resolve(destinations); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getOutline: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var outline = this.pdfInfo.outline; |
|
|
|
|
promise.resolve(outline); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
getMetadata: function() { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var info = this.pdfInfo.info; |
|
|
|
|
var metadata = this.pdfInfo.metadata; |
|
|
|
|
promise.resolve({ |
|
|
|
|
info: info, |
|
|
|
|
metadata: metadata ? new PDFJS.Metadata(metadata) : null |
|
|
|
|
}); |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
destroy: function() { |
|
|
|
|
this.transport.destroy(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
PDFJS.getDocument = function getDocument(source) { |
|
|
|
|
var promise = new PDFJS.Promise(); |
|
|
|
|
var transport = new WorkerTransport(promise); |
|
|
|
|
if (typeof source === 'string') { |
|
|
|
|
// fetch url
|
|
|
|
|
PDFJS.getPdf( |
|
|
|
|
{ |
|
|
|
|
url: source, |
|
|
|
|
progress: function getPdfProgress(evt) { |
|
|
|
|
if (evt.lengthComputable) |
|
|
|
|
promise.progress({ |
|
|
|
|
loaded: evt.loaded, |
|
|
|
|
total: evt.total |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
error: function getPdfError(e) { |
|
|
|
|
promise.reject('Unexpected server response of ' + |
|
|
|
|
e.target.status + '.'); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
function getPdfLoad(data) { |
|
|
|
|
transport.sendData(data); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// assuming the source is array, instantiating directly from it
|
|
|
|
|
transport.sendData(source); |
|
|
|
|
} |
|
|
|
|
return promise; |
|
|
|
|
}; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|