pdf.js 4.6 KB

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