pdf_manager.js
7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs/core/pdf_manager', ['exports', 'pdfjs/shared/util',
'pdfjs/core/stream', 'pdfjs/core/chunked_stream', 'pdfjs/core/document'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./stream.js'),
require('./chunked_stream.js'), require('./document.js'));
} else {
factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
root.pdfjsCoreDocument);
}
}(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
coreDocument) {
var warn = sharedUtil.warn;
var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
var shadow = sharedUtil.shadow;
var NotImplementedException = sharedUtil.NotImplementedException;
var MissingDataException = sharedUtil.MissingDataException;
var createPromiseCapability = sharedUtil.createPromiseCapability;
var Util = sharedUtil.Util;
var Stream = coreStream.Stream;
var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
var PDFDocument = coreDocument.PDFDocument;
var BasePdfManager = (function BasePdfManagerClosure() {
function BasePdfManager() {
throw new Error('Cannot initialize BaseManagerManager');
}
BasePdfManager.prototype = {
get docId() {
return this._docId;
},
get password() {
return this._password;
},
get docBaseUrl() {
var docBaseUrl = null;
if (this._docBaseUrl) {
var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
if (absoluteUrl) {
docBaseUrl = absoluteUrl.href;
} else {
warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
}
}
return shadow(this, 'docBaseUrl', docBaseUrl);
},
onLoadedStream: function BasePdfManager_onLoadedStream() {
throw new NotImplementedException();
},
ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
return this.ensure(this.pdfDocument, prop, args);
},
ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
return this.ensure(this.pdfDocument.xref, prop, args);
},
ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
return this.ensure(this.pdfDocument.catalog, prop, args);
},
getPage: function BasePdfManager_getPage(pageIndex) {
return this.pdfDocument.getPage(pageIndex);
},
cleanup: function BasePdfManager_cleanup() {
return this.pdfDocument.cleanup();
},
ensure: function BasePdfManager_ensure(obj, prop, args) {
return new NotImplementedException();
},
requestRange: function BasePdfManager_requestRange(begin, end) {
return new NotImplementedException();
},
requestLoadedStream: function BasePdfManager_requestLoadedStream() {
return new NotImplementedException();
},
sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
return new NotImplementedException();
},
updatePassword: function BasePdfManager_updatePassword(password) {
this._password = password;
},
terminate: function BasePdfManager_terminate() {
return new NotImplementedException();
}
};
return BasePdfManager;
})();
var LocalPdfManager = (function LocalPdfManagerClosure() {
function LocalPdfManager(docId, data, password, evaluatorOptions,
docBaseUrl) {
this._docId = docId;
this._password = password;
this._docBaseUrl = docBaseUrl;
this.evaluatorOptions = evaluatorOptions;
var stream = new Stream(data);
this.pdfDocument = new PDFDocument(this, stream);
this._loadedStreamCapability = createPromiseCapability();
this._loadedStreamCapability.resolve(stream);
}
Util.inherit(LocalPdfManager, BasePdfManager, {
ensure: function LocalPdfManager_ensure(obj, prop, args) {
return new Promise(function (resolve, reject) {
try {
var value = obj[prop];
var result;
if (typeof value === 'function') {
result = value.apply(obj, args);
} else {
result = value;
}
resolve(result);
} catch (e) {
reject(e);
}
});
},
requestRange: function LocalPdfManager_requestRange(begin, end) {
return Promise.resolve();
},
requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
return;
},
onLoadedStream: function LocalPdfManager_onLoadedStream() {
return this._loadedStreamCapability.promise;
},
terminate: function LocalPdfManager_terminate() {
return;
}
});
return LocalPdfManager;
})();
var NetworkPdfManager = (function NetworkPdfManagerClosure() {
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions,
docBaseUrl) {
this._docId = docId;
this._password = args.password;
this._docBaseUrl = docBaseUrl;
this.msgHandler = args.msgHandler;
this.evaluatorOptions = evaluatorOptions;
var params = {
msgHandler: args.msgHandler,
url: args.url,
length: args.length,
disableAutoFetch: args.disableAutoFetch,
rangeChunkSize: args.rangeChunkSize
};
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
}
Util.inherit(NetworkPdfManager, BasePdfManager, {
ensure: function NetworkPdfManager_ensure(obj, prop, args) {
var pdfManager = this;
return new Promise(function (resolve, reject) {
function ensureHelper() {
try {
var result;
var value = obj[prop];
if (typeof value === 'function') {
result = value.apply(obj, args);
} else {
result = value;
}
resolve(result);
} catch (e) {
if (!(e instanceof MissingDataException)) {
reject(e);
return;
}
pdfManager.streamManager.requestRange(e.begin, e.end).
then(ensureHelper, reject);
}
}
ensureHelper();
});
},
requestRange: function NetworkPdfManager_requestRange(begin, end) {
return this.streamManager.requestRange(begin, end);
},
requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
this.streamManager.requestAllChunks();
},
sendProgressiveData:
function NetworkPdfManager_sendProgressiveData(chunk) {
this.streamManager.onReceiveData({ chunk: chunk });
},
onLoadedStream: function NetworkPdfManager_onLoadedStream() {
return this.streamManager.onLoadedStream();
},
terminate: function NetworkPdfManager_terminate() {
this.streamManager.abort();
}
});
return NetworkPdfManager;
})();
exports.LocalPdfManager = LocalPdfManager;
exports.NetworkPdfManager = NetworkPdfManager;
}));