pdfjs-dist 2.4.456 → 2.5.207

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 (101) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +4447 -4379
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +8549 -8507
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/es5/build/pdf.js +14755 -14540
  9. package/es5/build/pdf.js.map +1 -1
  10. package/es5/build/pdf.worker.js +9830 -9469
  11. package/es5/build/pdf.worker.js.map +1 -1
  12. package/es5/web/pdf_viewer.css +5 -9
  13. package/es5/web/pdf_viewer.js +157 -172
  14. package/es5/web/pdf_viewer.js.map +1 -1
  15. package/image_decoders/pdf.image_decoders.js +107 -93
  16. package/image_decoders/pdf.image_decoders.js.map +1 -1
  17. package/image_decoders/pdf.image_decoders.min.js +1 -1
  18. package/lib/README.md +2 -2
  19. package/lib/core/ccitt.js +7 -7
  20. package/lib/core/cff_parser.js +1 -1
  21. package/lib/core/chunked_stream.js +5 -5
  22. package/lib/core/cmap.js +13 -0
  23. package/lib/core/document.js +22 -18
  24. package/lib/core/evaluator.js +285 -247
  25. package/lib/core/font_renderer.js +7 -7
  26. package/lib/core/fonts.js +163 -147
  27. package/lib/core/function.js +4 -5
  28. package/lib/core/glyphlist.js +4523 -4523
  29. package/lib/core/image.js +19 -44
  30. package/lib/core/image_utils.js +123 -47
  31. package/lib/core/jpeg_stream.js +2 -116
  32. package/lib/core/jpg.js +47 -55
  33. package/lib/core/jpx.js +6 -6
  34. package/lib/core/metrics.js +2916 -2916
  35. package/lib/core/obj.js +18 -7
  36. package/lib/core/operator_list.js +5 -0
  37. package/lib/core/parser.js +1 -1
  38. package/lib/core/pdf_manager.js +2 -2
  39. package/lib/core/primitives.js +4 -0
  40. package/lib/core/standard_fonts.js +103 -103
  41. package/lib/core/type1_parser.js +6 -6
  42. package/lib/core/worker.js +31 -24
  43. package/lib/core/worker_stream.js +1 -1
  44. package/lib/display/annotation_layer.js +3 -0
  45. package/lib/display/api.js +29 -137
  46. package/lib/display/api_compatibility.js +11 -18
  47. package/lib/display/canvas.js +7 -34
  48. package/lib/display/content_disposition.js +4 -4
  49. package/lib/display/display_utils.js +6 -15
  50. package/lib/display/fetch_stream.js +3 -1
  51. package/lib/display/font_loader.js +2 -2
  52. package/lib/display/network.js +1 -1
  53. package/lib/display/node_stream.js +10 -8
  54. package/lib/display/pattern_helper.js +1 -1
  55. package/lib/display/svg.js +61 -31
  56. package/lib/display/text_layer.js +44 -32
  57. package/lib/display/transport_stream.js +3 -3
  58. package/lib/pdf.js +210 -48
  59. package/lib/pdf.worker.js +12 -4
  60. package/lib/shared/compatibility.js +2 -0
  61. package/lib/shared/is_node.js +1 -1
  62. package/lib/shared/message_handler.js +6 -6
  63. package/lib/shared/util.js +15 -9
  64. package/lib/test/unit/api_spec.js +165 -95
  65. package/lib/test/unit/cff_parser_spec.js +12 -12
  66. package/lib/test/unit/clitests_helper.js +1 -1
  67. package/lib/test/unit/display_svg_spec.js +1 -5
  68. package/lib/test/unit/jasmine-boot.js +2 -2
  69. package/lib/test/unit/node_stream_spec.js +5 -3
  70. package/lib/test/unit/parser_spec.js +3 -3
  71. package/lib/test/unit/test_utils.js +1 -1
  72. package/lib/test/unit/testreporter.js +4 -4
  73. package/lib/test/unit/ui_utils_spec.js +1 -55
  74. package/lib/test/unit/unicode_spec.js +1 -1
  75. package/lib/web/app.js +247 -159
  76. package/lib/web/app_options.js +16 -10
  77. package/lib/web/base_viewer.js +14 -6
  78. package/lib/web/download_manager.js +3 -1
  79. package/lib/web/firefox_print_service.js +1 -1
  80. package/lib/web/firefoxcom.js +16 -4
  81. package/lib/web/pdf_attachment_viewer.js +14 -7
  82. package/lib/web/pdf_document_properties.js +11 -16
  83. package/lib/web/pdf_find_bar.js +3 -3
  84. package/lib/web/pdf_find_controller.js +3 -3
  85. package/lib/web/pdf_history.js +7 -5
  86. package/lib/web/pdf_link_service.js +7 -8
  87. package/lib/web/pdf_page_view.js +1 -1
  88. package/lib/web/pdf_presentation_mode.js +6 -2
  89. package/lib/web/pdf_print_service.js +1 -1
  90. package/lib/web/pdf_single_page_viewer.js +2 -2
  91. package/lib/web/pdf_viewer.component.js +2 -2
  92. package/lib/web/pdf_viewer.js +2 -2
  93. package/lib/web/preferences.js +4 -1
  94. package/lib/web/text_layer_builder.js +1 -3
  95. package/lib/web/ui_utils.js +3 -55
  96. package/lib/web/view_history.js +8 -9
  97. package/lib/web/viewer_compatibility.js +14 -1
  98. package/package.json +1 -1
  99. package/web/pdf_viewer.css +5 -9
  100. package/web/pdf_viewer.js +97 -127
  101. package/web/pdf_viewer.js.map +1 -1
