Using blob URL for open file
This commit is contained in:
parent
141669a318
commit
18515b8668
@ -45,7 +45,8 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||||||
function NetworkManager(url, args) {
|
function NetworkManager(url, args) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
args = args || {};
|
args = args || {};
|
||||||
this.httpHeaders = args.httpHeaders || {};
|
this.isHttp = /^https?:/i.test(url);
|
||||||
|
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
|
||||||
this.withCredentials = args.withCredentials || false;
|
this.withCredentials = args.withCredentials || false;
|
||||||
this.getXhr = args.getXhr ||
|
this.getXhr = args.getXhr ||
|
||||||
function NetworkManager_getXhr() {
|
function NetworkManager_getXhr() {
|
||||||
@ -107,7 +108,7 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||||||
}
|
}
|
||||||
xhr.setRequestHeader(property, value);
|
xhr.setRequestHeader(property, value);
|
||||||
}
|
}
|
||||||
if ('begin' in args && 'end' in args) {
|
if (this.isHttp && 'begin' in args && 'end' in args) {
|
||||||
var rangeStr = args.begin + '-' + (args.end - 1);
|
var rangeStr = args.begin + '-' + (args.end - 1);
|
||||||
xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
|
xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
|
||||||
pendingRequest.expectedStatus = 206;
|
pendingRequest.expectedStatus = 206;
|
||||||
@ -162,7 +163,7 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||||||
delete this.pendingRequests[xhrId];
|
delete this.pendingRequests[xhrId];
|
||||||
|
|
||||||
// success status == 0 can be on ftp, file and other protocols
|
// success status == 0 can be on ftp, file and other protocols
|
||||||
if (xhr.status === 0 && /^https?:/i.test(this.url)) {
|
if (xhr.status === 0 && this.isHttp) {
|
||||||
if (pendingRequest.onError) {
|
if (pendingRequest.onError) {
|
||||||
pendingRequest.onError(xhr.status);
|
pendingRequest.onError(xhr.status);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
|
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
|
||||||
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
|
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
|
||||||
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
|
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
|
||||||
Preferences, ViewHistory, PageView, ThumbnailView,
|
Preferences, ViewHistory, PageView, ThumbnailView, URL,
|
||||||
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
|
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
|
||||||
PresentationMode, HandTool, Promise, DocumentProperties */
|
PresentationMode, HandTool, Promise, DocumentProperties */
|
||||||
|
|
||||||
@ -1821,8 +1821,6 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
|||||||
// var streamUrl = response.streamUrl;
|
// var streamUrl = response.streamUrl;
|
||||||
// if (streamUrl) {
|
// if (streamUrl) {
|
||||||
// console.log('Found data stream for ' + file);
|
// console.log('Found data stream for ' + file);
|
||||||
// // The blob stream can be used only once, so disable range requests.
|
|
||||||
// PDFJS.disableRange = true;
|
|
||||||
// PDFView.open(streamUrl, 0);
|
// PDFView.open(streamUrl, 0);
|
||||||
// PDFView.setTitleUsingUrl(file);
|
// PDFView.setTitleUsingUrl(file);
|
||||||
// return;
|
// return;
|
||||||
@ -1936,11 +1934,18 @@ window.addEventListener('hashchange', function webViewerHashchange(evt) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//#if !(FIREFOX || MOZCENTRAL || CHROME)
|
||||||
window.addEventListener('change', function webViewerChange(evt) {
|
window.addEventListener('change', function webViewerChange(evt) {
|
||||||
var files = evt.target.files;
|
var files = evt.target.files;
|
||||||
if (!files || files.length === 0)
|
if (!files || files.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var file = files[0];
|
||||||
|
|
||||||
|
if (!PDFJS.disableCreateObjectURL &&
|
||||||
|
typeof URL !== 'undefined' && URL.createObjectURL) {
|
||||||
|
PDFView.open(URL.createObjectURL(file), 0);
|
||||||
|
} 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) {
|
||||||
@ -1948,9 +1953,9 @@ window.addEventListener('change', function webViewerChange(evt) {
|
|||||||
var uint8Array = new Uint8Array(buffer);
|
var uint8Array = new Uint8Array(buffer);
|
||||||
PDFView.open(uint8Array, 0);
|
PDFView.open(uint8Array, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
var file = files[0];
|
|
||||||
fileReader.readAsArrayBuffer(file);
|
fileReader.readAsArrayBuffer(file);
|
||||||
|
}
|
||||||
|
|
||||||
PDFView.setTitleUsingUrl(file.name);
|
PDFView.setTitleUsingUrl(file.name);
|
||||||
|
|
||||||
// URL does not reflect proper document location - hiding some icons.
|
// URL does not reflect proper document location - hiding some icons.
|
||||||
@ -1960,6 +1965,7 @@ window.addEventListener('change', function webViewerChange(evt) {
|
|||||||
document.getElementById('download').setAttribute('hidden', 'true');
|
document.getElementById('download').setAttribute('hidden', 'true');
|
||||||
document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
|
document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
|
||||||
}, true);
|
}, true);
|
||||||
|
//#endif
|
||||||
|
|
||||||
function selectScaleOption(value) {
|
function selectScaleOption(value) {
|
||||||
var options = document.getElementById('scaleSelect').options;
|
var options = document.getElementById('scaleSelect').options;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user