pdfjs-dist 2.5.207 → 2.6.347

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (133) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +867 -216
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +10214 -8547
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/es5/build/pdf.js +2023 -1046
  9. package/es5/build/pdf.js.map +1 -1
  10. package/es5/build/pdf.min.js +22 -0
  11. package/es5/build/pdf.worker.js +11136 -8144
  12. package/es5/build/pdf.worker.js.map +1 -1
  13. package/es5/build/pdf.worker.min.js +22 -0
  14. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  15. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  16. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  17. package/es5/web/images/shadow.png +0 -0
  18. package/es5/web/pdf_viewer.css +8 -5
  19. package/es5/web/pdf_viewer.js +195 -51
  20. package/es5/web/pdf_viewer.js.map +1 -1
  21. package/image_decoders/pdf.image_decoders.js +24 -16
  22. package/image_decoders/pdf.image_decoders.js.map +1 -1
  23. package/image_decoders/pdf.image_decoders.min.js +1 -1
  24. package/lib/core/annotation.js +479 -43
  25. package/lib/core/cff_parser.js +643 -615
  26. package/lib/core/chunked_stream.js +64 -50
  27. package/lib/core/colorspace.js +126 -104
  28. package/lib/core/crypto.js +37 -0
  29. package/lib/core/document.js +128 -75
  30. package/lib/core/evaluator.js +3015 -2754
  31. package/lib/core/fonts.js +47 -46
  32. package/lib/core/function.js +79 -6
  33. package/lib/core/image.js +364 -357
  34. package/lib/core/image_utils.js +109 -8
  35. package/lib/core/jpg.js +8 -3
  36. package/lib/core/obj.js +255 -34
  37. package/lib/core/operator_list.js +17 -15
  38. package/lib/core/parser.js +40 -3
  39. package/lib/core/pattern.js +24 -11
  40. package/lib/core/primitives.js +112 -53
  41. package/lib/core/type1_parser.js +2 -0
  42. package/lib/core/worker.js +102 -37
  43. package/lib/core/writer.js +242 -0
  44. package/lib/display/annotation_layer.js +51 -10
  45. package/lib/display/annotation_storage.js +89 -0
  46. package/lib/display/api.js +140 -54
  47. package/lib/display/canvas.js +215 -46
  48. package/lib/display/display_utils.js +55 -18
  49. package/lib/display/fetch_stream.js +6 -0
  50. package/lib/display/font_loader.js +26 -15
  51. package/lib/display/metadata.js +1 -7
  52. package/lib/display/network.js +0 -14
  53. package/lib/display/node_utils.js +87 -0
  54. package/lib/display/optional_content_config.js +184 -0
  55. package/lib/display/svg.js +1 -1
  56. package/lib/display/text_layer.js +4 -1
  57. package/lib/pdf.js +2 -2
  58. package/lib/pdf.worker.js +2 -2
  59. package/lib/shared/is_node.js +1 -1
  60. package/lib/shared/util.js +13 -10
  61. package/lib/test/unit/annotation_spec.js +520 -50
  62. package/lib/test/unit/annotation_storage_spec.js +83 -0
  63. package/lib/test/unit/api_spec.js +16 -6
  64. package/lib/test/unit/cmap_spec.js +4 -4
  65. package/lib/test/unit/colorspace_spec.js +216 -24
  66. package/lib/test/unit/crypto_spec.js +51 -4
  67. package/lib/test/unit/custom_spec.js +129 -1
  68. package/lib/test/unit/document_spec.js +112 -1
  69. package/lib/test/unit/evaluator_spec.js +29 -10
  70. package/lib/test/unit/jasmine-boot.js +1 -1
  71. package/lib/test/unit/metadata_spec.js +3 -3
  72. package/lib/test/unit/primitives_spec.js +242 -63
  73. package/lib/test/unit/test_utils.js +42 -89
  74. package/lib/test/unit/testreporter.js +17 -6
  75. package/lib/test/unit/util_spec.js +13 -12
  76. package/lib/test/unit/writer_spec.js +84 -0
  77. package/lib/web/annotation_layer_builder.js +13 -9
  78. package/lib/web/app.js +231 -26
  79. package/lib/web/app_options.js +1 -6
  80. package/lib/web/base_tree_viewer.js +100 -0
  81. package/lib/web/base_viewer.js +53 -4
  82. package/lib/web/download_manager.js +3 -10
  83. package/lib/web/firefox_print_service.js +32 -12
  84. package/lib/web/firefoxcom.js +20 -6
  85. package/lib/web/interfaces.js +1 -1
  86. package/lib/web/pdf_attachment_viewer.js +80 -38
  87. package/lib/web/pdf_find_controller.js +2 -1
  88. package/lib/web/pdf_layer_viewer.js +208 -0
  89. package/lib/web/pdf_outline_viewer.js +24 -57
  90. package/lib/web/pdf_page_view.js +29 -6
  91. package/lib/web/pdf_print_service.js +13 -11
  92. package/lib/web/pdf_sidebar.js +46 -25
  93. package/lib/web/pdf_thumbnail_view.js +16 -3
  94. package/lib/web/pdf_thumbnail_viewer.js +17 -1
  95. package/lib/web/pdf_viewer.component.js +2 -2
  96. package/lib/web/preferences.js +1 -1
  97. package/lib/web/toolbar.js +1 -1
  98. package/lib/web/ui_utils.js +7 -1
  99. package/package.json +3 -1
  100. package/types/display/annotation_layer.d.ts +61 -0
  101. package/types/display/annotation_storage.d.ts +36 -0
  102. package/types/display/api.d.ts +1107 -0
  103. package/types/display/api_compatibility.d.ts +1 -0
  104. package/types/display/canvas.d.ts +4 -0
  105. package/types/display/content_disposition.d.ts +7 -0
  106. package/types/display/display_utils.d.ts +243 -0
  107. package/types/display/fetch_stream.d.ts +67 -0
  108. package/types/display/font_loader.d.ts +19 -0
  109. package/types/display/metadata.d.ts +9 -0
  110. package/types/display/network.d.ts +80 -0
  111. package/types/display/network_utils.d.ts +14 -0
  112. package/types/display/node_stream.d.ts +72 -0
  113. package/types/display/node_utils.d.ts +6 -0
  114. package/types/display/optional_content_config.d.ts +12 -0
  115. package/types/display/pattern_helper.d.ts +5 -0
  116. package/types/display/svg.d.ts +2 -0
  117. package/types/display/text_layer.d.ts +83 -0
  118. package/types/display/transport_stream.d.ts +57 -0
  119. package/types/display/webgl.d.ts +20 -0
  120. package/types/display/worker_options.d.ts +27 -0
  121. package/types/display/xml_parser.d.ts +35 -0
  122. package/types/pdf.d.ts +33 -0
  123. package/types/shared/compatibility.d.ts +1 -0
  124. package/types/shared/is_node.d.ts +1 -0
  125. package/types/shared/message_handler.d.ts +62 -0
  126. package/types/shared/util.d.ts +421 -0
  127. package/web/images/shadow.png +0 -0
  128. package/web/pdf_viewer.css +8 -5
  129. package/web/pdf_viewer.js +109 -33
  130. package/web/pdf_viewer.js.map +1 -1
  131. package/webpack.js +1 -9
  132. package/es5/web/images/texture.png +0 -0
  133. package/web/images/texture.png +0 -0