@@ -49,7 +49,7 @@ exports.stringToUTF8String = stringToUTF8String;
49
49
  exports.utf8StringToString = utf8StringToString;
50
50
  exports.warn = warn;
51
51
  exports.unreachable = unreachable;
52
- exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
52
+ exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
53
53
 
54
54
  require("./compatibility.js");
55
55
 
@@ -57,12 +57,6 @@ const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
57
57
  exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
58
58
  const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
59
59
  exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
60
- const NativeImageDecoding = {
61
- NONE: "none",
62
- DECODE: "decode",
63
- DISPLAY: "display"
64
- };
65
- exports.NativeImageDecoding = NativeImageDecoding;
66
60
  const PermissionFlag = {
67
61
  PRINT: 0x04,
68
62
  MODIFY_CONTENTS: 0x08,
@@ -327,7 +321,19 @@ const UNSUPPORTED_FEATURES = {
327
321
  javaScript: "javaScript",
328
322
  smask: "smask",
329
323
  shadingPattern: "shadingPattern",
330
- font: "font"
324
+ font: "font",
325
+ errorTilingPattern: "errorTilingPattern",
326
+ errorExtGState: "errorExtGState",
327
+ errorXObject: "errorXObject",
328
+ errorFontLoadType3: "errorFontLoadType3",
329
+ errorFontState: "errorFontState",
330
+ errorFontMissing: "errorFontMissing",
331
+ errorFontTranslate: "errorFontTranslate",
332
+ errorColorSpace: "errorColorSpace",
333
+ errorOperatorList: "errorOperatorList",
334
+ errorFontToUnicode: "errorFontToUnicode",
335
+ errorFontLoadNative: "errorFontLoadNative",
336
+ errorFontGetPath: "errorFontGetPath"
331
337
  };
332
338
  exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
333
339
  const PasswordResponses = {
@@ -540,7 +546,7 @@ function arrayByteLength(arr) {
540
546
  return arr.length;
541
547
  }
542
548
 
543
- assert(arr.byteLength !== undefined);
549
+ assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
544
550
  return arr.byteLength;
545
551
  }
546
552
 
@@ -31,6 +31,8 @@ var _api = require("../../display/api.js");
31
31
 
32
32
  var _ui_utils = require("../../web/ui_utils.js");
33
33
 
34
+ var _image_utils = require("../../core/image_utils.js");
35
+
34
36
  var _worker_options = require("../../display/worker_options.js");
35
37
 
36
38
  var _is_node = require("../../shared/is_node.js");
@@ -374,26 +376,25 @@ describe("api", function () {
374
376
  });
375
377
  });
