/src/pdf.js

http://github.com/mozilla/pdf.js · JavaScript · 156 lines · 118 code · 8 blank · 30 comment · 9 complexity · f5dbb2978a5fc55684a51e914ba96e8a MD5 · raw file

  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 sort-exports/sort-exports */
  16. // eslint-disable-next-line max-len
  17. /** @typedef {import("./display/api").PDFDocumentLoadingTask} PDFDocumentLoadingTask */
  18. /** @typedef {import("./display/api").PDFDocumentProxy} PDFDocumentProxy */
  19. /** @typedef {import("./display/api").PDFPageProxy} PDFPageProxy */
  20. /** @typedef {import("./display/api").RenderTask} RenderTask */
  21. import {
  22. addLinkAttributes,
  23. getFilenameFromUrl,
  24. getPdfFilenameFromUrl,
  25. getXfaPageViewport,
  26. isPdfFile,
  27. isValidFetchUrl,
  28. LinkTarget,
  29. loadScript,
  30. PDFDateString,
  31. PixelsPerInch,
  32. RenderingCancelledException,
  33. } from "./display/display_utils.js";
  34. import {
  35. AnnotationMode,
  36. CMapCompressionType,
  37. createObjectURL,
  38. createPromiseCapability,
  39. createValidAbsoluteUrl,
  40. InvalidPDFException,
  41. MissingPDFException,
  42. OPS,
  43. PasswordResponses,
  44. PermissionFlag,
  45. removeNullCharacters,
  46. shadow,
  47. UnexpectedResponseException,
  48. UNSUPPORTED_FEATURES,
  49. Util,
  50. VerbosityLevel,
  51. } from "./shared/util.js";
  52. import {
  53. build,
  54. getDocument,
  55. LoopbackPort,
  56. PDFDataRangeTransport,
  57. PDFWorker,
  58. setPDFNetworkStreamFactory,
  59. version,
  60. } from "./display/api.js";
  61. import { AnnotationLayer } from "./display/annotation_layer.js";
  62. import { GlobalWorkerOptions } from "./display/worker_options.js";
  63. import { isNodeJS } from "./shared/is_node.js";
  64. import { renderTextLayer } from "./display/text_layer.js";
  65. import { SVGGraphics } from "./display/svg.js";
  66. import { XfaLayer } from "./display/xfa_layer.js";
  67. /* eslint-disable-next-line no-unused-vars */
  68. const pdfjsVersion =
  69. typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
  70. /* eslint-disable-next-line no-unused-vars */
  71. const pdfjsBuild =
  72. typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
  73. if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
  74. const streamsPromise = Promise.all([
  75. import("pdfjs/display/network.js"),
  76. import("pdfjs/display/fetch_stream.js"),
  77. ]);
  78. setPDFNetworkStreamFactory(async params => {
  79. const [{ PDFNetworkStream }, { PDFFetchStream }] = await streamsPromise;
  80. if (isValidFetchUrl(params.url)) {
  81. return new PDFFetchStream(params);
  82. }
  83. return new PDFNetworkStream(params);
  84. });
  85. } else if (PDFJSDev.test("GENERIC || CHROME")) {
  86. if (PDFJSDev.test("GENERIC") && isNodeJS) {
  87. const { PDFNodeStream } = require("./display/node_stream.js");
  88. setPDFNetworkStreamFactory(params => {
  89. return new PDFNodeStream(params);
  90. });
  91. } else {
  92. const { PDFNetworkStream } = require("./display/network.js");
  93. const { PDFFetchStream } = require("./display/fetch_stream.js");
  94. setPDFNetworkStreamFactory(params => {
  95. if (isValidFetchUrl(params.url)) {
  96. return new PDFFetchStream(params);
  97. }
  98. return new PDFNetworkStream(params);
  99. });
  100. }
  101. }
  102. export {
  103. // From "./display/display_utils.js":
  104. addLinkAttributes,
  105. getFilenameFromUrl,
  106. getPdfFilenameFromUrl,
  107. isPdfFile,
  108. LinkTarget,
  109. loadScript,
  110. PDFDateString,
  111. PixelsPerInch,
  112. RenderingCancelledException,
  113. getXfaPageViewport,
  114. // From "./shared/util.js":
  115. AnnotationMode,
  116. CMapCompressionType,
  117. createObjectURL,
  118. createPromiseCapability,
  119. createValidAbsoluteUrl,
  120. InvalidPDFException,
  121. MissingPDFException,
  122. OPS,
  123. PasswordResponses,
  124. PermissionFlag,
  125. removeNullCharacters,
  126. shadow,
  127. UnexpectedResponseException,
  128. UNSUPPORTED_FEATURES,
  129. Util,
  130. VerbosityLevel,
  131. // From "./display/api.js":
  132. build,
  133. getDocument,
  134. LoopbackPort,
  135. PDFDataRangeTransport,
  136. PDFWorker,
  137. version,
  138. // From "./display/annotation_layer.js":
  139. AnnotationLayer,
  140. // From "./display/worker_options.js":
  141. GlobalWorkerOptions,
  142. // From "./display/text_layer.js":
  143. renderTextLayer,
  144. // From "./display/svg.js":
  145. SVGGraphics,
  146. // From "./display/xfa_layer.js":
  147. XfaLayer,
  148. };