@@ -83,6 +83,7 @@ var ARCFourCipher = function ARCFourCipherClosure() {
83
83
  }
84
84
  };
85
85
  ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
86
+ ARCFourCipher.prototype.encrypt = ARCFourCipher.prototype.encryptBlock;
86
87
  return ARCFourCipher;
87
88
  }();
88
89
 
@@ -622,6 +623,9 @@ var NullCipher = function NullCipherClosure() {
622
623
  NullCipher.prototype = {
623
624
  decryptBlock: function NullCipher_decryptBlock(data) {
624
625
  return data;
626
+ },
627
+ encrypt: function NullCipher_encrypt(data) {
628
+ return data;
625
629
  }
626
630
  };
627
631
  return NullCipher;
@@ -1235,6 +1239,39 @@ var CipherTransform = function CipherTransformClosure() {
1235
1239
  var data = (0, _util.stringToBytes)(s);
1236
1240
  data = cipher.decryptBlock(data, true);
1237
1241
  return (0, _util.bytesToString)(data);
1242
+ },
1243
+ encryptString: function CipherTransform_encryptString(s) {
1244
+ const cipher = new this.StringCipherConstructor();
1245
+
1246
+ if (cipher instanceof AESBaseCipher) {
1247
+ const strLen = s.length;
1248
+ const pad = 16 - strLen % 16;
1249
+
1250
+ if (pad !== 16) {
1251
+ s = s.padEnd(16 * Math.ceil(strLen / 16), String.fromCharCode(pad));
1252
+ }
1253
+
1254
+ const iv = new Uint8Array(16);
1255
+
1256
+ if (typeof crypto !== "undefined") {
1257
+ crypto.getRandomValues(iv);
1258
+ } else {
1259
+ for (let i = 0; i < 16; i++) {
1260
+ iv[i] = Math.floor(256 * Math.random());
1261
+ }
1262
+ }
1263
+
1264
+ let data = (0, _util.stringToBytes)(s);
1265
+ data = cipher.encrypt(data, iv);
1266
+ const buf = new Uint8Array(16 + data.length);
1267
+ buf.set(iv);
1268
+ buf.set(data, 16);
1269
+ return (0, _util.bytesToString)(buf);
1270
+ }
1271
+
1272
+ let data = (0, _util.stringToBytes)(s);
1273
+ data = cipher.encrypt(data);
1274
+ return (0, _util.bytesToString)(data);
1238
1275
  }
1239
1276
  };
