pdf.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* eslint-disable no-unused-vars */
  16. 'use strict';
  17. var pdfjsVersion =
  18. typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : void 0;
  19. var pdfjsBuild =
  20. typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_BUILD') : void 0;
  21. var pdfjsSharedUtil = require('./shared/util.js');
  22. var pdfjsDisplayAPI = require('./display/api.js');
  23. var pdfjsDisplayTextLayer = require('./display/text_layer.js');
  24. var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
  25. var pdfjsDisplayDisplayUtils = require('./display/display_utils.js');
  26. var pdfjsDisplaySVG = require('./display/svg.js');
  27. let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
  28. let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
  29. if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
  30. const isNodeJS = require('./shared/is_node.js');
  31. if (isNodeJS()) {
  32. let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
  33. pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
  34. return new PDFNodeStream(params);
  35. });
  36. } else {
  37. let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
  38. let PDFFetchStream;
  39. if (pdfjsDisplayDisplayUtils.isFetchSupported()) {
  40. PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
  41. }
  42. pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
  43. if (PDFFetchStream &&
  44. pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) {
  45. return new PDFFetchStream(params);
  46. }
  47. return new PDFNetworkStream(params);
  48. });
  49. }
  50. } else if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
  51. let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
  52. let PDFFetchStream;
  53. let isChromeWithFetchCredentials = function() {
  54. // fetch does not include credentials until Chrome 61.0.3138.0 and later.
  55. // https://chromium.googlesource.com/chromium/src/+/2e231cf052ca5e68e22baf0008ac9e5e29121707
  56. try {
  57. // Indexed properties on window are read-only in Chrome 61.0.3151.0+
  58. // https://chromium.googlesource.com/chromium/src.git/+/58ab4a971b06dec13e4edf9de8382ca6847f6190
  59. window[999] = 123; // should throw. Note: JS strict mode MUST be enabled.
  60. delete window[999];
  61. return false;
  62. } catch (e) {
  63. return true;
  64. }
  65. };
  66. if (pdfjsDisplayDisplayUtils.isFetchSupported() &&
  67. isChromeWithFetchCredentials()) {
  68. PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
  69. }
  70. pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
  71. if (PDFFetchStream &&
  72. pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) {
  73. return new PDFFetchStream(params);
  74. }
  75. return new PDFNetworkStream(params);
  76. });
  77. }
  78. exports.build = pdfjsDisplayAPI.build;
  79. exports.version = pdfjsDisplayAPI.version;
  80. exports.getDocument = pdfjsDisplayAPI.getDocument;
  81. exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort;
  82. exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
  83. exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
  84. exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
  85. exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
  86. exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
  87. exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
  88. exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
  89. exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
  90. exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
  91. exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
  92. exports.CMapCompressionType = pdfjsSharedUtil.CMapCompressionType;
  93. exports.PermissionFlag = pdfjsSharedUtil.PermissionFlag;
  94. exports.UnexpectedResponseException =
  95. pdfjsSharedUtil.UnexpectedResponseException;
  96. exports.OPS = pdfjsSharedUtil.OPS;
  97. exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel;
  98. exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  99. exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
  100. exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
  101. exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
  102. exports.shadow = pdfjsSharedUtil.shadow;
  103. exports.Util = pdfjsSharedUtil.Util;
  104. exports.ReadableStream = pdfjsSharedUtil.ReadableStream;
  105. exports.RenderingCancelledException =
  106. pdfjsDisplayDisplayUtils.RenderingCancelledException;
  107. exports.getFilenameFromUrl = pdfjsDisplayDisplayUtils.getFilenameFromUrl;
  108. exports.LinkTarget = pdfjsDisplayDisplayUtils.LinkTarget;
  109. exports.addLinkAttributes = pdfjsDisplayDisplayUtils.addLinkAttributes;
  110. exports.loadScript = pdfjsDisplayDisplayUtils.loadScript;
  111. exports.PDFDateString = pdfjsDisplayDisplayUtils.PDFDateString;
  112. exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions;
  113. exports.apiCompatibilityParams =
  114. pdfjsDisplayAPICompatibility.apiCompatibilityParams;