|
|
@ -92,6 +92,7 @@ var PDFViewerApplication = { |
|
|
|
initialized: false, |
|
|
|
initialized: false, |
|
|
|
fellback: false, |
|
|
|
fellback: false, |
|
|
|
pdfDocument: null, |
|
|
|
pdfDocument: null, |
|
|
|
|
|
|
|
pdfLoadingTask: null, |
|
|
|
sidebarOpen: false, |
|
|
|
sidebarOpen: false, |
|
|
|
printing: false, |
|
|
|
printing: false, |
|
|
|
/** @type {PDFViewer} */ |
|
|
|
/** @type {PDFViewer} */ |
|
|
@ -434,8 +435,8 @@ var PDFViewerApplication = { |
|
|
|
pdfDataRangeTransport = |
|
|
|
pdfDataRangeTransport = |
|
|
|
new FirefoxComDataRangeTransport(args.length, args.data); |
|
|
|
new FirefoxComDataRangeTransport(args.length, args.data); |
|
|
|
|
|
|
|
|
|
|
|
PDFViewerApplication.open(args.pdfUrl, 0, undefined, |
|
|
|
PDFViewerApplication.open(args.pdfUrl, |
|
|
|
pdfDataRangeTransport); |
|
|
|
{range: pdfDataRangeTransport}); |
|
|
|
|
|
|
|
|
|
|
|
if (args.length) { |
|
|
|
if (args.length) { |
|
|
|
PDFViewerApplication.pdfDocumentProperties |
|
|
|
PDFViewerApplication.pdfDocumentProperties |
|
|
@ -460,7 +461,7 @@ var PDFViewerApplication = { |
|
|
|
'An error occurred while loading the PDF.'), e); |
|
|
|
'An error occurred while loading the PDF.'), e); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
PDFViewerApplication.open(args.data, 0); |
|
|
|
PDFViewerApplication.open(args.data); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -487,36 +488,76 @@ var PDFViewerApplication = { |
|
|
|
document.title = title; |
|
|
|
document.title = title; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Closes opened PDF document. |
|
|
|
|
|
|
|
* @returns {Promise} - Returns the promise, which is resolved when all |
|
|
|
|
|
|
|
* destruction is completed. |
|
|
|
|
|
|
|
*/ |
|
|
|
close: function pdfViewClose() { |
|
|
|
close: function pdfViewClose() { |
|
|
|
var errorWrapper = document.getElementById('errorWrapper'); |
|
|
|
var errorWrapper = document.getElementById('errorWrapper'); |
|
|
|
errorWrapper.setAttribute('hidden', 'true'); |
|
|
|
errorWrapper.setAttribute('hidden', 'true'); |
|
|
|
|
|
|
|
|
|
|
|
if (!this.pdfDocument) { |
|
|
|
if (!this.pdfLoadingTask) { |
|
|
|
return; |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.pdfDocument.destroy(); |
|
|
|
var promise = this.pdfLoadingTask.destroy(); |
|
|
|
this.pdfDocument = null; |
|
|
|
this.pdfLoadingTask = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.pdfDocument) { |
|
|
|
|
|
|
|
this.pdfDocument = null; |
|
|
|
|
|
|
|
|
|
|
|
this.pdfThumbnailViewer.setDocument(null); |
|
|
|
this.pdfThumbnailViewer.setDocument(null); |
|
|
|
this.pdfViewer.setDocument(null); |
|
|
|
this.pdfViewer.setDocument(null); |
|
|
|
this.pdfLinkService.setDocument(null, null); |
|
|
|
this.pdfLinkService.setDocument(null, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof PDFBug !== 'undefined') { |
|
|
|
if (typeof PDFBug !== 'undefined') { |
|
|
|
PDFBug.cleanup(); |
|
|
|
PDFBug.cleanup(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return promise; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// TODO(mack): This function signature should really be pdfViewOpen(url, args)
|
|
|
|
/** |
|
|
|
open: function pdfViewOpen(file, scale, password, |
|
|
|
* Opens PDF document specified by URL or array with additional arguments. |
|
|
|
pdfDataRangeTransport, args) { |
|
|
|
* @param {string|TypedArray|ArrayBuffer} file - PDF location or binary data. |
|
|
|
if (this.pdfDocument) { |
|
|
|
* @param {Object} args - (optional) Additional arguments for the getDocument |
|
|
|
// Reload the preferences if a document was previously opened.
|
|
|
|
* call, e.g. HTTP headers ('httpHeaders') or |
|
|
|
Preferences.reload(); |
|
|
|
* alternative data transport ('range'). |
|
|
|
|
|
|
|
* @returns {Promise} - Returns the promise, which is resolved when document |
|
|
|
|
|
|
|
* is opened. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
open: function pdfViewOpen(file, args) { |
|
|
|
|
|
|
|
var scale = 0; |
|
|
|
|
|
|
|
if (arguments.length > 2 || typeof args === 'number') { |
|
|
|
|
|
|
|
console.warn('Call of open() with obsolete signature.'); |
|
|
|
|
|
|
|
if (typeof args === 'number') { |
|
|
|
|
|
|
|
scale = args; // scale argument was found
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
args = arguments[4] || null; |
|
|
|
|
|
|
|
if (arguments[3] && typeof arguments[3] === 'object') { |
|
|
|
|
|
|
|
// The pdfDataRangeTransport argument is present.
|
|
|
|
|
|
|
|
args = Object.create(args); |
|
|
|
|
|
|
|
args.range = arguments[3]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (typeof arguments[2] === 'string') { |
|
|
|
|
|
|
|
// The password argument is present.
|
|
|
|
|
|
|
|
args = Object.create(args); |
|
|
|
|
|
|
|
args.password = arguments[2]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.pdfLoadingTask) { |
|
|
|
|
|
|
|
// We need to destroy already opened document.
|
|
|
|
|
|
|
|
return this.close().then(function () { |
|
|
|
|
|
|
|
// Reload the preferences if a document was previously opened.
|
|
|
|
|
|
|
|
Preferences.reload(); |
|
|
|
|
|
|
|
// ... and repeat the open() call.
|
|
|
|
|
|
|
|
return this.open(file, args); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
this.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parameters = {password: password}; |
|
|
|
var parameters = Object.create(null); |
|
|
|
if (typeof file === 'string') { // URL
|
|
|
|
if (typeof file === 'string') { // URL
|
|
|
|
this.setTitleUsingUrl(file); |
|
|
|
this.setTitleUsingUrl(file); |
|
|
|
parameters.url = file; |
|
|
|
parameters.url = file; |
|
|
@ -526,9 +567,6 @@ var PDFViewerApplication = { |
|
|
|
this.setTitleUsingUrl(file.originalUrl); |
|
|
|
this.setTitleUsingUrl(file.originalUrl); |
|
|
|
parameters.url = file.url; |
|
|
|
parameters.url = file.url; |
|
|
|
} |
|
|
|
} |
|
|
|
if (pdfDataRangeTransport) { |
|
|
|
|
|
|
|
parameters.range = pdfDataRangeTransport; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (args) { |
|
|
|
if (args) { |
|
|
|
for (var prop in args) { |
|
|
|
for (var prop in args) { |
|
|
|
parameters[prop] = args[prop]; |
|
|
|
parameters[prop] = args[prop]; |
|
|
@ -539,6 +577,7 @@ var PDFViewerApplication = { |
|
|
|
self.downloadComplete = false; |
|
|
|
self.downloadComplete = false; |
|
|
|
|
|
|
|
|
|
|
|
var loadingTask = PDFJS.getDocument(parameters); |
|
|
|
var loadingTask = PDFJS.getDocument(parameters); |
|
|
|
|
|
|
|
this.pdfLoadingTask = loadingTask; |
|
|
|
|
|
|
|
|
|
|
|
loadingTask.onPassword = function passwordNeeded(updatePassword, reason) { |
|
|
|
loadingTask.onPassword = function passwordNeeded(updatePassword, reason) { |
|
|
|
PasswordPrompt.updatePassword = updatePassword; |
|
|
|
PasswordPrompt.updatePassword = updatePassword; |
|
|
@ -550,7 +589,7 @@ var PDFViewerApplication = { |
|
|
|
self.progress(progressData.loaded / progressData.total); |
|
|
|
self.progress(progressData.loaded / progressData.total); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
loadingTask.promise.then( |
|
|
|
var result = loadingTask.promise.then( |
|
|
|
function getDocumentCallback(pdfDocument) { |
|
|
|
function getDocumentCallback(pdfDocument) { |
|
|
|
self.load(pdfDocument, scale); |
|
|
|
self.load(pdfDocument, scale); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -576,12 +615,15 @@ var PDFViewerApplication = { |
|
|
|
message: message |
|
|
|
message: message |
|
|
|
}; |
|
|
|
}; |
|
|
|
self.error(loadingErrorMessage, moreInfo); |
|
|
|
self.error(loadingErrorMessage, moreInfo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new Error(loadingErrorMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (args && args.length) { |
|
|
|
if (args && args.length) { |
|
|
|
PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length); |
|
|
|
PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
download: function pdfViewDownload() { |
|
|
|
download: function pdfViewDownload() { |
|
|
@ -1008,6 +1050,9 @@ var PDFViewerApplication = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
cleanup: function pdfViewCleanup() { |
|
|
|
cleanup: function pdfViewCleanup() { |
|
|
|
|
|
|
|
if (!this.pdfDocument) { |
|
|
|
|
|
|
|
return; // run cleanup when document is loaded
|
|
|
|
|
|
|
|
} |
|
|
|
this.pdfViewer.cleanup(); |
|
|
|
this.pdfViewer.cleanup(); |
|
|
|
this.pdfThumbnailViewer.cleanup(); |
|
|
|
this.pdfThumbnailViewer.cleanup(); |
|
|
|
this.pdfDocument.cleanup(); |
|
|
|
this.pdfDocument.cleanup(); |
|
|
@ -1502,7 +1547,7 @@ function webViewerInitialized() { |
|
|
|
PDFViewerApplication.setTitleUsingUrl(file); |
|
|
|
PDFViewerApplication.setTitleUsingUrl(file); |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
xhr.onload = function() { |
|
|
|
xhr.onload = function() { |
|
|
|
PDFViewerApplication.open(new Uint8Array(xhr.response), 0); |
|
|
|
PDFViewerApplication.open(new Uint8Array(xhr.response)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
try { |
|
|
|
try { |
|
|
|
xhr.open('GET', file); |
|
|
|
xhr.open('GET', file); |
|
|
@ -1516,7 +1561,7 @@ function webViewerInitialized() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (file) { |
|
|
|
if (file) { |
|
|
|
PDFViewerApplication.open(file, 0); |
|
|
|
PDFViewerApplication.open(file); |
|
|
|
} |
|
|
|
} |
|
|
|
//#endif
|
|
|
|
//#endif
|
|
|
|
//#if CHROME
|
|
|
|
//#if CHROME
|
|
|
@ -1731,14 +1776,14 @@ window.addEventListener('change', function webViewerChange(evt) { |
|
|
|
|
|
|
|
|
|
|
|
if (!PDFJS.disableCreateObjectURL && |
|
|
|
if (!PDFJS.disableCreateObjectURL && |
|
|
|
typeof URL !== 'undefined' && URL.createObjectURL) { |
|
|
|
typeof URL !== 'undefined' && URL.createObjectURL) { |
|
|
|
PDFViewerApplication.open(URL.createObjectURL(file), 0); |
|
|
|
PDFViewerApplication.open(URL.createObjectURL(file)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Read the local file into a Uint8Array.
|
|
|
|
// Read the local file into a Uint8Array.
|
|
|
|
var fileReader = new FileReader(); |
|
|
|
var fileReader = new FileReader(); |
|
|
|
fileReader.onload = function webViewerChangeFileReaderOnload(evt) { |
|
|
|
fileReader.onload = function webViewerChangeFileReaderOnload(evt) { |
|
|
|
var buffer = evt.target.result; |
|
|
|
var buffer = evt.target.result; |
|
|
|
var uint8Array = new Uint8Array(buffer); |
|
|
|
var uint8Array = new Uint8Array(buffer); |
|
|
|
PDFViewerApplication.open(uint8Array, 0); |
|
|
|
PDFViewerApplication.open(uint8Array); |
|
|
|
}; |
|
|
|
}; |
|
|
|
fileReader.readAsArrayBuffer(file); |
|
|
|
fileReader.readAsArrayBuffer(file); |
|
|
|
} |
|
|
|
} |
|
|
|