1240
1277
  return CipherTransform;
@@ -46,8 +46,6 @@ var _operator_list = require("./operator_list.js");
46
46
 
47
47
  var _evaluator = require("./evaluator.js");
48
48
 
49
- var _function = require("./function.js");
50
-
51
49
  const DEFAULT_USER_UNIT = 1.0;
52
50
  const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
53
51
 
@@ -62,10 +60,10 @@ class Page {
62
60
  pageIndex,
63
61
  pageDict,
64
62
  ref,
63
+ globalIdFactory,
65
64
  fontCache,
66
65
  builtInCMapCache,
67
- globalImageCache,
68
- pdfFunctionFactory
66
+ globalImageCache
69
67
  }) {
70
68
  this.pdfManager = pdfManager;
71
69
  this.pageIndex = pageIndex;
@@ -75,19 +73,14 @@ class Page {
75
73
  this.fontCache = fontCache;
76
74
  this.builtInCMapCache = builtInCMapCache;
77
75
  this.globalImageCache = globalImageCache;
78
- this.pdfFunctionFactory = pdfFunctionFactory;
79
76
  this.evaluatorOptions = pdfManager.evaluatorOptions;
80
77
  this.resourcesPromise = null;
81
78
  const idCounters = {
82
79
  obj: 0
83
80
  };
84
- this.idFactory = {
85
- createObjId() {
81
+ this._localIdFactory = class extends globalIdFactory {
82
+ static createObjId() {
86
83
  return `p${pageIndex}_${++idCounters.obj}`;
87
- },
88
-
89
- getDocId() {
90
- return `g_${pdfManager.docId}`;
91
84
  }
92
85
 
93
86
  };
@@ -109,7 +102,10 @@ class Page {
109
102
  return value[0];
110
103
  }
111
104
 
112
- return _primitives.Dict.merge(this.xref, value);
105
+ return _primitives.Dict.merge({
106
+ xref: this.xref,
107
+ dictArray: value
108
+ });
113
109
  }
114
110
 
115
111
  get content() {
@@ -210,6 +206,35 @@ class Page {
210
206
  return stream;
211
207
  }
212
208
 
209
+ save(handler, task, annotationStorage) {
210
+ const partialEvaluator = new _evaluator.PartialEvaluator({
211
+ xref: this.xref,
212
+ handler,
213
+ pageIndex: this.pageIndex,
214
+ idFactory: this._localIdFactory,
215
+ fontCache: this.fontCache,
216
+ builtInCMapCache: this.builtInCMapCache,
217
+ globalImageCache: this.globalImageCache,
218
+ options: this.evaluatorOptions
219
+ });
220
+ return this._parsedAnnotations.then(function (annotations) {
221
+ const newRefsPromises = [];
222
+
223
+ for (const annotation of annotations) {
224
+ if (!isAnnotationRenderable(annotation, "print")) {
225
+ continue;
226
+ }
227
+
228
+ newRefsPromises.push(annotation.save(partialEvaluator, task, annotationStorage).catch(function (reason) {
229
+ (0, _util.warn)("save - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
230
+ return null;
231
+ }));
232
+ }
233
+
234
+ return Promise.all(newRefsPromises);
235
+ });
236
+ }
237
+
213
238
  loadResources(keys) {
214
239
  if (!this.resourcesPromise) {
215
240
  this.resourcesPromise = this.pdfManager.ensure(this, "resources");
@@ -226,7 +251,8 @@ class Page {
226
251
  sink,
227
252
  task,
228
253
  intent,
229
- renderInteractiveForms
254
+ renderInteractiveForms,
255
+ annotationStorage
230
256
  }) {
231
257
  const contentStreamPromise = this.pdfManager.ensure(this, "getContentStream");
232
258
  const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
@@ -234,16 +260,15 @@ class Page {
234
260
  xref: this.xref,
235
261
  handler,
236
262
  pageIndex: this.pageIndex,
237
- idFactory: this.idFactory,
263
+ idFactory: this._localIdFactory,
238
264
  fontCache: this.fontCache,
239
265
  builtInCMapCache: this.builtInCMapCache,
240
266
  globalImageCache: this.globalImageCache,
241
- options: this.evaluatorOptions,
242
- pdfFunctionFactory: this.pdfFunctionFactory
267
+ options: this.evaluatorOptions
243
268
  });
244
269
  const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
245
270
  const pageListPromise = dataPromises.then(([contentStream]) => {
246
- const opList = new _operator_list.OperatorList(intent, sink, this.pageIndex);
271
+ const opList = new _operator_list.OperatorList(intent, sink);
247
272
  handler.send("StartRenderPage", {
248
273
  transparency: partialEvaluator.hasBlendModes(this.resources),
249
274
  pageIndex: this.pageIndex,
@@ -270,7 +295,7 @@ class Page {
270
295
 
271
296
  for (const annotation of annotations) {
272
297
  if (isAnnotationRenderable(annotation, intent)) {
273
- opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms).catch(function (reason) {
298
+ opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms, annotationStorage).catch(function (reason) {
274
299
  (0, _util.warn)("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
275
300
  return null;
276
301
  }));
@@ -308,12 +333,11 @@ class Page {
308
333
  xref: this.xref,
309
334
  handler,
310
335
  pageIndex: this.pageIndex,
311
- idFactory: this.idFactory,
336
+ idFactory: this._localIdFactory,
312
337
  fontCache: this.fontCache,
313
338
  builtInCMapCache: this.builtInCMapCache,
314
339
  globalImageCache: this.globalImageCache,
315
- options: this.evaluatorOptions,
316
- pdfFunctionFactory: this.pdfFunctionFactory
340
+ options: this.evaluatorOptions
317
341
  });
318
342
  return partialEvaluator.getTextContent({
319
343
  stream: contentStream,
@@ -349,7 +373,7 @@ class Page {
349
373
  const annotationPromises = [];
350
374
 
351
375
  for (const annotationRef of this.annotations) {
352
- annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRef, this.pdfManager, this.idFactory).catch(function (reason) {
376
+ annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRef, this.pdfManager, this._localIdFactory).catch(function (reason) {
353
377
  (0, _util.warn)(`_parsedAnnotations: "${reason}".`);
354
378
  return null;
355
379
  }));
@@ -440,53 +464,33 @@ class PDFDocument {
440
464
  this.pdfManager = pdfManager;
441
465
  this.stream = stream;
442
466
  this.xref = new _obj.XRef(stream, pdfManager);
443
- this.pdfFunctionFactory = new _function.PDFFunctionFactory({
444
- xref: this.xref,
445
- isEvalSupported: pdfManager.evaluatorOptions.isEvalSupported
446
- });
447
467
  this._pagePromises = [];
448
- }
449
-
450
- parse(recoveryMode) {
451
- this.setup(recoveryMode);
452
- const version = this.catalog.catDict.get("Version");
453
-
454
- if ((0, _primitives.isName)(version)) {
455
- this.pdfFormatVersion = version.name;
456
- }
457
-
458
- try {
459
- this.acroForm = this.catalog.catDict.get("AcroForm");
460
-
461
- if (this.acroForm) {
462
- this.xfa = this.acroForm.get("XFA");
463
- const fields = this.acroForm.get("Fields");
464
-
465
- if ((!Array.isArray(fields) || fields.length === 0) && !this.xfa) {
466
- this.acroForm = null;
467
- }
468
+ this._version = null;
469
+ const idCounters = {
470
+ font: 0
471
+ };
472
+ this._globalIdFactory = class {
473
+ static getDocId() {
474
+ return `g_${pdfManager.docId}`;
468
475
  }
469
- } catch (ex) {
470
- if (ex instanceof _core_utils.MissingDataException) {
471
- throw ex;
476
+
477
+ static createFontId() {
478
+ return `f${++idCounters.font}`;
472
479
  }
473
480
 
474
- (0, _util.info)("Cannot fetch AcroForm entry; assuming no AcroForms are present");
475
- this.acroForm = null;
476
- }
481
+ static createObjId() {
482
+ (0, _util.unreachable)("Abstract method `createObjId` called.");
483
+ }
477
484
 
478
- try {
479
- const collection = this.catalog.catDict.get("Collection");
485
+ };
486
+ }
480
487
 
481
- if ((0, _primitives.isDict)(collection) && collection.getKeys().length > 0) {
482
- this.collection = collection;
483
- }
484
- } catch (ex) {
485
- if (ex instanceof _core_utils.MissingDataException) {
486
- throw ex;
487
- }
488
+ parse(recoveryMode) {
489
+ this.xref.parse(recoveryMode);
490
+ this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
488
491
 
489
- (0, _util.info)("Cannot fetch Collection dictionary.");
492
+ if (this.catalog.version) {
493
+ this._version = this.catalog.version;
490
494
  }
491
495
  }
492
496
 
@@ -580,8 +584,8 @@ class PDFDocument {
580
584
  version += String.fromCharCode(ch);
581
585
  }
582
586
 
583
- if (!this.pdfFormatVersion) {
584
- this.pdfFormatVersion = version.substring(5);
587
+ if (!this._version) {
588
+ this._version = version.substring(5);
585
589
  }
586
590
  }
587
591
 
@@ -589,17 +593,66 @@ class PDFDocument {
589
593
  this.xref.setStartXRef(this.startXRef);
590
594
  }
591
595
 
592
- setup(recoveryMode) {
593
- this.xref.parse(recoveryMode);
594
- this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
595
- }
596
-
597
596
  get numPages() {
598
597
  const linearization = this.linearization;
599
598
  const num = linearization ? linearization.numPages : this.catalog.numPages;
600
599
  return (0, _util.shadow)(this, "numPages", num);
601
600
  }
602
601
 
602
+ _hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
603
+ const RECURSION_LIMIT = 10;
604
+ return fields.every(field => {
605
+ field = this.xref.fetchIfRef(field);
606
+
607
+ if (field.has("Kids")) {
608
+ if (++recursionDepth > RECURSION_LIMIT) {
609
+ (0, _util.warn)("_hasOnlyDocumentSignatures: maximum recursion depth reached");
610
+ return false;
611
+ }
612
+
613
+ return this._hasOnlyDocumentSignatures(field.get("Kids"), recursionDepth);
614
+ }
615
+
616
+ const isSignature = (0, _primitives.isName)(field.get("FT"), "Sig");
617
+ const rectangle = field.get("Rect");
618
+ const isInvisible = Array.isArray(rectangle) && rectangle.every(value => value === 0);
619
+ return isSignature && isInvisible;
620
+ });
621
+ }
622
+
623
+ get formInfo() {
624
+ const formInfo = {
625
+ hasAcroForm: false,
626
+ hasXfa: false
627
+ };
628
+ const acroForm = this.catalog.acroForm;
629
+
630
+ if (!acroForm) {
631
+ return (0, _util.shadow)(this, "formInfo", formInfo);
632
+ }
633
+
634
+ try {
635
+ const xfa = acroForm.get("XFA");
636
+ const hasXfa = Array.isArray(xfa) && xfa.length > 0 || (0, _primitives.isStream)(xfa) && !xfa.isEmpty;
637
+ formInfo.hasXfa = hasXfa;
638
+ const fields = acroForm.get("Fields");
639
+ const hasFields = Array.isArray(fields) && fields.length > 0;
640
+ const sigFlags = acroForm.get("SigFlags");
641
+
642
+ const hasOnlyDocumentSignatures = !!(sigFlags & 0x1) && this._hasOnlyDocumentSignatures(fields);
643
+
644
+ formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures;
645
+ } catch (ex) {
646
+ if (ex instanceof _core_utils.MissingDataException) {
647
+ throw ex;
648
+ }
649
+
650
+ (0, _util.info)("Cannot fetch form information.");
651
+ }
652
+
653
+ return (0, _util.shadow)(this, "formInfo", formInfo);
654
+ }
655
+
603
656
  get documentInfo() {
604
657
  const DocumentInfoValidators = {
605
658
  Title: _util.isString,
@@ -612,7 +665,7 @@ class PDFDocument {
612
665
  ModDate: _util.isString,
613
666
  Trapped: _primitives.isName
614
667
  };
615
- let version = this.pdfFormatVersion;
668
+ let version = this._version;
616
669
 
617
670
  if (typeof version !== "string" || !PDF_HEADER_VERSION_REGEXP.test(version)) {
618
671
  (0, _util.warn)(`Invalid PDF header version number: ${version}`);
@@ -622,9 +675,9 @@ class PDFDocument {
622
675
  const docInfo = {
623
676
  PDFFormatVersion: version,
624
677
  IsLinearized: !!this.linearization,
625
- IsAcroFormPresent: !!this.acroForm,
626
- IsXFAPresent: !!this.xfa,
627
- IsCollectionPresent: !!this.collection
678
+ IsAcroFormPresent: this.formInfo.hasAcroForm,
679
+ IsXFAPresent: this.formInfo.hasXfa,
680
+ IsCollectionPresent: !!this.catalog.collection
628
681
  };
629
682
  let infoDict;
630
683
 
@@ -733,10 +786,10 @@ class PDFDocument {
733
786
  pageIndex,
734
787
  pageDict,
735
788
  ref,
789
+ globalIdFactory: this._globalIdFactory,
736
790
  fontCache: catalog.fontCache,
737
791
  builtInCMapCache: catalog.builtInCMapCache,
738
- globalImageCache: catalog.globalImageCache,
739
- pdfFunctionFactory: this.pdfFunctionFactory
792
+ globalImageCache: catalog.globalImageCache
740
793
  });
741
794
  });
742
795
  }