376
378
  describe("PDFDocument", function () {
377
- var loadingTask;
378
- var doc;
379
+ let pdfLoadingTask, pdfDocument;
379
380
  beforeAll(function (done) {
380
- loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
381
- loadingTask.promise.then(function (data) {
382
- doc = data;
381
+ pdfLoadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
382
+ pdfLoadingTask.promise.then(function (data) {
383
+ pdfDocument = data;
383
384
  done();
384
385
  });
385
386
  });
386
387
  afterAll(function (done) {
387
- loadingTask.destroy().then(done);
388
+ pdfLoadingTask.destroy().then(done);
388
389
  });
389
390
  it("gets number of pages", function () {
390
- expect(doc.numPages).toEqual(3);
391
+ expect(pdfDocument.numPages).toEqual(3);
391
392
  });
392
393
  it("gets fingerprint", function () {
393
- expect(doc.fingerprint).toEqual("ea8b35919d6279a369e835bde778611b");
394
+ expect(pdfDocument.fingerprint).toEqual("ea8b35919d6279a369e835bde778611b");
394
395
  });
395
396
  it("gets page", function (done) {
396
- var promise = doc.getPage(1);
397
+ var promise = pdfDocument.getPage(1);
397
398
  promise.then(function (data) {
398
399
  expect(data instanceof _api.PDFPageProxy).toEqual(true);
399
400
  expect(data.pageNumber).toEqual(1);
@@ -401,9 +402,9 @@ describe("api", function () {
401
402
  }).catch(done.fail);
402
403
  });
403
404
  it("gets non-existent page", function (done) {
404
- var outOfRangePromise = doc.getPage(100);
405
- var nonIntegerPromise = doc.getPage(2.5);
406
- var nonNumberPromise = doc.getPage("1");
405
+ var outOfRangePromise = pdfDocument.getPage(100);
406
+ var nonIntegerPromise = pdfDocument.getPage(2.5);
407
+ var nonNumberPromise = pdfDocument.getPage("1");
407
408
  outOfRangePromise = outOfRangePromise.then(function () {
408
409
  throw new Error("shall fail for out-of-range pageNumber parameter");
409
410
  }, function (reason) {
@@ -453,7 +454,7 @@ describe("api", function () {
453
454
  num: 17,
454
455
  gen: 0
455
456
  };
456
- var promise = doc.getPageIndex(ref);
457
+ var promise = pdfDocument.getPageIndex(ref);
457
458
  promise.then(function (pageIndex) {
458
459
  expect(pageIndex).toEqual(1);
459
460
  done();
@@ -464,7 +465,7 @@ describe("api", function () {
464
465
  num: 3,
465
466
  gen: 0
466
467
  };
467
- var promise = doc.getPageIndex(ref);
468
+ var promise = pdfDocument.getPageIndex(ref);
468
469
  promise.then(function () {
469
470
  done.fail("shall fail for invalid page reference.");
470
471
  }).catch(function (reason) {
@@ -473,7 +474,7 @@ describe("api", function () {
473
474
  });
474
475
  });
475
476
  it("gets destinations, from /Dests dictionary", function (done) {
476
- var promise = doc.getDestinations();
477
+ var promise = pdfDocument.getDestinations();
477
478
  promise.then(function (data) {
478
479
  expect(data).toEqual({
479
480
  chapter1: [{
@@ -487,7 +488,7 @@ describe("api", function () {
487
488
  }).catch(done.fail);
488
489
  });
489
490
  it("gets a destination, from /Dests dictionary", function (done) {
490
- var promise = doc.getDestination("chapter1");
491
+ var promise = pdfDocument.getDestination("chapter1");
491
492
  promise.then(function (data) {
492
493
  expect(data).toEqual([{
493
494
  gen: 0,
@@ -499,7 +500,7 @@ describe("api", function () {
499
500
  }).catch(done.fail);
500
501
  });
501
502
  it("gets a non-existent destination, from /Dests dictionary", function (done) {
502
- var promise = doc.getDestination("non-existent-named-destination");
503
+ var promise = pdfDocument.getDestination("non-existent-named-destination");
503
504
  promise.then(function (data) {
504
505
  expect(data).toEqual(null);
505
506
  done();
@@ -507,8 +508,8 @@ describe("api", function () {
507
508
  });
508
509
  it("gets destinations, from /Names (NameTree) dictionary", function (done) {
509
510
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
510
- var promise = loadingTask.promise.then(function (pdfDocument) {
511
- return pdfDocument.getDestinations();
511
+ var promise = loadingTask.promise.then(function (pdfDoc) {
512
+ return pdfDoc.getDestinations();
512
513
  });
513
514
  promise.then(function (destinations) {
514
515
  expect(destinations).toEqual({
@@ -530,8 +531,8 @@ describe("api", function () {
530
531
  });
531
532
  it("gets a destination, from /Names (NameTree) dictionary", function (done) {
532
533
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
533
- var promise = loadingTask.promise.then(function (pdfDocument) {
534
- return pdfDocument.getDestination("Page.1");
534
+ var promise = loadingTask.promise.then(function (pdfDoc) {
535
+ return pdfDoc.getDestination("Page.1");
535
536
  });
536
537
  promise.then(function (destination) {
537
538
  expect(destination).toEqual([{
@@ -545,8 +546,8 @@ describe("api", function () {
545
546
  });
546
547
  it("gets a non-existent destination, from /Names (NameTree) dictionary", function (done) {
547
548
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
548
- var promise = loadingTask.promise.then(function (pdfDocument) {
549
- return pdfDocument.getDestination("non-existent-named-destination");
549
+ var promise = loadingTask.promise.then(function (pdfDoc) {
550
+ return pdfDoc.getDestination("non-existent-named-destination");
550
551
  });
551
552
  promise.then(function (destination) {
552
553
  expect(destination).toEqual(null);
@@ -554,9 +555,9 @@ describe("api", function () {
554
555
  }).catch(done.fail);
555
556
  });
556
557
  it("gets non-string destination", function (done) {
557
- let numberPromise = doc.getDestination(4.3);
558
- let booleanPromise = doc.getDestination(true);
559
- let arrayPromise = doc.getDestination([{
558
+ let numberPromise = pdfDocument.getDestination(4.3);
559
+ let booleanPromise = pdfDocument.getDestination(true);
560
+ let arrayPromise = pdfDocument.getDestination([{
560
561
  num: 17,
561
562
  gen: 0
562
563
  }, {
@@ -580,7 +581,7 @@ describe("api", function () {
580
581
  Promise.all([numberPromise, booleanPromise, arrayPromise]).then(done, done.fail);
581
582
  });
582
583
  it("gets non-existent page labels", function (done) {
583
- var promise = doc.getPageLabels();
584
+ var promise = pdfDocument.getPageLabels();
584
585
  promise.then(function (data) {
585
586
  expect(data).toEqual(null);
586
587
  done();
@@ -613,45 +614,45 @@ describe("api", function () {
613
614
  });
614
615
  it("gets default page layout", function (done) {
615
616
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
616
- loadingTask.promise.then(function (pdfDocument) {
617
- return pdfDocument.getPageLayout();
617
+ loadingTask.promise.then(function (pdfDoc) {
618
+ return pdfDoc.getPageLayout();
618
619
  }).then(function (mode) {
619
620
  expect(mode).toEqual("");
620
621
  loadingTask.destroy().then(done);
621
622
  }).catch(done.fail);
622
623
  });
623
624
  it("gets non-default page layout", function (done) {
624
- doc.getPageLayout().then(function (mode) {
625
+ pdfDocument.getPageLayout().then(function (mode) {
625
626
  expect(mode).toEqual("SinglePage");
626
627
  done();
627
628
  }).catch(done.fail);
628
629
  });
629
630
  it("gets default page mode", function (done) {
630
631
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
631
- loadingTask.promise.then(function (pdfDocument) {
632
- return pdfDocument.getPageMode();
632
+ loadingTask.promise.then(function (pdfDoc) {
633
+ return pdfDoc.getPageMode();
633
634
  }).then(function (mode) {
634
635
  expect(mode).toEqual("UseNone");
635
636
  loadingTask.destroy().then(done);
636
637
  }).catch(done.fail);
637
638
  });
638
639
  it("gets non-default page mode", function (done) {
639
- doc.getPageMode().then(function (mode) {
640
+ pdfDocument.getPageMode().then(function (mode) {
640
641
  expect(mode).toEqual("UseOutlines");
641
642
  done();
642
643
  }).catch(done.fail);
643
644
  });
644
645
  it("gets default viewer preferences", function (done) {
645
646
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
646
- loadingTask.promise.then(function (pdfDocument) {
647
- return pdfDocument.getViewerPreferences();
647
+ loadingTask.promise.then(function (pdfDoc) {
648
+ return pdfDoc.getViewerPreferences();
648
649
  }).then(function (prefs) {
649
- expect(typeof prefs === "object" && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
650
+ expect(prefs).toEqual(null);
650
651
  loadingTask.destroy().then(done);
651
652
  }).catch(done.fail);
652
653
  });
653
654
  it("gets non-default viewer preferences", function (done) {
654
- doc.getViewerPreferences().then(function (prefs) {
655
+ pdfDocument.getViewerPreferences().then(function (prefs) {
655
656
  expect(prefs).toEqual({
656
657
  Direction: "L2R"
657
658
  });
@@ -660,15 +661,15 @@ describe("api", function () {
660
661
  });
661
662
  it("gets default open action", function (done) {
662
663
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
663
- loadingTask.promise.then(function (pdfDocument) {
664
- return pdfDocument.getOpenAction();
664
+ loadingTask.promise.then(function (pdfDoc) {
665
+ return pdfDoc.getOpenAction();
665
666
  }).then(function (openAction) {
666
667
  expect(openAction).toEqual(null);
667
668
  loadingTask.destroy().then(done);
668
669
  }).catch(done.fail);
669
670
  });
670
671
  it("gets non-default open action (with destination)", function (done) {
671
- doc.getOpenAction().then(function (openAction) {
672
+ pdfDocument.getOpenAction().then(function (openAction) {
672
673
  expect(openAction.dest).toEqual([{
673
674
  num: 15,
674
675
  gen: 0
@@ -682,15 +683,15 @@ describe("api", function () {
682
683
  it("gets non-default open action (with Print action)", function (done) {
683
684
  const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1001080.pdf"));
684
685
  const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue11442_reduced.pdf"));
685
- const promise1 = loadingTask1.promise.then(function (pdfDocument) {
686
- return pdfDocument.getOpenAction();
686
+ const promise1 = loadingTask1.promise.then(function (pdfDoc) {
687
+ return pdfDoc.getOpenAction();
687
688
  }).then(function (openAction) {
688
689
  expect(openAction.dest).toBeUndefined();
689
690
  expect(openAction.action).toEqual("Print");
690
691
  return loadingTask1.destroy();
691
692
  });
692
- const promise2 = loadingTask2.promise.then(function (pdfDocument) {
693
- return pdfDocument.getOpenAction();
693
+ const promise2 = loadingTask2.promise.then(function (pdfDoc) {
694
+ return pdfDoc.getOpenAction();
694
695
  }).then(function (openAction) {
695
696
  expect(openAction.dest).toBeUndefined();
696
697
  expect(openAction.action).toEqual("Print");
@@ -699,7 +700,7 @@ describe("api", function () {
699
700
  Promise.all([promise1, promise2]).then(done, done.fail);
700
701
  });
701
702
  it("gets non-existent attachments", function (done) {
702
- var promise = doc.getAttachments();
703
+ var promise = pdfDocument.getAttachments();
703
704
  promise.then(function (data) {
704
705
  expect(data).toEqual(null);
705
706
  done();
@@ -718,7 +719,7 @@ describe("api", function () {
718
719
  }).catch(done.fail);
719
720
  });
720
721
  it("gets javascript", function (done) {
721
- var promise = doc.getJavaScript();
722
+ var promise = pdfDocument.getJavaScript();
722
723
  promise.then(function (data) {
723
724
  expect(data).toEqual(null);
724
725
  done();
@@ -726,8 +727,8 @@ describe("api", function () {
726
727
  });
727
728
  it("gets javascript with printing instructions (JS action)", function (done) {
728
729
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6106.pdf"));
729
- var promise = loadingTask.promise.then(function (doc) {
730
- return doc.getJavaScript();
730
+ var promise = loadingTask.promise.then(function (pdfDoc) {
731
+ return pdfDoc.getJavaScript();
731
732
  });
732
733
  promise.then(function (data) {
733
734
  expect(data).toEqual(["this.print({bUI:true,bSilent:false,bShrinkToFit:true});"]);
@@ -737,8 +738,8 @@ describe("api", function () {
737
738
  });
738
739
  it("gets non-existent outline", function (done) {
739
740
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
740
- var promise = loadingTask.promise.then(function (pdfDocument) {
741
- return pdfDocument.getOutline();
741
+ var promise = loadingTask.promise.then(function (pdfDoc) {
742
+ return pdfDoc.getOutline();
742
743
  });
743
744
  promise.then(function (outline) {
744
745
  expect(outline).toEqual(null);
@@ -746,7 +747,7 @@ describe("api", function () {
746
747
  }).catch(done.fail);
747
748
  });
748
749
  it("gets outline", function (done) {
749
- var promise = doc.getOutline();
750
+ var promise = pdfDocument.getOutline();
750
751
  promise.then(function (outline) {
751
752
  expect(Array.isArray(outline)).toEqual(true);
752
753
  expect(outline.length).toEqual(2);
@@ -766,8 +767,8 @@ describe("api", function () {
766
767
  });
767
768
  it("gets outline containing a url", function (done) {
768
769
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue3214.pdf"));
769
- loadingTask.promise.then(function (pdfDocument) {
770
- pdfDocument.getOutline().then(function (outline) {
770
+ loadingTask.promise.then(function (pdfDoc) {
771
+ pdfDoc.getOutline().then(function (outline) {
771
772
  expect(Array.isArray(outline)).toEqual(true);
772
773
  expect(outline.length).toEqual(5);
773
774
  var outlineItemTwo = outline[2];
@@ -785,23 +786,23 @@ describe("api", function () {
785
786
  }).catch(done.fail);
786
787
  });
787
788
  it("gets non-existent permissions", function (done) {
788
- doc.getPermissions().then(function (permissions) {
789
+ pdfDocument.getPermissions().then(function (permissions) {
789
790
  expect(permissions).toEqual(null);
790
791
  done();
791
792
  }).catch(done.fail);
792
793
  });
793
794
  it("gets permissions", function (done) {
794
795
  const loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-1.pdf"));
795
- const promise0 = loadingTask0.promise.then(function (pdfDocument) {
796
- return pdfDocument.getPermissions();
796
+ const promise0 = loadingTask0.promise.then(function (pdfDoc) {
797
+ return pdfDoc.getPermissions();
797
798
  });
798
799
  const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-2.pdf"));
799
- const promise1 = loadingTask1.promise.then(function (pdfDocument) {
800
- return pdfDocument.getPermissions();
800
+ const promise1 = loadingTask1.promise.then(function (pdfDoc) {
801
+ return pdfDoc.getPermissions();
801
802
  });
802
803
  const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-3.pdf"));
803
- const promise2 = loadingTask2.promise.then(function (pdfDocument) {
804
- return pdfDocument.getPermissions();
804
+ const promise2 = loadingTask2.promise.then(function (pdfDoc) {
805
+ return pdfDoc.getPermissions();
805
806
  });
806
807
  const totalPermissionCount = Object.keys(_util.PermissionFlag).length;
807
808
  Promise.all([promise0, promise1, promise2]).then(function (permissions) {
@@ -816,19 +817,19 @@ describe("api", function () {
816
817
  }).catch(done.fail);
817
818
  });
818
819
  it("gets metadata", function (done) {
819
- var promise = doc.getMetadata();
820
+ var promise = pdfDocument.getMetadata();
820
821
  promise.then(function ({
821
822
  info,
822
823
  metadata,
823
824
  contentDispositionFilename
824
825
  }) {
825
- expect(info["Title"]).toEqual("Basic API Test");
826
- expect(info["Custom"]).toEqual(undefined);
827
- expect(info["PDFFormatVersion"]).toEqual("1.7");
828
- expect(info["IsLinearized"]).toEqual(false);
829
- expect(info["IsAcroFormPresent"]).toEqual(false);
830
- expect(info["IsXFAPresent"]).toEqual(false);
831
- expect(info["IsCollectionPresent"]).toEqual(false);
826
+ expect(info.Title).toEqual("Basic API Test");
827
+ expect(info.Custom).toEqual(undefined);
828
+ expect(info.PDFFormatVersion).toEqual("1.7");
829
+ expect(info.IsLinearized).toEqual(false);
830
+ expect(info.IsAcroFormPresent).toEqual(false);
831
+ expect(info.IsXFAPresent).toEqual(false);
832
+ expect(info.IsCollectionPresent).toEqual(false);
832
833
  expect(metadata instanceof _metadata.Metadata).toEqual(true);
833
834
  expect(metadata.get("dc:title")).toEqual("Basic API Test");
834
835
  expect(contentDispositionFilename).toEqual(null);
@@ -837,24 +838,24 @@ describe("api", function () {
837
838
  });
838
839
  it("gets metadata, with custom info dict entries", function (done) {
839
840
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
840
- loadingTask.promise.then(function (pdfDocument) {
841
- return pdfDocument.getMetadata();
841
+ loadingTask.promise.then(function (pdfDoc) {
842
+ return pdfDoc.getMetadata();
842
843
  }).then(function ({
843
844
  info,
844
845
  metadata,
845
846
  contentDispositionFilename
846
847
  }) {
847
- expect(info["Creator"]).toEqual("TeX");
848
- expect(info["Producer"]).toEqual("pdfeTeX-1.21a");
849
- expect(info["CreationDate"]).toEqual("D:20090401163925-07'00'");
850
- const custom = info["Custom"];
848
+ expect(info.Creator).toEqual("TeX");
849
+ expect(info.Producer).toEqual("pdfeTeX-1.21a");
850
+ expect(info.CreationDate).toEqual("D:20090401163925-07'00'");
851
+ const custom = info.Custom;
851
852
  expect(typeof custom === "object" && custom !== null).toEqual(true);
852
853
  expect(custom["PTEX.Fullbanner"]).toEqual("This is pdfeTeX, " + "Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6");
853
- expect(info["PDFFormatVersion"]).toEqual("1.4");
854
- expect(info["IsLinearized"]).toEqual(false);
855
- expect(info["IsAcroFormPresent"]).toEqual(false);
856
- expect(info["IsXFAPresent"]).toEqual(false);
857
- expect(info["IsCollectionPresent"]).toEqual(false);
854
+ expect(info.PDFFormatVersion).toEqual("1.4");
855
+ expect(info.IsLinearized).toEqual(false);
856
+ expect(info.IsAcroFormPresent).toEqual(false);
857
+ expect(info.IsXFAPresent).toEqual(false);
858
+ expect(info.IsCollectionPresent).toEqual(false);
858
859
  expect(metadata).toEqual(null);
859
860
  expect(contentDispositionFilename).toEqual(null);
860
861
  loadingTask.destroy().then(done);
@@ -862,25 +863,25 @@ describe("api", function () {
862
863
  });
863
864
  it("gets metadata, with missing PDF header (bug 1606566)", function (done) {
864
865
  const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1606566.pdf"));
865
- loadingTask.promise.then(function (pdfDocument) {
866
- return pdfDocument.getMetadata();
866
+ loadingTask.promise.then(function (pdfDoc) {
867
+ return pdfDoc.getMetadata();
867
868
  }).then(function ({
868
869
  info,
869
870
  metadata,
870
871
  contentDispositionFilename
871
872
  }) {
872
- expect(info["PDFFormatVersion"]).toEqual(null);
873
- expect(info["IsLinearized"]).toEqual(false);
874
- expect(info["IsAcroFormPresent"]).toEqual(false);
875
- expect(info["IsXFAPresent"]).toEqual(false);
876
- expect(info["IsCollectionPresent"]).toEqual(false);
873
+ expect(info.PDFFormatVersion).toEqual(null);
874
+ expect(info.IsLinearized).toEqual(false);
875
+ expect(info.IsAcroFormPresent).toEqual(false);
876
+ expect(info.IsXFAPresent).toEqual(false);
877
+ expect(info.IsCollectionPresent).toEqual(false);
877
878
  expect(metadata).toEqual(null);
878
879
  expect(contentDispositionFilename).toEqual(null);
879
880
  loadingTask.destroy().then(done);
880
881
  }).catch(done.fail);
881
882
  });
882
883
  it("gets data", function (done) {
883
- var promise = doc.getData();
884
+ var promise = pdfDocument.getData();
884
885
  promise.then(function (data) {
885
886
  expect(data instanceof Uint8Array).toEqual(true);
886
887
  expect(data.length).toEqual(basicApiFileLength);
@@ -888,7 +889,7 @@ describe("api", function () {
888
889
  }).catch(done.fail);
889
890
  });
890
891
  it("gets download info", function (done) {
891
- var promise = doc.getDownloadInfo();
892
+ var promise = pdfDocument.getDownloadInfo();
892
893
  promise.then(function (data) {
893
894
  expect(data).toEqual({
894
895
  length: basicApiFileLength
@@ -897,7 +898,7 @@ describe("api", function () {
897
898
  }).catch(done.fail);
898
899
  });
899
900
  it("gets document stats", function (done) {
900
- var promise = doc.getStats();
901
+ var promise = pdfDocument.getStats();
901
902
  promise.then(function (stats) {
902
903
  expect(stats).toEqual({
903
904
  streamTypes: {},
@@ -907,7 +908,7 @@ describe("api", function () {
907
908
  }).catch(done.fail);
908
909
  });
909
910
  it("cleans up document resources", function (done) {
910
- const promise = doc.cleanup();
911
+ const promise = pdfDocument.cleanup();
911
912
  promise.then(function () {
912
913
  expect(true).toEqual(true);
913
914
  done();
@@ -1003,11 +1004,10 @@ describe("api", function () {
1003
1004
  });
1004
1005
  });
1005
1006
  describe("Page", function () {
1006
- var loadingTask;
1007
- var pdfDocument, page;
1007
+ let pdfLoadingTask, pdfDocument, page;
1008
1008
  beforeAll(function (done) {
1009
- loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
1010
- loadingTask.promise.then(function (doc) {
1009
+ pdfLoadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
1010
+ pdfLoadingTask.promise.then(function (doc) {
1011
1011
  pdfDocument = doc;
1012
1012
  pdfDocument.getPage(1).then(function (data) {
1013
1013
  page = data;
@@ -1016,7 +1016,7 @@ describe("api", function () {
1016
1016
  }).catch(done.fail);
1017
1017
  });
1018
1018
  afterAll(function (done) {
1019
- loadingTask.destroy().then(done);
1019
+ pdfLoadingTask.destroy().then(done);
1020
1020
  });
1021
1021
  it("gets page number", function () {
1022
1022
  expect(page.pageNumber).toEqual(1);
@@ -1097,6 +1097,14 @@ describe("api", function () {
1097
1097
  expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
1098
1098
  expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
1099
1099
  });
1100
+ it("gets viewport with invalid rotation", function () {
1101
+ expect(function () {
1102
+ page.getViewport({
1103
+ scale: 1,
1104
+ rotation: 45
1105
+ });
1106
+ }).toThrow(new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees."));
1107
+ });
1100
1108
  it("gets annotations", function (done) {
1101
1109
  var defaultPromise = page.getAnnotations().then(function (data) {
1102
1110
  expect(data.length).toEqual(4);
@@ -1450,6 +1458,68 @@ describe("api", function () {
1450
1458
  });
1451
1459
  }).catch(done.fail);
1452
1460
  });
1461
+ it("caches image resources at the document/page level as expected (issue 11878)", async function (done) {
1462
+ const {
1463
+ NUM_PAGES_THRESHOLD
1464
+ } = _image_utils.GlobalImageCache,
1465
+ EXPECTED_WIDTH = 2550,
1466
+ EXPECTED_HEIGHT = 3300;
1467
+ const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue11878.pdf"));
1468
+ let firstImgData = null;
1469
+
1470
+ try {
1471
+ const pdfDoc = await loadingTask.promise;
1472
+
1473
+ for (let i = 1; i <= pdfDoc.numPages; i++) {
1474
+ const pdfPage = await pdfDoc.getPage(i);
1475
+ const opList = await pdfPage.getOperatorList();
1476
+ const {
1477
+ commonObjs,
1478
+ objs
1479
+ } = pdfPage;
1480
+ const imgIndex = opList.fnArray.indexOf(_util.OPS.paintImageXObject);
1481
+ const [objId, width, height] = opList.argsArray[imgIndex];
1482
+
1483
+ if (i < NUM_PAGES_THRESHOLD) {
1484
+ expect(objId).toEqual(`img_p${i - 1}_1`);
1485
+ expect(objs.has(objId)).toEqual(true);
1486
+ expect(commonObjs.has(objId)).toEqual(false);
1487
+ } else {
1488
+ expect(objId).toEqual(`g_${loadingTask.docId}_img_p${NUM_PAGES_THRESHOLD - 1}_1`);
1489
+ expect(objs.has(objId)).toEqual(false);
1490
+ expect(commonObjs.has(objId)).toEqual(true);
1491
+ }
1492
+
1493
+ expect(width).toEqual(EXPECTED_WIDTH);
1494
+ expect(height).toEqual(EXPECTED_HEIGHT);
1495
+
1496
+ if (i === 1) {
1497
+ firstImgData = objs.get(objId);
1498
+ expect(firstImgData.width).toEqual(EXPECTED_WIDTH);
1499
+ expect(firstImgData.height).toEqual(EXPECTED_HEIGHT);
1500
+ expect(firstImgData.kind).toEqual(_util.ImageKind.RGB_24BPP);
1501
+ expect(firstImgData.data instanceof Uint8ClampedArray).toEqual(true);
1502
+ expect(firstImgData.data.length).toEqual(25245000);
1503
+ } else {
1504
+ const objsPool = i >= NUM_PAGES_THRESHOLD ? commonObjs : objs;
1505
+ const currentImgData = objsPool.get(objId);
1506
+ expect(currentImgData.width).toEqual(firstImgData.width);
1507
+ expect(currentImgData.height).toEqual(firstImgData.height);
1508
+ expect(currentImgData.kind).toEqual(firstImgData.kind);
1509
+ expect(currentImgData.data instanceof Uint8ClampedArray).toEqual(true);
1510
+ expect(currentImgData.data.every((value, index) => {
1511
+ return value === firstImgData.data[index];
1512
+ })).toEqual(true);
1513
+ }
1514
+ }
1515
+
1516
+ await loadingTask.destroy();
1517
+ firstImgData = null;
1518
+ done();
1519
+ } catch (ex) {
1520
+ done.fail(ex);
1521
+ }
1522
+ });
1453
1523
  });
1454
1524
  describe("Multiple `getDocument` instances", function () {
1455
1525
  var pdf1 = (0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf");