base_viewer.d.ts 19 KB

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