base_viewer.d.ts 18 KB

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