base_viewer.d.ts 18 KB

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