base_viewer.d.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. export type PDFDocumentProxy = import("../src/display/api").PDFDocumentProxy;
  2. export type PDFPageProxy = import("../src/display/api").PDFPageProxy;
  3. export type PageViewport = import("../src/display/display_utils").PageViewport;
  4. export type EventBus = import("./event_utils").EventBus;
  5. export type IDownloadManager = import("./interfaces").IDownloadManager;
  6. export type IL10n = import("./interfaces").IL10n;
  7. export type IPDFAnnotationLayerFactory = import("./interfaces").IPDFAnnotationLayerFactory;
  8. export type IPDFLinkService = import("./interfaces").IPDFLinkService;
  9. export type IPDFStructTreeLayerFactory = import("./interfaces").IPDFStructTreeLayerFactory;
  10. export type IPDFTextLayerFactory = import("./interfaces").IPDFTextLayerFactory;
  11. export type IPDFXfaLayerFactory = import("./interfaces").IPDFXfaLayerFactory;
  12. export type PDFViewerOptions = {
  13. /**
  14. * - The container for the viewer element.
  15. */
  16. container: HTMLDivElement;
  17. /**
  18. * - The viewer element.
  19. */
  20. viewer?: HTMLDivElement | undefined;
  21. /**
  22. * - The application event bus.
  23. */
  24. eventBus: EventBus;
  25. /**
  26. * - The navigation/linking service.
  27. */
  28. linkService: IPDFLinkService;
  29. /**
  30. * - The download manager
  31. * component.
  32. */
  33. downloadManager?: import("./interfaces").IDownloadManager | undefined;
  34. /**
  35. * - The find controller
  36. * component.
  37. */
  38. findController?: any;
  39. /**
  40. * - The scripting manager
  41. * component.
  42. */
  43. scriptingManager?: any;
  44. /**
  45. * - The rendering queue object.
  46. */
  47. renderingQueue?: PDFRenderingQueue | undefined;
  48. /**
  49. * - Removes the border shadow around
  50. * the pages. The default value is `false`.
  51. */
  52. removePageBorders?: boolean | undefined;
  53. /**
  54. * - Controls if the text layer used for
  55. * selection and searching is created, and if the improved text selection
  56. * behaviour is enabled. The constants from {TextLayerMode} should be used.
  57. * The default value is `TextLayerMode.ENABLE`.
  58. */
  59. textLayerMode?: number | undefined;
  60. /**
  61. * - Controls if the annotation layer is
  62. * created, and if interactive form elements or `AnnotationStorage`-data are
  63. * being rendered. The constants from {@link AnnotationMode } should be used;
  64. * see also {@link RenderParameters } and {@link GetOperatorListParameters }.
  65. * The default value is `AnnotationMode.ENABLE_FORMS`.
  66. */
  67. annotationMode?: number | undefined;
  68. /**
  69. * - Path for image resources, mainly
  70. * mainly for annotation icons. Include trailing slash.
  71. */
  72. imageResourcesPath?: string | undefined;
  73. /**
  74. * - Enables automatic rotation of
  75. * landscape pages upon printing. The default is `false`.
  76. */
  77. enablePrintAutoRotate?: boolean | undefined;
  78. /**
  79. * - 'canvas' or 'svg'. The default is 'canvas'.
  80. */
  81. renderer: string;
  82. /**
  83. * - Enables CSS only zooming. The default
  84. * value is `false`.
  85. */
  86. useOnlyCssZoom?: boolean | undefined;
  87. /**
  88. * - The maximum supported canvas size in
  89. * total pixels, i.e. width * height. Use -1 for no limit. The default value
  90. * is 4096 * 4096 (16 mega-pixels).
  91. */
  92. maxCanvasPixels?: number | undefined;
  93. /**
  94. * - Localization service.
  95. */
  96. l10n: IL10n;
  97. /**
  98. * - Enables PDF document permissions,
  99. * when they exist. The default value is `false`.
  100. */
  101. enablePermissions?: boolean | undefined;
  102. };
  103. /**
  104. * Simple viewer control to display PDF content/pages.
  105. *
  106. * @implements {IPDFAnnotationLayerFactory}
  107. * @implements {IPDFStructTreeLayerFactory}
  108. * @implements {IPDFTextLayerFactory}
  109. * @implements {IPDFXfaLayerFactory}
  110. */
  111. export class BaseViewer implements IPDFAnnotationLayerFactory, IPDFStructTreeLayerFactory, IPDFTextLayerFactory, IPDFXfaLayerFactory {
  112. /**
  113. * @param {PDFViewerOptions} options
  114. */
  115. constructor(options: PDFViewerOptions);
  116. container: HTMLDivElement;
  117. viewer: Element | null;
  118. eventBus: import("./event_utils").EventBus;
  119. linkService: import("./interfaces").IPDFLinkService;
  120. downloadManager: import("./interfaces").IDownloadManager | null;
  121. findController: any;
  122. _scriptingManager: any;
  123. removePageBorders: boolean;
  124. textLayerMode: number;
  125. imageResourcesPath: string;
  126. enablePrintAutoRotate: boolean;
  127. renderer: string;
  128. useOnlyCssZoom: boolean;
  129. maxCanvasPixels: number | undefined;
  130. l10n: import("./interfaces").IL10n;
  131. defaultRenderingQueue: boolean;
  132. renderingQueue: PDFRenderingQueue | undefined;
  133. _doc: HTMLElement;
  134. scroll: {
  135. right: boolean;
  136. down: boolean;
  137. lastX: any;
  138. lastY: any;
  139. _eventHandler: (evt: any) => void;
  140. };
  141. presentationModeState: number;
  142. _onBeforeDraw: ((evt: any) => void) | null;
  143. _onAfterDraw: any;
  144. get pagesCount(): number;
  145. getPageView(index: any): any;
  146. /**
  147. * @type {boolean} - True if all {PDFPageView} objects are initialized.
  148. */
  149. get pageViewsReady(): boolean;
  150. /**
  151. * @type {boolean}
  152. */
  153. get renderForms(): boolean;
  154. /**
  155. * @type {boolean}
  156. */
  157. get enableScripting(): boolean;
  158. /**
  159. * @param {number} val - The page number.
  160. */
  161. set currentPageNumber(arg: number);
  162. /**
  163. * @type {number}
  164. */
  165. get currentPageNumber(): number;
  166. /**
  167. * @returns {boolean} Whether the pageNumber is valid (within bounds).
  168. * @private
  169. */
  170. private _setCurrentPageNumber;
  171. _currentPageNumber: any;
  172. /**
  173. * @param {string} val - The page label.
  174. */
  175. set currentPageLabel(arg: string | null);
  176. /**
  177. * @type {string|null} Returns the current page label, or `null` if no page
  178. * labels exist.
  179. */
  180. get currentPageLabel(): string | null;
  181. /**
  182. * @param {number} val - Scale of the pages in percents.
  183. */
  184. set currentScale(arg: number);
  185. /**
  186. * @type {number}
  187. */
  188. get currentScale(): number;
  189. /**
  190. * @param val - The scale of the pages (in percent or predefined value).
  191. */
  192. set currentScaleValue(arg: string);
  193. /**
  194. * @type {string}
  195. */
  196. get currentScaleValue(): string;
  197. /**
  198. * @param {number} rotation - The rotation of the pages (0, 90, 180, 270).
  199. */
  200. set pagesRotation(arg: number);
  201. /**
  202. * @type {number}
  203. */
  204. get pagesRotation(): number;
  205. _pagesRotation: any;
  206. get firstPagePromise(): any;
  207. get onePageRendered(): any;
  208. get pagesPromise(): any;
  209. /**
  210. * @param {PDFDocumentProxy} pdfDocument
  211. */
  212. setDocument(pdfDocument: PDFDocumentProxy): void;
  213. pdfDocument: import("../src/display/api").PDFDocumentProxy | undefined;
  214. _scrollMode: any;
  215. _optionalContentConfigPromise: Promise<any> | null | undefined;
  216. /**
  217. * @param {Array|null} labels
  218. */
  219. setPageLabels(labels: any[] | null): void;
  220. _pageLabels: any[] | null | undefined;
  221. _resetView(): void;
  222. _pages: any[] | undefined;
  223. _currentScale: any;
  224. _currentScaleValue: any;
  225. _location: {
  226. pageNumber: any;
  227. scale: any;
  228. top: number;
  229. left: number;
  230. rotation: any;
  231. pdfOpenParams: string;
  232. } | null | undefined;
  233. _firstPageCapability: any;
  234. _onePageRenderedCapability: any;
  235. _pagesCapability: any;
  236. _previousScrollMode: any;
  237. _spreadMode: any;
  238. _scrollUpdate(): void;
  239. _scrollIntoView({ pageDiv, pageSpot, pageNumber }: {
  240. pageDiv: any;
  241. pageSpot?: null | undefined;
  242. pageNumber?: null | undefined;
  243. }): void;
  244. _setScaleUpdatePages(newScale: any, newValue: any, noScroll?: boolean, preset?: boolean): void;
  245. /**
  246. * @private
  247. */
  248. private get _pageWidthScaleFactor();
  249. _setScale(value: any, noScroll?: boolean): void;
  250. /**
  251. * Refreshes page view: scrolls to the current page and updates the scale.
  252. * @private
  253. */
  254. private _resetCurrentPageView;
  255. /**
  256. * @param {string} label - The page label.
  257. * @returns {number|null} The page number corresponding to the page label,
  258. * or `null` when no page labels exist and/or the input is invalid.
  259. */
  260. pageLabelToPageNumber(label: string): number | null;
  261. /**
  262. * @typedef ScrollPageIntoViewParameters
  263. * @property {number} pageNumber - The page number.
  264. * @property {Array} [destArray] - The original PDF destination array, in the
  265. * format: <page-ref> </XYZ|/FitXXX> <args..>
  266. * @property {boolean} [allowNegativeOffset] - Allow negative page offsets.
  267. * The default value is `false`.
  268. * @property {boolean} [ignoreDestinationZoom] - Ignore the zoom argument in
  269. * the destination array. The default value is `false`.
  270. */
  271. /**
  272. * Scrolls page into view.
  273. * @param {ScrollPageIntoViewParameters} params
  274. */
  275. scrollPageIntoView({ pageNumber, destArray, allowNegativeOffset, ignoreDestinationZoom, }: {
  276. /**
  277. * - The page number.
  278. */
  279. pageNumber: number;
  280. /**
  281. * - The original PDF destination array, in the
  282. * format: <page-ref> </XYZ|/FitXXX> <args..>
  283. */
  284. destArray?: any[] | undefined;
  285. /**
  286. * - Allow negative page offsets.
  287. * The default value is `false`.
  288. */
  289. allowNegativeOffset?: boolean | undefined;
  290. /**
  291. * - Ignore the zoom argument in
  292. * the destination array. The default value is `false`.
  293. */
  294. ignoreDestinationZoom?: boolean | undefined;
  295. }): void;
  296. _updateLocation(firstPage: any): void;
  297. update(): void;
  298. containsElement(element: any): boolean;
  299. focus(): void;
  300. get _isContainerRtl(): boolean;
  301. get isInPresentationMode(): boolean;
  302. get isChangingPresentationMode(): boolean;
  303. get isHorizontalScrollbarEnabled(): boolean;
  304. get isVerticalScrollbarEnabled(): boolean;
  305. /**
  306. * Helper method for `this._getVisiblePages`. Should only ever be used when
  307. * the viewer can only display a single page at a time, for example:
  308. * - When PresentationMode is active.
  309. */
  310. _getCurrentVisiblePage(): {
  311. views: never[];
  312. first?: undefined;
  313. last?: undefined;
  314. ids?: undefined;
  315. } | {
  316. first: {
  317. id: any;
  318. x: any;
  319. y: any;
  320. view: any;
  321. };
  322. last: {
  323. id: any;
  324. x: any;
  325. y: any;
  326. view: any;
  327. };
  328. views: {
  329. id: any;
  330. x: any;
  331. y: any;
  332. view: any;
  333. }[];
  334. ids: Set<any>;
  335. };
  336. _getVisiblePages(): Object;
  337. /**
  338. * @param {number} pageNumber
  339. */
  340. isPageVisible(pageNumber: number): any;
  341. /**
  342. * @param {number} pageNumber
  343. */
  344. isPageCached(pageNumber: number): any;
  345. cleanup(): void;
  346. /**
  347. * @private
  348. */
  349. private _cancelRendering;
  350. forceRendering(currentlyVisiblePages: any): boolean;
  351. /**
  352. * @param {HTMLDivElement} textLayerDiv
  353. * @param {number} pageIndex
  354. * @param {PageViewport} viewport
  355. * @param {boolean} enhanceTextSelection
  356. * @param {EventBus} eventBus
  357. * @param {TextHighlighter} highlighter
  358. * @returns {TextLayerBuilder}
  359. */
  360. createTextLayerBuilder(textLayerDiv: HTMLDivElement, pageIndex: number, viewport: PageViewport, enhanceTextSelection: boolean | undefined, eventBus: EventBus, highlighter: TextHighlighter): TextLayerBuilder;
  361. /**
  362. * @param {number} pageIndex
  363. * @param {EventBus} eventBus
  364. * @returns {TextHighlighter}
  365. */
  366. createTextHighlighter(pageIndex: number, eventBus: EventBus): TextHighlighter;
  367. /**
  368. * @param {HTMLDivElement} pageDiv
  369. * @param {PDFPageProxy} pdfPage
  370. * @param {AnnotationStorage} [annotationStorage] - Storage for annotation
  371. * data in forms.
  372. * @param {string} [imageResourcesPath] - Path for image resources, mainly
  373. * for annotation icons. Include trailing slash.
  374. * @param {boolean} renderForms
  375. * @param {IL10n} l10n
  376. * @param {boolean} [enableScripting]
  377. * @param {Promise<boolean>} [hasJSActionsPromise]
  378. * @param {Object} [mouseState]
  379. * @param {Promise<Object<string, Array<Object>> | null>}
  380. * [fieldObjectsPromise]
  381. * @param {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
  382. * @returns {AnnotationLayerBuilder}
  383. */
  384. createAnnotationLayerBuilder(pageDiv: HTMLDivElement, pdfPage: PDFPageProxy, annotationStorage?: any, imageResourcesPath?: string | undefined, renderForms?: boolean, l10n?: IL10n, enableScripting?: boolean | undefined, hasJSActionsPromise?: Promise<boolean> | undefined, mouseState?: Object | undefined, fieldObjectsPromise?: Promise<{
  385. [x: string]: Object[];
  386. } | null> | undefined, annotationCanvasMap?: Map<string, HTMLCanvasElement> | undefined): AnnotationLayerBuilder;
  387. /**
  388. * @param {HTMLDivElement} pageDiv
  389. * @param {PDFPageProxy} pdfPage
  390. * @param {AnnotationStorage} [annotationStorage] - Storage for annotation
  391. * data in forms.
  392. * @returns {XfaLayerBuilder}
  393. */
  394. createXfaLayerBuilder(pageDiv: HTMLDivElement, pdfPage: PDFPageProxy, annotationStorage?: any): XfaLayerBuilder;
  395. /**
  396. * @param {PDFPageProxy} pdfPage
  397. * @returns {StructTreeLayerBuilder}
  398. */
  399. createStructTreeLayerBuilder(pdfPage: PDFPageProxy): StructTreeLayerBuilder;
  400. /**
  401. * @type {boolean} Whether all pages of the PDF document have identical
  402. * widths and heights.
  403. */
  404. get hasEqualPageSizes(): boolean;
  405. /**
  406. * Returns sizes of the pages.
  407. * @returns {Array} Array of objects with width/height/rotation fields.
  408. */
  409. getPagesOverview(): any[];
  410. /**
  411. * @param {Promise<OptionalContentConfig>} promise - A promise that is
  412. * resolved with an {@link OptionalContentConfig} instance.
  413. */
  414. set optionalContentConfigPromise(arg: Promise<any>);
  415. /**
  416. * @type {Promise<OptionalContentConfig | null>}
  417. */
  418. get optionalContentConfigPromise(): Promise<any>;
  419. /**
  420. * @param {number} mode - The direction in which the document pages should be
  421. * laid out within the scrolling container.
  422. * The constants from {ScrollMode} should be used.
  423. */
  424. set scrollMode(arg: number);
  425. /**
  426. * @type {number} One of the values in {ScrollMode}.
  427. */
  428. get scrollMode(): number;
  429. _updateScrollMode(pageNumber?: null): void;
  430. /**
  431. * @param {number} mode - Group the pages in spreads, starting with odd- or
  432. * even-number pages (unless `SpreadMode.NONE` is used).
  433. * The constants from {SpreadMode} should be used.
  434. */
  435. set spreadMode(arg: number);
  436. /**
  437. * @type {number} One of the values in {SpreadMode}.
  438. */
  439. get spreadMode(): number;
  440. _updateSpreadMode(pageNumber?: null): void;
  441. /**
  442. * @private
  443. */
  444. private _getPageAdvance;
  445. /**
  446. * Go to the next page, taking scroll/spread-modes into account.
  447. * @returns {boolean} Whether navigation occured.
  448. */
  449. nextPage(): boolean;
  450. /**
  451. * Go to the previous page, taking scroll/spread-modes into account.
  452. * @returns {boolean} Whether navigation occured.
  453. */
  454. previousPage(): boolean;
  455. /**
  456. * Increase the current zoom level one, or more, times.
  457. * @param {number} [steps] - Defaults to zooming once.
  458. */
  459. increaseScale(steps?: number | undefined): void;
  460. /**
  461. * Decrease the current zoom level one, or more, times.
  462. * @param {number} [steps] - Defaults to zooming once.
  463. */
  464. decreaseScale(steps?: number | undefined): void;
  465. #private;
  466. }
  467. export namespace PagesCountLimit {
  468. const FORCE_SCROLL_MODE_PAGE: number;
  469. const FORCE_LAZY_PAGE_INIT: number;
  470. const PAUSE_EAGER_PAGE_INIT: number;
  471. }
  472. /**
  473. * @typedef {Object} PDFViewerOptions
  474. * @property {HTMLDivElement} container - The container for the viewer element.
  475. * @property {HTMLDivElement} [viewer] - The viewer element.
  476. * @property {EventBus} eventBus - The application event bus.
  477. * @property {IPDFLinkService} linkService - The navigation/linking service.
  478. * @property {IDownloadManager} [downloadManager] - The download manager
  479. * component.
  480. * @property {PDFFindController} [findController] - The find controller
  481. * component.
  482. * @property {PDFScriptingManager} [scriptingManager] - The scripting manager
  483. * component.
  484. * @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
  485. * @property {boolean} [removePageBorders] - Removes the border shadow around
  486. * the pages. The default value is `false`.
  487. * @property {number} [textLayerMode] - Controls if the text layer used for
  488. * selection and searching is created, and if the improved text selection
  489. * behaviour is enabled. The constants from {TextLayerMode} should be used.
  490. * The default value is `TextLayerMode.ENABLE`.
  491. * @property {number} [annotationMode] - Controls if the annotation layer is
  492. * created, and if interactive form elements or `AnnotationStorage`-data are
  493. * being rendered. The constants from {@link AnnotationMode} should be used;
  494. * see also {@link RenderParameters} and {@link GetOperatorListParameters}.
  495. * The default value is `AnnotationMode.ENABLE_FORMS`.
  496. * @property {string} [imageResourcesPath] - Path for image resources, mainly
  497. * mainly for annotation icons. Include trailing slash.
  498. * @property {boolean} [enablePrintAutoRotate] - Enables automatic rotation of
  499. * landscape pages upon printing. The default is `false`.
  500. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
  501. * @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
  502. * value is `false`.
  503. * @property {number} [maxCanvasPixels] - The maximum supported canvas size in
  504. * total pixels, i.e. width * height. Use -1 for no limit. The default value
  505. * is 4096 * 4096 (16 mega-pixels).
  506. * @property {IL10n} l10n - Localization service.
  507. * @property {boolean} [enablePermissions] - Enables PDF document permissions,
  508. * when they exist. The default value is `false`.
  509. */
  510. export class PDFPageViewBuffer {
  511. constructor(size: any);
  512. push(view: any): void;
  513. /**
  514. * After calling resize, the size of the buffer will be `newSize`.
  515. * The optional parameter `idsToKeep` is, if present, a Set of page-ids to
  516. * push to the back of the buffer, delaying their destruction. The size of
  517. * `idsToKeep` has no impact on the final size of the buffer; if `idsToKeep`
  518. * is larger than `newSize`, some of those pages will be destroyed anyway.
  519. */
  520. resize(newSize: any, idsToKeep?: null): void;
  521. has(view: any): boolean;
  522. [Symbol.iterator](): IterableIterator<any>;
  523. #private;
  524. }
  525. import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
  526. import { TextHighlighter } from "./text_highlighter.js";
  527. import { TextLayerBuilder } from "./text_layer_builder.js";
  528. import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
  529. import { XfaLayerBuilder } from "./xfa_layer_builder.js";
  530. import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";