pdf_viewer.d.ts 16 KB

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