api.d.ts 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
  2. /**
  3. * Document initialization / loading parameters object.
  4. */
  5. export type DocumentInitParameters = {
  6. /**
  7. * - The URL of the PDF.
  8. */
  9. url?: string | undefined;
  10. /**
  11. * - Binary PDF data. Use
  12. * typed arrays (Uint8Array) to improve the memory usage. If PDF data is
  13. * BASE64-encoded, use `atob()` to convert it to a binary string first.
  14. */
  15. data?: string | number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | undefined;
  16. /**
  17. * - Basic authentication headers.
  18. */
  19. httpHeaders?: Object | undefined;
  20. /**
  21. * - Indicates whether or not
  22. * cross-site Access-Control requests should be made using credentials such
  23. * as cookies or authorization headers. The default is `false`.
  24. */
  25. withCredentials?: boolean | undefined;
  26. /**
  27. * - For decrypting password-protected PDFs.
  28. */
  29. password?: string | undefined;
  30. /**
  31. * - A typed array with the first portion
  32. * or all of the pdf data. Used by the extension since some data is already
  33. * loaded before the switch to range requests.
  34. */
  35. initialData?: Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | undefined;
  36. /**
  37. * - The PDF file length. It's used for progress
  38. * reports and range requests operations.
  39. */
  40. length?: number | undefined;
  41. /**
  42. * - Allows for using a custom range
  43. * transport implementation.
  44. */
  45. range?: PDFDataRangeTransport | undefined;
  46. /**
  47. * - Specify maximum number of bytes fetched
  48. * per range request. The default value is {@link DEFAULT_RANGE_CHUNK_SIZE}.
  49. */
  50. rangeChunkSize?: number | undefined;
  51. /**
  52. * - The worker that will be used for loading and
  53. * parsing the PDF data.
  54. */
  55. worker?: any;
  56. /**
  57. * - Controls the logging level; the constants
  58. * from {@link VerbosityLevel} should be used.
  59. */
  60. verbosity?: number | undefined;
  61. /**
  62. * - The base URL of the document, used when
  63. * attempting to recover valid absolute URLs for annotations, and outline
  64. * items, that (incorrectly) only specify relative URLs.
  65. */
  66. docBaseUrl?: string | undefined;
  67. /**
  68. * - The URL where the predefined Adobe CMaps are
  69. * located. Include the trailing slash.
  70. */
  71. cMapUrl?: string | undefined;
  72. /**
  73. * - Specifies if the Adobe CMaps are binary
  74. * packed or not.
  75. */
  76. cMapPacked?: boolean | undefined;
  77. /**
  78. * - The factory that will be used when
  79. * reading built-in CMap files. Providing a custom factory is useful for
  80. * environments without Fetch API or `XMLHttpRequest` support, such as
  81. * Node.js. The default value is {DOMCMapReaderFactory}.
  82. */
  83. CMapReaderFactory?: Object | undefined;
  84. /**
  85. * - Reject certain promises, e.g.
  86. * `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
  87. * PDF data cannot be successfully parsed, instead of attempting to recover
  88. * whatever possible of the data. The default value is `false`.
  89. */
  90. stopAtErrors?: boolean | undefined;
  91. /**
  92. * - The maximum allowed image size in total
  93. * pixels, i.e. width * height. Images above this value will not be rendered.
  94. * Use -1 for no limit, which is also the default value.
  95. */
  96. maxImageSize?: number | undefined;
  97. /**
  98. * - Determines if we can evaluate strings
  99. * as JavaScript. Primarily used to improve performance of font rendering, and
  100. * when parsing PDF functions. The default value is `true`.
  101. */
  102. isEvalSupported?: boolean | undefined;
  103. /**
  104. * - By default fonts are converted to
  105. * OpenType fonts and loaded via `@font-face` rules. If disabled, fonts will
  106. * be rendered using a built-in font renderer that constructs the glyphs with
  107. * primitive path commands. The default value is `false`.
  108. */
  109. disableFontFace?: boolean | undefined;
  110. /**
  111. * - Include additional properties,
  112. * which are unused during rendering of PDF documents, when exporting the
  113. * parsed font data from the worker-thread. This may be useful for debugging
  114. * purposes (and backwards compatibility), but note that it will lead to
  115. * increased memory usage. The default value is `false`.
  116. */
  117. fontExtraProperties?: boolean | undefined;
  118. /**
  119. * - Specify an explicit document
  120. * context to create elements with and to load resources, such as fonts,
  121. * into. Defaults to the current document.
  122. */
  123. ownerDocument?: HTMLDocument | undefined;
  124. /**
  125. * - Disable range request loading of PDF
  126. * files. When enabled, and if the server supports partial content requests,
  127. * then the PDF will be fetched in chunks. The default value is `false`.
  128. */
  129. disableRange?: boolean | undefined;
  130. /**
  131. * - Disable streaming of PDF file data.
  132. * By default PDF.js attempts to load PDF files in chunks. The default value
  133. * is `false`.
  134. */
  135. disableStream?: boolean | undefined;
  136. /**
  137. * - Disable pre-fetching of PDF file
  138. * data. When range requests are enabled PDF.js will automatically keep
  139. * fetching more data even if it isn't needed to display the current page.
  140. * The default value is `false`.
  141. *
  142. * NOTE: It is also necessary to disable streaming, see above, in order for
  143. * disabling of pre-fetching to work correctly.
  144. */
  145. disableAutoFetch?: boolean | undefined;
  146. /**
  147. * - Enables special hooks for debugging PDF.js
  148. * (see `web/debugger.js`). The default value is `false`.
  149. */
  150. pdfBug?: boolean | undefined;
  151. };
  152. export type PDFDocumentStats = {
  153. /**
  154. * - Used stream types in the
  155. * document (an item is set to true if specific stream ID was used in the
  156. * document).
  157. */
  158. streamTypes: {
  159. [x: string]: boolean;
  160. };
  161. /**
  162. * - Used font types in the
  163. * document (an item is set to true if specific font ID was used in the
  164. * document).
  165. */
  166. fontTypes: {
  167. [x: string]: boolean;
  168. };
  169. };
  170. export type IPDFStreamFactory = Function;
  171. /**
  172. * The loading task controls the operations required to load a PDF document
  173. * (such as network requests) and provides a way to listen for completion,
  174. * after which individual pages can be rendered.
  175. */
  176. export type PDFDocumentLoadingTask = {
  177. /**
  178. * - Unique identifier for the document loading task.
  179. */
  180. docId: string;
  181. /**
  182. * - Whether the loading task is destroyed or not.
  183. */
  184. destroyed: boolean;
  185. /**
  186. * - Callback to request a password if a wrong
  187. * or no password was provided. The callback receives two parameters: a
  188. * function that should be called with the new password, and a reason (see
  189. * {@link PasswordResponses}).
  190. */
  191. onPassword?: Function | undefined;
  192. /**
  193. * - Callback to be able to monitor the
  194. * loading progress of the PDF file (necessary to implement e.g. a loading
  195. * bar). The callback receives an {Object} with the properties `loaded`
  196. * ({number}) and `total` ({number}) that indicate how many bytes are loaded.
  197. */
  198. onProgress?: Function | undefined;
  199. /**
  200. * - Callback for when an
  201. * unsupported feature is used in the PDF document. The callback receives an
  202. * {@link UNSUPPORTED_FEATURES} argument.
  203. */
  204. onUnsupportedFeature?: Function | undefined;
  205. /**
  206. * - Promise for document loading
  207. * task completion.
  208. */
  209. promise: Promise<PDFDocumentProxy>;
  210. /**
  211. * - Abort all network requests and destroy
  212. * the worker. Returns a promise that is resolved when destruction is
  213. * completed.
  214. */
  215. destroy: Function;
  216. };
  217. /**
  218. * Page getViewport parameters.
  219. */
  220. export type GetViewportParameters = {
  221. /**
  222. * - The desired scale of the viewport.
  223. */
  224. scale: number;
  225. /**
  226. * - The desired rotation, in degrees, of
  227. * the viewport. If omitted it defaults to the page rotation.
  228. */
  229. rotation?: number | undefined;
  230. /**
  231. * - The horizontal, i.e. x-axis, offset.
  232. * The default value is `0`.
  233. */
  234. offsetX?: number | undefined;
  235. /**
  236. * - The vertical, i.e. y-axis, offset.
  237. * The default value is `0`.
  238. */
  239. offsetY?: number | undefined;
  240. /**
  241. * - If true, the y-axis will not be
  242. * flipped. The default value is `false`.
  243. */
  244. dontFlip?: boolean | undefined;
  245. };
  246. /**
  247. * Page getTextContent parameters.
  248. */
  249. export type getTextContentParameters = {
  250. /**
  251. * - Replaces all occurrences of
  252. * whitespace with standard spaces (0x20). The default value is `false`.
  253. */
  254. normalizeWhitespace: boolean;
  255. /**
  256. * - Do not attempt to combine
  257. * same line {@link TextItem}'s. The default value is `false`.
  258. */
  259. disableCombineTextItems: boolean;
  260. };
  261. /**
  262. * Page text content.
  263. */
  264. export type TextContent = {
  265. /**
  266. * - Array of {@link TextItem} objects.
  267. */
  268. items: Array<TextItem>;
  269. /**
  270. * - {@link TextStyle} objects,
  271. * indexed by font name.
  272. */
  273. styles: {
  274. [x: string]: TextStyle;
  275. };
  276. };
  277. /**
  278. * Page text content part.
  279. */
  280. export type TextItem = {
  281. /**
  282. * - Text content.
  283. */
  284. str: string;
  285. /**
  286. * - Text direction: 'ttb', 'ltr' or 'rtl'.
  287. */
  288. dir: string;
  289. /**
  290. * - Transformation matrix.
  291. */
  292. transform: Array<any>;
  293. /**
  294. * - Width in device space.
  295. */
  296. width: number;
  297. /**
  298. * - Height in device space.
  299. */
  300. height: number;
  301. /**
  302. * - Font name used by PDF.js for converted font.
  303. */
  304. fontName: string;
  305. };
  306. /**
  307. * Text style.
  308. */
  309. export type TextStyle = {
  310. /**
  311. * - Font ascent.
  312. */
  313. ascent: number;
  314. /**
  315. * - Font descent.
  316. */
  317. descent: number;
  318. /**
  319. * - Whether or not the text is in vertical mode.
  320. */
  321. vertical: boolean;
  322. /**
  323. * - The possible font family.
  324. */
  325. fontFamily: string;
  326. };
  327. /**
  328. * Page annotation parameters.
  329. */
  330. export type GetAnnotationsParameters = {
  331. /**
  332. * - Determines the annotations that will be fetched,
  333. * can be either 'display' (viewable annotations) or 'print' (printable
  334. * annotations). If the parameter is omitted, all annotations are fetched.
  335. */
  336. intent: string;
  337. };
  338. /**
  339. * Page render parameters.
  340. */
  341. export type RenderParameters = {
  342. /**
  343. * - A 2D context of a DOM Canvas object.
  344. */
  345. canvasContext: Object;
  346. /**
  347. * - Rendering viewport obtained by calling
  348. * the `PDFPageProxy.getViewport` method.
  349. */
  350. viewport: PageViewport;
  351. /**
  352. * - Rendering intent, can be 'display' or 'print'.
  353. * The default value is 'display'.
  354. */
  355. intent?: string | undefined;
  356. /**
  357. * - Enables WebGL accelerated rendering for
  358. * some operations. The default value is `false`.
  359. */
  360. enableWebGL?: boolean | undefined;
  361. /**
  362. * - Whether or not interactive
  363. * form elements are rendered in the display layer. If so, we do not render
  364. * them on the canvas as well.
  365. */
  366. renderInteractiveForms?: boolean | undefined;
  367. /**
  368. * - Additional transform, applied just
  369. * before viewport transform.
  370. */
  371. transform?: any[] | undefined;
  372. /**
  373. * - An object that has `beginLayout`,
  374. * `endLayout` and `appendImage` functions.
  375. */
  376. imageLayer?: Object | undefined;
  377. /**
  378. * - The factory instance that will be used
  379. * when creating canvases. The default value is {new DOMCanvasFactory()}.
  380. */
  381. canvasFactory?: Object | undefined;
  382. /**
  383. * - Background to use for the canvas.
  384. * Any valid `canvas.fillStyle` can be used: a `DOMString` parsed as CSS
  385. * <color> value, a `CanvasGradient` object (a linear or radial gradient) or
  386. * a `CanvasPattern` object (a repetitive image). The default value is
  387. * 'rgb(255,255,255)'.
  388. */
  389. background?: string | Object | undefined;
  390. /**
  391. * - Storage for annotation
  392. * data in forms.
  393. */
  394. annotationStorage?: AnnotationStorage | undefined;
  395. /**
  396. * -
  397. * A promise that should resolve with an {@link OptionalContentConfig}
  398. * created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
  399. * the configuration will be fetched automatically with the default visibility
  400. * states set.
  401. */
  402. optionalContentConfigPromise?: Promise<OptionalContentConfig> | undefined;
  403. };
  404. /**
  405. * PDF page operator list.
  406. */
  407. export type PDFOperatorList = {
  408. /**
  409. * - Array containing the operator functions.
  410. */
  411. fnArray: Array<number>;
  412. /**
  413. * - Array containing the arguments of the
  414. * functions.
  415. */
  416. argsArray: Array<any>;
  417. };
  418. export type PDFWorkerParameters = {
  419. /**
  420. * - The name of the worker.
  421. */
  422. name?: string | undefined;
  423. /**
  424. * - The `workerPort` object.
  425. */
  426. port?: Object | undefined;
  427. /**
  428. * - Controls the logging level; the
  429. * constants from {@link VerbosityLevel} should be used.
  430. */
  431. verbosity?: number | undefined;
  432. };
  433. /** @type {string} */
  434. export const build: string;
  435. export const DefaultCanvasFactory: typeof DOMCanvasFactory | {
  436. new (): {};
  437. };
  438. export const DefaultCMapReaderFactory: typeof DOMCMapReaderFactory | {
  439. new (): {};
  440. };
  441. /**
  442. * @typedef { Int8Array | Uint8Array | Uint8ClampedArray |
  443. * Int16Array | Uint16Array |
  444. * Int32Array | Uint32Array | Float32Array |
  445. * Float64Array
  446. * } TypedArray
  447. */
  448. /**
  449. * Document initialization / loading parameters object.
  450. *
  451. * @typedef {Object} DocumentInitParameters
  452. * @property {string} [url] - The URL of the PDF.
  453. * @property {TypedArray|Array<number>|string} [data] - Binary PDF data. Use
  454. * typed arrays (Uint8Array) to improve the memory usage. If PDF data is
  455. * BASE64-encoded, use `atob()` to convert it to a binary string first.
  456. * @property {Object} [httpHeaders] - Basic authentication headers.
  457. * @property {boolean} [withCredentials] - Indicates whether or not
  458. * cross-site Access-Control requests should be made using credentials such
  459. * as cookies or authorization headers. The default is `false`.
  460. * @property {string} [password] - For decrypting password-protected PDFs.
  461. * @property {TypedArray} [initialData] - A typed array with the first portion
  462. * or all of the pdf data. Used by the extension since some data is already
  463. * loaded before the switch to range requests.
  464. * @property {number} [length] - The PDF file length. It's used for progress
  465. * reports and range requests operations.
  466. * @property {PDFDataRangeTransport} [range] - Allows for using a custom range
  467. * transport implementation.
  468. * @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched
  469. * per range request. The default value is {@link DEFAULT_RANGE_CHUNK_SIZE}.
  470. * @property {PDFWorker} [worker] - The worker that will be used for loading and
  471. * parsing the PDF data.
  472. * @property {number} [verbosity] - Controls the logging level; the constants
  473. * from {@link VerbosityLevel} should be used.
  474. * @property {string} [docBaseUrl] - The base URL of the document, used when
  475. * attempting to recover valid absolute URLs for annotations, and outline
  476. * items, that (incorrectly) only specify relative URLs.
  477. * @property {string} [cMapUrl] - The URL where the predefined Adobe CMaps are
  478. * located. Include the trailing slash.
  479. * @property {boolean} [cMapPacked] - Specifies if the Adobe CMaps are binary
  480. * packed or not.
  481. * @property {Object} [CMapReaderFactory] - The factory that will be used when
  482. * reading built-in CMap files. Providing a custom factory is useful for
  483. * environments without Fetch API or `XMLHttpRequest` support, such as
  484. * Node.js. The default value is {DOMCMapReaderFactory}.
  485. * @property {boolean} [stopAtErrors] - Reject certain promises, e.g.
  486. * `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
  487. * PDF data cannot be successfully parsed, instead of attempting to recover
  488. * whatever possible of the data. The default value is `false`.
  489. * @property {number} [maxImageSize] - The maximum allowed image size in total
  490. * pixels, i.e. width * height. Images above this value will not be rendered.
  491. * Use -1 for no limit, which is also the default value.
  492. * @property {boolean} [isEvalSupported] - Determines if we can evaluate strings
  493. * as JavaScript. Primarily used to improve performance of font rendering, and
  494. * when parsing PDF functions. The default value is `true`.
  495. * @property {boolean} [disableFontFace] - By default fonts are converted to
  496. * OpenType fonts and loaded via `@font-face` rules. If disabled, fonts will
  497. * be rendered using a built-in font renderer that constructs the glyphs with
  498. * primitive path commands. The default value is `false`.
  499. * @property {boolean} [fontExtraProperties] - Include additional properties,
  500. * which are unused during rendering of PDF documents, when exporting the
  501. * parsed font data from the worker-thread. This may be useful for debugging
  502. * purposes (and backwards compatibility), but note that it will lead to
  503. * increased memory usage. The default value is `false`.
  504. * @property {HTMLDocument} [ownerDocument] - Specify an explicit document
  505. * context to create elements with and to load resources, such as fonts,
  506. * into. Defaults to the current document.
  507. * @property {boolean} [disableRange] - Disable range request loading of PDF
  508. * files. When enabled, and if the server supports partial content requests,
  509. * then the PDF will be fetched in chunks. The default value is `false`.
  510. * @property {boolean} [disableStream] - Disable streaming of PDF file data.
  511. * By default PDF.js attempts to load PDF files in chunks. The default value
  512. * is `false`.
  513. * @property {boolean} [disableAutoFetch] - Disable pre-fetching of PDF file
  514. * data. When range requests are enabled PDF.js will automatically keep
  515. * fetching more data even if it isn't needed to display the current page.
  516. * The default value is `false`.
  517. *
  518. * NOTE: It is also necessary to disable streaming, see above, in order for
  519. * disabling of pre-fetching to work correctly.
  520. * @property {boolean} [pdfBug] - Enables special hooks for debugging PDF.js
  521. * (see `web/debugger.js`). The default value is `false`.
  522. */
  523. /**
  524. * @typedef {Object} PDFDocumentStats
  525. * @property {Object<string, boolean>} streamTypes - Used stream types in the
  526. * document (an item is set to true if specific stream ID was used in the
  527. * document).
  528. * @property {Object<string, boolean>} fontTypes - Used font types in the
  529. * document (an item is set to true if specific font ID was used in the
  530. * document).
  531. */
  532. /**
  533. * This is the main entry point for loading a PDF and interacting with it.
  534. *
  535. * NOTE: If a URL is used to fetch the PDF data a standard Fetch API call (or
  536. * XHR as fallback) is used, which means it must follow same origin rules,
  537. * e.g. no cross-domain requests without CORS.
  538. *
  539. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src -
  540. * Can be a URL to where a PDF file is located, a typed array (Uint8Array)
  541. * already populated with data or parameter object.
  542. * @returns {PDFDocumentLoadingTask}
  543. */
  544. export function getDocument(src: string | TypedArray | DocumentInitParameters | PDFDataRangeTransport): PDFDocumentLoadingTask;
  545. export class LoopbackPort {
  546. constructor(defer?: boolean);
  547. _listeners: any[];
  548. _defer: boolean;
  549. _deferred: Promise<undefined>;
  550. postMessage(obj: any, transfers: any): void;
  551. addEventListener(name: any, listener: any): void;
  552. removeEventListener(name: any, listener: any): void;
  553. terminate(): void;
  554. }
  555. /**
  556. * Abstract class to support range requests file loading.
  557. */
  558. export class PDFDataRangeTransport {
  559. /**
  560. * @param {number} length
  561. * @param {Uint8Array} initialData
  562. * @param {boolean} [progressiveDone]
  563. */
  564. constructor(length: number, initialData: Uint8Array, progressiveDone?: boolean | undefined);
  565. length: number;
  566. initialData: Uint8Array;
  567. progressiveDone: boolean;
  568. _rangeListeners: any[];
  569. _progressListeners: any[];
  570. _progressiveReadListeners: any[];
  571. _progressiveDoneListeners: any[];
  572. _readyCapability: import("../shared/util.js").PromiseCapability;
  573. addRangeListener(listener: any): void;
  574. addProgressListener(listener: any): void;
  575. addProgressiveReadListener(listener: any): void;
  576. addProgressiveDoneListener(listener: any): void;
  577. onDataRange(begin: any, chunk: any): void;
  578. onDataProgress(loaded: any, total: any): void;
  579. onDataProgressiveRead(chunk: any): void;
  580. onDataProgressiveDone(): void;
  581. transportReady(): void;
  582. requestDataRange(begin: any, end: any): void;
  583. abort(): void;
  584. }
  585. /**
  586. * Proxy to a `PDFDocument` in the worker thread.
  587. */
  588. export class PDFDocumentProxy {
  589. constructor(pdfInfo: any, transport: any);
  590. _pdfInfo: any;
  591. _transport: any;
  592. /**
  593. * @type {AnnotationStorage} Storage for annotation data in forms.
  594. */
  595. get annotationStorage(): AnnotationStorage;
  596. /**
  597. * @type {number} Total number of pages in the PDF file.
  598. */
  599. get numPages(): number;
  600. /**
  601. * @type {string} A (not guaranteed to be) unique ID to identify a PDF.
  602. */
  603. get fingerprint(): string;
  604. /**
  605. * @param {number} pageNumber - The page number to get. The first page is 1.
  606. * @returns {Promise<PDFPageProxy>} A promise that is resolved with
  607. * a {@link PDFPageProxy} object.
  608. */
  609. getPage(pageNumber: number): Promise<PDFPageProxy>;
  610. /**
  611. * @param {{num: number, gen: number}} ref - The page reference. Must have
  612. * the `num` and `gen` properties.
  613. * @returns {Promise<{num: number, gen: number}>} A promise that is resolved
  614. * with the page index (starting from zero) that is associated with the
  615. * reference.
  616. */
  617. getPageIndex(ref: {
  618. num: number;
  619. gen: number;
  620. }): Promise<{
  621. num: number;
  622. gen: number;
  623. }>;
  624. /**
  625. * @returns {Promise<Object<string, Array<any>>>} A promise that is resolved
  626. * with a mapping from named destinations to references.
  627. *
  628. * This can be slow for large documents. Use `getDestination` instead.
  629. */
  630. getDestinations(): Promise<{
  631. [x: string]: Array<any>;
  632. }>;
  633. /**
  634. * @param {string} id - The named destination to get.
  635. * @returns {Promise<Array<any>>} A promise that is resolved with all
  636. * information of the given named destination.
  637. */
  638. getDestination(id: string): Promise<Array<any>>;
  639. /**
  640. * @returns {Promise<Array<string> | null>} A promise that is resolved with
  641. * an {Array} containing the page labels that correspond to the page
  642. * indexes, or `null` when no page labels are present in the PDF file.
  643. */
  644. getPageLabels(): Promise<Array<string> | null>;
  645. /**
  646. * @returns {Promise<string>} A promise that is resolved with a {string}
  647. * containing the page layout name.
  648. */
  649. getPageLayout(): Promise<string>;
  650. /**
  651. * @returns {Promise<string>} A promise that is resolved with a {string}
  652. * containing the page mode name.
  653. */
  654. getPageMode(): Promise<string>;
  655. /**
  656. * @returns {Promise<Object | null>} A promise that is resolved with an
  657. * {Object} containing the viewer preferences, or `null` when no viewer
  658. * preferences are present in the PDF file.
  659. */
  660. getViewerPreferences(): Promise<Object | null>;
  661. /**
  662. * @returns {Promise<any | null>} A promise that is resolved with an {Array}
  663. * containing the destination, or `null` when no open action is present
  664. * in the PDF.
  665. */
  666. getOpenAction(): Promise<any | null>;
  667. /**
  668. * @returns {Promise<any>} A promise that is resolved with a lookup table
  669. * for mapping named attachments to their content.
  670. */
  671. getAttachments(): Promise<any>;
  672. /**
  673. * @returns {Promise<Array<string> | null>} A promise that is resolved with
  674. * an {Array} of all the JavaScript strings in the name tree, or `null`
  675. * if no JavaScript exists.
  676. */
  677. getJavaScript(): Promise<Array<string> | null>;
  678. /**
  679. * @returns {Promise<Object | null>} A promise that is resolved with
  680. * an {Object} with the JavaScript actions:
  681. * - from the name tree (like getJavaScript);
  682. * - from A or AA entries in the catalog dictionary.
  683. * , or `null` if no JavaScript exists.
  684. */
  685. getJSActions(): Promise<Object | null>;
  686. /**
  687. * @typedef {Object} OutlineNode
  688. * @property {string} title
  689. * @property {boolean} bold
  690. * @property {boolean} italic
  691. * @property {Uint8ClampedArray} color - The color in RGB format to use for
  692. * display purposes.
  693. * @property {string | Array<any> | null} dest
  694. * @property {string | null} url
  695. * @property {string | undefined} unsafeUrl
  696. * @property {boolean | undefined} newWindow
  697. * @property {number | undefined} count
  698. * @property {Array<OutlineNode>} items
  699. */
  700. /**
  701. * @returns {Promise<Array<OutlineNode>>} A promise that is resolved with an
  702. * {Array} that is a tree outline (if it has one) of the PDF file.
  703. */
  704. getOutline(): Promise<{
  705. title: string;
  706. bold: boolean;
  707. italic: boolean;
  708. /**
  709. * - The color in RGB format to use for
  710. * display purposes.
  711. */
  712. color: Uint8ClampedArray;
  713. dest: string | Array<any> | null;
  714. url: string | null;
  715. unsafeUrl: string | undefined;
  716. newWindow: boolean | undefined;
  717. count: number | undefined;
  718. items: any[];
  719. }[]>;
  720. /**
  721. * @returns {Promise<OptionalContentConfig>} A promise that is resolved with
  722. * an {@link OptionalContentConfig} that contains all the optional content
  723. * groups (assuming that the document has any).
  724. */
  725. getOptionalContentConfig(): Promise<OptionalContentConfig>;
  726. /**
  727. * @returns {Promise<Array<number> | null>} A promise that is resolved with
  728. * an {Array} that contains the permission flags for the PDF document, or
  729. * `null` when no permissions are present in the PDF file.
  730. */
  731. getPermissions(): Promise<Array<number> | null>;
  732. /**
  733. * @returns {Promise<{ info: Object, metadata: Metadata }>} A promise that is
  734. * resolved with an {Object} that has `info` and `metadata` properties.
  735. * `info` is an {Object} filled with anything available in the information
  736. * dictionary and similarly `metadata` is a {Metadata} object with
  737. * information from the metadata section of the PDF.
  738. */
  739. getMetadata(): Promise<{
  740. info: Object;
  741. metadata: Metadata;
  742. }>;
  743. /**
  744. * @typedef {Object} MarkInfo
  745. * Properties correspond to Table 321 of the PDF 32000-1:2008 spec.
  746. * @property {boolean} Marked
  747. * @property {boolean} UserProperties
  748. * @property {boolean} Suspects
  749. */
  750. /**
  751. * @returns {Promise<MarkInfo | null>} A promise that is resolved with
  752. * a {MarkInfo} object that contains the MarkInfo flags for the PDF
  753. * document, or `null` when no MarkInfo values are present in the PDF file.
  754. */
  755. getMarkInfo(): Promise<{
  756. Marked: boolean;
  757. UserProperties: boolean;
  758. Suspects: boolean;
  759. } | null>;
  760. /**
  761. * @returns {Promise<TypedArray>} A promise that is resolved with a
  762. * {TypedArray} that has the raw data from the PDF.
  763. */
  764. getData(): Promise<TypedArray>;
  765. /**
  766. * @returns {Promise<{ length: number }>} A promise that is resolved when the
  767. * document's data is loaded. It is resolved with an {Object} that contains
  768. * the `length` property that indicates size of the PDF data in bytes.
  769. */
  770. getDownloadInfo(): Promise<{
  771. length: number;
  772. }>;
  773. /**
  774. * @returns {Promise<PDFDocumentStats>} A promise this is resolved with
  775. * current statistics about document structures (see
  776. * {@link PDFDocumentStats}).
  777. */
  778. getStats(): Promise<PDFDocumentStats>;
  779. /**
  780. * Cleans up resources allocated by the document on both the main and worker
  781. * threads.
  782. *
  783. * NOTE: Do not, under any circumstances, call this method when rendering is
  784. * currently ongoing since that may lead to rendering errors.
  785. *
  786. * @returns {Promise} A promise that is resolved when clean-up has finished.
  787. */
  788. cleanup(): Promise<any>;
  789. /**
  790. * Destroys the current document instance and terminates the worker.
  791. */
  792. destroy(): any;
  793. /**
  794. * @type {DocumentInitParameters} A subset of the current
  795. * {DocumentInitParameters}, which are either needed in the viewer and/or
  796. * whose default values may be affected by the `apiCompatibilityParams`.
  797. */
  798. get loadingParams(): DocumentInitParameters;
  799. /**
  800. * @type {PDFDocumentLoadingTask} The loadingTask for the current document.
  801. */
  802. get loadingTask(): PDFDocumentLoadingTask;
  803. /**
  804. * @param {AnnotationStorage} annotationStorage - Storage for annotation
  805. * data in forms.
  806. * @returns {Promise<Uint8Array>} A promise that is resolved with a
  807. * {Uint8Array} containing the full data of the saved document.
  808. */
  809. saveDocument(annotationStorage: AnnotationStorage): Promise<Uint8Array>;
  810. /**
  811. * @returns {Promise<Array<Object> | null>} A promise that is resolved with an
  812. * {Array<Object>} containing /AcroForm field data for the JS sandbox,
  813. * or `null` when no field data is present in the PDF file.
  814. */
  815. getFieldObjects(): Promise<Array<Object> | null>;
  816. /**
  817. * @returns {Promise<boolean>} A promise that is resolved with `true`
  818. * if some /AcroForm fields have JavaScript actions.
  819. */
  820. hasJSActions(): Promise<boolean>;
  821. /**
  822. * @returns {Promise<Array<string> | null>} A promise that is resolved with an
  823. * {Array<string>} containing IDs of annotations that have a calculation
  824. * action, or `null` when no such annotations are present in the PDF file.
  825. */
  826. getCalculationOrderIds(): Promise<Array<string> | null>;
  827. }
  828. /**
  829. * Page getViewport parameters.
  830. *
  831. * @typedef {Object} GetViewportParameters
  832. * @property {number} scale - The desired scale of the viewport.
  833. * @property {number} [rotation] - The desired rotation, in degrees, of
  834. * the viewport. If omitted it defaults to the page rotation.
  835. * @property {number} [offsetX] - The horizontal, i.e. x-axis, offset.
  836. * The default value is `0`.
  837. * @property {number} [offsetY] - The vertical, i.e. y-axis, offset.
  838. * The default value is `0`.
  839. * @property {boolean} [dontFlip] - If true, the y-axis will not be
  840. * flipped. The default value is `false`.
  841. */
  842. /**
  843. * Page getTextContent parameters.
  844. *
  845. * @typedef {Object} getTextContentParameters
  846. * @property {boolean} normalizeWhitespace - Replaces all occurrences of
  847. * whitespace with standard spaces (0x20). The default value is `false`.
  848. * @property {boolean} disableCombineTextItems - Do not attempt to combine
  849. * same line {@link TextItem}'s. The default value is `false`.
  850. */
  851. /**
  852. * Page text content.
  853. *
  854. * @typedef {Object} TextContent
  855. * @property {Array<TextItem>} items - Array of {@link TextItem} objects.
  856. * @property {Object<string, TextStyle>} styles - {@link TextStyle} objects,
  857. * indexed by font name.
  858. */
  859. /**
  860. * Page text content part.
  861. *
  862. * @typedef {Object} TextItem
  863. * @property {string} str - Text content.
  864. * @property {string} dir - Text direction: 'ttb', 'ltr' or 'rtl'.
  865. * @property {Array<any>} transform - Transformation matrix.
  866. * @property {number} width - Width in device space.
  867. * @property {number} height - Height in device space.
  868. * @property {string} fontName - Font name used by PDF.js for converted font.
  869. */
  870. /**
  871. * Text style.
  872. *
  873. * @typedef {Object} TextStyle
  874. * @property {number} ascent - Font ascent.
  875. * @property {number} descent - Font descent.
  876. * @property {boolean} vertical - Whether or not the text is in vertical mode.
  877. * @property {string} fontFamily - The possible font family.
  878. */
  879. /**
  880. * Page annotation parameters.
  881. *
  882. * @typedef {Object} GetAnnotationsParameters
  883. * @property {string} intent - Determines the annotations that will be fetched,
  884. * can be either 'display' (viewable annotations) or 'print' (printable
  885. * annotations). If the parameter is omitted, all annotations are fetched.
  886. */
  887. /**
  888. * Page render parameters.
  889. *
  890. * @typedef {Object} RenderParameters
  891. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  892. * @property {PageViewport} viewport - Rendering viewport obtained by calling
  893. * the `PDFPageProxy.getViewport` method.
  894. * @property {string} [intent] - Rendering intent, can be 'display' or 'print'.
  895. * The default value is 'display'.
  896. * @property {boolean} [enableWebGL] - Enables WebGL accelerated rendering for
  897. * some operations. The default value is `false`.
  898. * @property {boolean} [renderInteractiveForms] - Whether or not interactive
  899. * form elements are rendered in the display layer. If so, we do not render
  900. * them on the canvas as well.
  901. * @property {Array<any>} [transform] - Additional transform, applied just
  902. * before viewport transform.
  903. * @property {Object} [imageLayer] - An object that has `beginLayout`,
  904. * `endLayout` and `appendImage` functions.
  905. * @property {Object} [canvasFactory] - The factory instance that will be used
  906. * when creating canvases. The default value is {new DOMCanvasFactory()}.
  907. * @property {Object | string} [background] - Background to use for the canvas.
  908. * Any valid `canvas.fillStyle` can be used: a `DOMString` parsed as CSS
  909. * <color> value, a `CanvasGradient` object (a linear or radial gradient) or
  910. * a `CanvasPattern` object (a repetitive image). The default value is
  911. * 'rgb(255,255,255)'.
  912. * @property {AnnotationStorage} [annotationStorage] - Storage for annotation
  913. * data in forms.
  914. * @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
  915. * A promise that should resolve with an {@link OptionalContentConfig}
  916. * created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
  917. * the configuration will be fetched automatically with the default visibility
  918. * states set.
  919. */
  920. /**
  921. * PDF page operator list.
  922. *
  923. * @typedef {Object} PDFOperatorList
  924. * @property {Array<number>} fnArray - Array containing the operator functions.
  925. * @property {Array<any>} argsArray - Array containing the arguments of the
  926. * functions.
  927. */
  928. /**
  929. * Proxy to a `PDFPage` in the worker thread.
  930. */
  931. export class PDFPageProxy {
  932. constructor(pageIndex: any, pageInfo: any, transport: any, ownerDocument: any, pdfBug?: boolean);
  933. _pageIndex: any;
  934. _pageInfo: any;
  935. _ownerDocument: any;
  936. _transport: any;
  937. _stats: StatTimer | null;
  938. _pdfBug: boolean;
  939. commonObjs: any;
  940. objs: PDFObjects;
  941. cleanupAfterRender: boolean;
  942. pendingCleanup: boolean;
  943. _intentStates: Map<any, any>;
  944. destroyed: boolean;
  945. /**
  946. * @type {number} Page number of the page. First page is 1.
  947. */
  948. get pageNumber(): number;
  949. /**
  950. * @type {number} The number of degrees the page is rotated clockwise.
  951. */
  952. get rotate(): number;
  953. /**
  954. * @type {Object} The reference that points to this page. It has `num` and
  955. * `gen` properties.
  956. */
  957. get ref(): Object;
  958. /**
  959. * @type {number} The default size of units in 1/72nds of an inch.
  960. */
  961. get userUnit(): number;
  962. /**
  963. * @type {Array<number>} An array of the visible portion of the PDF page in
  964. * user space units [x1, y1, x2, y2].
  965. */
  966. get view(): number[];
  967. /**
  968. * @param {GetViewportParameters} params - Viewport parameters.
  969. * @returns {PageViewport} Contains 'width' and 'height' properties
  970. * along with transforms required for rendering.
  971. */
  972. getViewport({ scale, rotation, offsetX, offsetY, dontFlip, }?: GetViewportParameters): PageViewport;
  973. /**
  974. * @param {GetAnnotationsParameters} params - Annotation parameters.
  975. * @returns {Promise<Array<any>>} A promise that is resolved with an
  976. * {Array} of the annotation objects.
  977. */
  978. getAnnotations({ intent }?: GetAnnotationsParameters): Promise<Array<any>>;
  979. annotationsPromise: any;
  980. annotationsIntent: string | undefined;
  981. /**
  982. * @returns {Promise<Object>} A promise that is resolved with an
  983. * {Object} with JS actions.
  984. */
  985. getJSActions(): Promise<Object>;
  986. /**
  987. * Begins the process of rendering a page to the desired context.
  988. *
  989. * @param {RenderParameters} params Page render parameters.
  990. * @returns {RenderTask} An object that contains a promise that is
  991. * resolved when the page finishes rendering.
  992. */
  993. render({ canvasContext, viewport, intent, enableWebGL, renderInteractiveForms, transform, imageLayer, canvasFactory, background, annotationStorage, optionalContentConfigPromise, }: RenderParameters): RenderTask;
  994. /**
  995. * @returns {Promise<PDFOperatorList>} A promise resolved with an
  996. * {@link PDFOperatorList} object that represents page's operator list.
  997. */
  998. getOperatorList(): Promise<PDFOperatorList>;
  999. /**
  1000. * @param {getTextContentParameters} params - getTextContent parameters.
  1001. * @returns {ReadableStream} Stream for reading text content chunks.
  1002. */
  1003. streamTextContent({ normalizeWhitespace, disableCombineTextItems, }?: getTextContentParameters): ReadableStream;
  1004. /**
  1005. * @param {getTextContentParameters} params - getTextContent parameters.
  1006. * @returns {Promise<TextContent>} A promise that is resolved with a
  1007. * {@link TextContent} object that represents the page's text content.
  1008. */
  1009. getTextContent(params?: getTextContentParameters): Promise<TextContent>;
  1010. /**
  1011. * Destroys the page object.
  1012. * @private
  1013. */
  1014. private _destroy;
  1015. _jsActionsPromise: any;
  1016. /**
  1017. * Cleans up resources allocated by the page.
  1018. *
  1019. * @param {boolean} [resetStats] - Reset page stats, if enabled.
  1020. * The default value is `false`.
  1021. * @returns {boolean} Indicates if clean-up was successfully run.
  1022. */
  1023. cleanup(resetStats?: boolean | undefined): boolean;
  1024. /**
  1025. * Attempts to clean up if rendering is in a state where that's possible.
  1026. * @private
  1027. */
  1028. private _tryCleanup;
  1029. /**
  1030. * @private
  1031. */
  1032. private _startRenderPage;
  1033. /**
  1034. * @private
  1035. */
  1036. private _renderPageChunk;
  1037. /**
  1038. * @private
  1039. */
  1040. private _pumpOperatorList;
  1041. /**
  1042. * @private
  1043. */
  1044. private _abortOperatorList;
  1045. /**
  1046. * @type {Object} Returns page stats, if enabled; returns `null` otherwise.
  1047. */
  1048. get stats(): Object;
  1049. }
  1050. /**
  1051. * @typedef {Object} PDFWorkerParameters
  1052. * @property {string} [name] - The name of the worker.
  1053. * @property {Object} [port] - The `workerPort` object.
  1054. * @property {number} [verbosity] - Controls the logging level; the
  1055. * constants from {@link VerbosityLevel} should be used.
  1056. */
  1057. /** @type {any} */
  1058. export const PDFWorker: any;
  1059. /**
  1060. * Sets the function that instantiates an {IPDFStream} as an alternative PDF
  1061. * data transport.
  1062. *
  1063. * @param {IPDFStreamFactory} pdfNetworkStreamFactory - The factory function
  1064. * that takes document initialization parameters (including a "url") and
  1065. * returns a promise which is resolved with an instance of {IPDFStream}.
  1066. * @ignore
  1067. */
  1068. export function setPDFNetworkStreamFactory(pdfNetworkStreamFactory: IPDFStreamFactory): void;
  1069. /** @type {string} */
  1070. export const version: string;
  1071. import { PageViewport } from "./display_utils.js";
  1072. import { AnnotationStorage } from "./annotation_storage.js";
  1073. import { OptionalContentConfig } from "./optional_content_config.js";
  1074. import { DOMCanvasFactory } from "./display_utils.js";
  1075. import { DOMCMapReaderFactory } from "./display_utils.js";
  1076. /**
  1077. * The loading task controls the operations required to load a PDF document
  1078. * (such as network requests) and provides a way to listen for completion,
  1079. * after which individual pages can be rendered.
  1080. *
  1081. * @typedef {Object} PDFDocumentLoadingTask
  1082. * @property {string} docId - Unique identifier for the document loading task.
  1083. * @property {boolean} destroyed - Whether the loading task is destroyed or not.
  1084. * @property {function} [onPassword] - Callback to request a password if a wrong
  1085. * or no password was provided. The callback receives two parameters: a
  1086. * function that should be called with the new password, and a reason (see
  1087. * {@link PasswordResponses}).
  1088. * @property {function} [onProgress] - Callback to be able to monitor the
  1089. * loading progress of the PDF file (necessary to implement e.g. a loading
  1090. * bar). The callback receives an {Object} with the properties `loaded`
  1091. * ({number}) and `total` ({number}) that indicate how many bytes are loaded.
  1092. * @property {function} [onUnsupportedFeature] - Callback for when an
  1093. * unsupported feature is used in the PDF document. The callback receives an
  1094. * {@link UNSUPPORTED_FEATURES} argument.
  1095. * @property {Promise<PDFDocumentProxy>} promise - Promise for document loading
  1096. * task completion.
  1097. * @property {function} destroy - Abort all network requests and destroy
  1098. * the worker. Returns a promise that is resolved when destruction is
  1099. * completed.
  1100. */
  1101. /**
  1102. * @type {any}
  1103. * @ignore
  1104. */
  1105. declare const PDFDocumentLoadingTask: any;
  1106. import { info } from "../shared/util.js";
  1107. import { Metadata } from "./metadata.js";
  1108. import { StatTimer } from "./display_utils.js";
  1109. /**
  1110. * A PDF document and page is built of many objects. E.g. there are objects for
  1111. * fonts, images, rendering code, etc. These objects may get processed inside of
  1112. * a worker. This class implements some basic methods to manage these objects.
  1113. * @ignore
  1114. */
  1115. declare class PDFObjects {
  1116. _objs: any;
  1117. /**
  1118. * Ensures there is an object defined for `objId`.
  1119. * @private
  1120. */
  1121. private _ensureObj;
  1122. /**
  1123. * If called *without* callback, this returns the data of `objId` but the
  1124. * object needs to be resolved. If it isn't, this method throws.
  1125. *
  1126. * If called *with* a callback, the callback is called with the data of the
  1127. * object once the object is resolved. That means, if you call this method
  1128. * and the object is already resolved, the callback gets called right away.
  1129. */
  1130. get(objId: any, callback?: any): any;
  1131. has(objId: any): any;
  1132. /**
  1133. * Resolves the object `objId` with optional `data`.
  1134. */
  1135. resolve(objId: any, data: any): void;
  1136. clear(): void;
  1137. }
  1138. /**
  1139. * Allows controlling of the rendering tasks.
  1140. */
  1141. declare class RenderTask {
  1142. constructor(internalRenderTask: any);
  1143. _internalRenderTask: any;
  1144. /**
  1145. * Callback for incremental rendering -- a function that will be called
  1146. * each time the rendering is paused. To continue rendering call the
  1147. * function that is the first argument to the callback.
  1148. * @type {function}
  1149. */
  1150. onContinue: Function;
  1151. /**
  1152. * Promise for rendering task completion.
  1153. * @type {Promise<void>}
  1154. */
  1155. get promise(): Promise<void>;
  1156. /**
  1157. * Cancels the rendering task. If the task is currently rendering it will
  1158. * not be cancelled until graphics pauses with a timeout. The promise that
  1159. * this object extends will be rejected when cancelled.
  1160. */
  1161. cancel(): void;
  1162. }
  1163. export {};