forked from blackbeam/poppler-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poppler.d.ts
345 lines (319 loc) · 8.82 KB
/
poppler.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/// <reference types="node" />
/**
* Represents an absolutely positioned rectangle on a page.
*
* Coordinates are in pts (1/72 of inch).
*/
export interface AbsRect {
/** x coordinate (in pts) of the bottom left corner */
x1: number
/** x coordinate (in pts) of the upper right corner */
x2: number
/** y coordinate (in pts) of the bottom left corner */
y1: number
/** y coordinate (in pts) of the upper right corner */
y2: number
}
/**
* Represents a relatevly positioned rectangle on a page.
*
* Coordinates are relative to page width and height.
* I.e. `0.5` means the middle of the page.
*/
export interface RelRect {
/**
* x coordinate of the bottom left corner relative
* to the bottom left corner of the page.
*/
x1: number
/**
* x coordinate of the upper right corner relative
* to the bottom left corner of the page.
*/
x2: number
/**
* y coordinate of the bottom left corner relative
* to the bottom left corner of the page.
*/
y1: number
/**
* y coordinate of the upper right corner relative
* to the bottom left corner of the page.
*/
y2: number
}
/**
* Represents a word on a page.
*
* Stores the actual value of the word as well as its bouding box position.
*/
export interface Word extends RelRect {
/** Actual value of this word */
text: string,
}
/**
* Represents a slice of a page.
*
* Coordinates are relative to the bottom left corner of the page.
*/
export interface Slice {
/**
* Relative `x` coordinate of the bottom left corner,
* e.g `0.5` points to the horizontal middle of the page
*/
x: number
/**
* Relative `y` coordinate of the bottom left corner,
* e.g `0.5` points to the vertical middle of the page
*/
y: number
/**
* Relative width of a slice,
* e.g. `0.5` defines a half of a page width.
*/
w: number
/**
* Relative height of a slice,
* e.g. `0.5` defines a half of a page height.
*/
h: number
}
/**
* Represents a result of a `renderToFile` operation.
*/
export interface FileRenderResult {
type: 'file',
path: string,
}
/**
* Represents a result of a `renderToBuffer` operation.
*/
export interface BufferRenderResult {
type: 'buffer',
format: 'png' | 'jpeg' | 'tiff',
/** Raw image data. */
data: Buffer,
}
export type RenderResult = FileRenderResult | BufferRenderResult
/**
* Compression method for `tiff` format.
*
* Actual availability of different compression methods depends
* on your environment so not all methods may be supported by
* your setup.
*/
export type TiffCompression = 'none'
| 'ccittrle'
| 'ccittfax3'
| 'ccittt4'
| 'ccittfax4'
| 'ccittt6'
| 'lzw'
| 'ojpeg'
| 'jpeg'
| 'next'
| 'packbits'
| 'ccittrlew'
| 'deflate'
| 'adeflate'
| 'dcs'
| 'jbig'
| 'jp2000';
/**
* Options for a render operation.
*/
export interface RenderOptions {
/**
* Number from 0 to 100. Works only for `jpeg` format.
*/
quality?: number,
/**
* Compression method for `tiff` format.
*/
compression?: TiffCompression,
/**
* Progressive `jpeg`.
*/
progressive?: boolean,
/**
* Slice of a page to render instead of a full page.
*/
slice?: Slice,
}
/**
* PDF document.
*/
export class PopplerDocument {
/** Is this document linearized? */
isLinearized: boolean
/** Is this document encrypted? */
isEncrypted: boolean
/** PDF version (e.g. `'PDF-1.6'`). */
pdfVersion: string
/** Nuber of pages in this document. */
pageCount: number
/** E.g. `1`. */
PDFMajorVersion: number
/** E.g. `6`. */
PDFMinorVersion: number
/** Path to a document file, if any. */
fileName?: string
/**
* Constructor of a PDF document.
* @param fileName string | Buffer path to the document or a memory byffer containing pdf data.
* @param userPassword string? password required to open this document, if any.
* @param ownerPassword string? password required to manipulate this document, if any.
*/
constructor(fileName: string | Buffer, userPassword?: string, ownerPassword?: string);
/**
* This method will return a specified page if it exists in the document.
* @param number number of desired page.
*/
getPage(number: number): PopplerPage | null;
}
/**
* Page of a PDF document.
*/
export class PopplerPage {
/** Page number in a document. */
num: number
/** Widht of a page in pts (1/72 of inch). */
height: number
/** Height of a page in pts (1/72 of inch). */
width: number
/** Number of annotataion on this page. */
numAnnots: number
/** Crop box of this page. */
crop_box: AbsRect
/** Media box of this page. */
media_box: AbsRect
/** Art box of this page. */
art_box: AbsRect
/** Trim box of this page. */
trim_box: AbsRect
/** Bleed box of this page. */
bleed_box: AbsRect
/** Page rotation. */
rotate: number
/** Is this pages cropped? */
isCropped: boolean
/**
* Renders page to a file syncronously.
* @param path path to a file
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
*/
renderToFile(
path: string,
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options?: RenderOptions,
): FileRenderResult;
/**
* Renders page to a file asyncronously using old-fashioned CPS API.
* @param path path to a file
* @param format output file format
* @param ppi resolution in pixels per inch
* @param callback operation callback
*/
renderToFile(
path: string,
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
callback: (err: Error, result: FileRenderResult) => any,
): void;
/**
* Renders page to a file asyncronously using old-fashioned CPS API.
* @param path path to a file
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
* @param callback operation callback
*/
renderToFile(
path: string,
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options: RenderOptions,
callback: (err: Error, result: FileRenderResult) => any,
): void;
/**
* Renders page to a file asyncronously. Returns `Promise`.
* @param path path to a file
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
*/
renderToFileAsync(
path: string,
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options?: RenderOptions,
): Promise<FileRenderResult>;
/**
* Renders page to a buffer syncronously.
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
*/
renderToBuffer(
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options?: RenderOptions,
): BufferRenderResult;
/**
* Renders page to a buffer asyncronously using old-fashioned CPS API.
* @param format output file format
* @param ppi resolution in pixels per inch
* @param callback operation callback
*/
renderToBuffer(
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
callback: (err: Error, result: BufferRenderResult) => any,
): void;
/**
* Renders page to a buffer asyncronously using old-fashioned CPS API.
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
* @param callback operation callback
*/
renderToBuffer(
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options: RenderOptions,
callback: (err: Error, result: BufferRenderResult) => any,
): void;
/**
* Renders page to a buffer asyncronously. Returns `Promise`.
* @param format output file format
* @param ppi resolution in pixels per inch
* @param options render options
*/
renderToBufferAsync(
format: 'png' | 'jpeg' | 'tiff',
ppi: number,
options?: RenderOptions,
): Promise<BufferRenderResult>;
/**
* This method tries to find `text` on this page.
* @param text text to search
* @returns list of found rectangles
*/
findText(text: string): RelRect[];
/**
* This method will return list of all words on this page.
*/
getWordList(): Word[];
/**
* It's a way to "highlight" one or multiple rectangles on a page.
* @param rectangles desired positions for annotations
*/
addAnnot(rectangles: RelRect | RelRect[]): void;
/**
* Removes annotations created using `addAnnot(..)`.
*/
deleteAnnots(): void;
}