forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfkit.d.ts
390 lines (346 loc) · 13 KB
/
pdfkit.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// Type definitions for Pdfkit v0.7.1
// Project: http://pdfkit.org
// Definitions by: Eric Hillah <https://github.com/erichillah>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module PDFKit {
interface PDFGradient {
new(document: any): PDFGradient ;
stop(pos: number, color?: string|PDFKit.PDFGradient, opacity?: number): PDFGradient;
embed(): void;
apply(): void;
}
interface PDFLinearGradient extends PDFGradient {
new(document: any, x1: number, y1: number, x2: number, y2: number): PDFLinearGradient;
shader(fn: () => any): any;
opacityGradient(): PDFLinearGradient;
}
interface PDFRadialGradient extends PDFGradient {
new(document: any, x1: number, y1: number, x2: number, y2: number): PDFRadialGradient;
shader(fn: () => any): any;
opacityGradient(): PDFRadialGradient;
}
}
declare module PDFKit.Mixins {
interface AnnotationOption {
Type?: string;
Rect?: any;
Border?: Array<number>;
SubType?: string;
Contents?: string;
Name?: string;
color?: string;
QuadPoints?: Array<number>;
A?: any;
B?: any;
C?: any;
L?: any;
DA?: string;
}
interface PDFAnnotation<TDocument> {
annotate(x: number, y: number, w: number, h: number, option: AnnotationOption): TDocument;
note(x: number, y: number, w: number, h: number, content: string, option?: AnnotationOption): TDocument;
link(x: number, y: number, w: number, h: number, url: string, option?: AnnotationOption): TDocument;
highlight(x: number, y: number, w: number, h: number, option?: AnnotationOption): TDocument;
underline(x: number, y: number, w: number, h: number, option?: AnnotationOption): TDocument;
strike(x: number, y: number, w: number, h: number, option?: AnnotationOption): TDocument;
lineAnnotation(x1: number, y1: number, x2: number, y2: number, option?: AnnotationOption): TDocument;
rectAnnotation(x: number, y: number, w: number, h: number, option?: AnnotationOption): TDocument;
ellipseAnnotation(x: number, y: number, w: number, h: number, option?: AnnotationOption): TDocument;
textAnnotation(x: number, y: number, w: number, h: number, text: string, option?: AnnotationOption): TDocument;
}
interface PDFColor<TDocument> {
fillColor(color: string|PDFGradient, opacity?: number): TDocument;
strokeColor(color: string, opacity?: number): TDocument;
opacity(opacity: number): TDocument;
fillOpacity(opacity: number): TDocument;
strokeOpacity(opacity: number): TDocument;
linearGradient(x1: number, y1: number, x2: number, y2: number): PDFLinearGradient;
radialGradient(x1: number, y1: number, r1: number, x2: number, y2: number, r2: number): PDFRadialGradient;
}
interface PDFFont<TDocument> {
font(src: string, family?: string, size?: number): TDocument;
fontSize(size: number): TDocument;
currentLineHeight(includeGap?: boolean): number;
registerFont(name: string, src?: string, family?: string): TDocument;
}
interface ImageOption {
width?: number;
height?: number;
/** Scale percentage */
scale?: number;
/** Two elements array specifying dimensions(w,h) */
fit?: number[];
}
interface PDFImage {
/**
* Draw an image in PDFKit document.
* No need chainning capabilities
*/
image(src: any, x: number, y: number, options: ImageOption): any;
}
interface TextOptions {
/** Set to false to disable line wrapping all together */
lineBreak?: boolean;
/** The width that text should be wrapped to (by default, the page width minus the left and right margin) */
width?: number;
/** The maximum height that text should be clipped to */
height?: number;
/** The character to display at the end of the text when it is too long. Set to true to use the default character. */
ellipsis?: boolean|string;
/** the number of columns to flow the text into */
columns?: number;
/** the amount of space between each column (1/4 inch by default) */
columnGap?: number;
/** The amount in PDF points (72 per inch) to indent each paragraph of text */
indent?: number;
/** the amount of space between each paragraph of text */
paragrahGap?: number;
/** the amount of space between each line of text */
lineGap?: number;
/** the amount of space between each word in the text */
wordSpacing?: number;
/** the amount of space between each character in the text */
characterSpacing?: number;
/** whether to fill the text (true by default) */
fill?: boolean;
/** whether to stroke the text */
stroke?: boolean;
/** A URL to link this text to (shortcut to create an annotation) */
link?: string;
/** whether to underline the text */
underline?: boolean;
/** whether to strike out the text */
strike?: boolean;
/**whether the text segment will be followed immediately by another segment. Useful for changing styling in the middle of a paragraph. */
continued?: boolean;
}
interface PDFText<TDocument> {
lineGap(lineGap: number): TDocument;
moveDown(line?: number): TDocument;
moveUp(line?: number): TDocument;
text(text: string, x?: number, y?: number, options?: TextOptions): TDocument;
text(text: string, options?: TextOptions): TDocument;
widthOfString(text: string, options?: TextOptions): number;
heightOfString(text: string, options?: TextOptions): number;
list(list: Array<string|any>, x?: number, y?: number, options?: TextOptions): TDocument;
list(list: Array<string|any>, options?: TextOptions): TDocument;
}
interface PDFVector<TDocument> {
save(): TDocument;
restore(): TDocument;
closePath(): TDocument;
lineWidth(w: number): TDocument;
lineCap(c: string): TDocument;
lineJoin(j: string): TDocument;
miterLimit(m: any): TDocument;
dash(length: number, option: any): TDocument;
undash(): TDocument;
moveTo(x: number, y: number): TDocument;
lineTo(x: number, y: number): TDocument;
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): TDocument;
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): TDocument;
rect(x: number, y: number, w: number, h: number): TDocument;
roundRect(x: number, y: number, w: number, h: number, r?: number): TDocument;
ellipse(x: number, y: number, r1: number, r2?: number): TDocument;
circle(x: number, y: number, raduis: number): TDocument;
polygon(...points: number[][]): TDocument;
path(path: string): TDocument;
fill(color: string|PDFKit.PDFGradient, rule?: string): TDocument;
stroke(color?: string|PDFKit.PDFGradient): TDocument;
fillAndStroke(fillColor: string, strokeColor?: string, rule?: string): TDocument;
clip(rule?: string): TDocument;
transform(m11: number, m12: number, m21: number, m22: number, dx: number, dy: number): TDocument;
translate(x: number, y: number): TDocument;
rotate(angle: number, options?: { origin?: number[] }): TDocument;
scale(xFactor: number, yFactor?: number, options?: { origin?: number[] }): TDocument;
}
}
declare module PDFKit {
/**
* PDFKit data
*/
interface PDFData {
new (data: any[]): PDFData;
readByte(): any;
writeByte(byte: any): void;
byteAt(index: number): any;
readBool(): boolean;
writeBool(val: boolean): boolean;
readUInt32(): number;
writeUInt32(val: number): void;
readInt32(): number;
writeInt32(val: number): void;
readUInt16(): number;
writeUInt16(val: number): void;
readInt16(): number;
writeInt16(val: number): void;
readString(length: number): string;
writeString(val: string): void;
stringAt(pos: number, length: number): string;
readShort(): number;
writeShort(val: number): void;
readLongLong(): number;
writeLongLong(val: number): void;
readInt(): number;
writeInt(val: number): void;
slice(start: number, end: number): any[];
read(length: number): any[];
write(bytes: any[]): void;
}
}
declare module "pdfkit/js/data" {
var PDFKitData: PDFKit.PDFData;
export = PDFKitData;
}
declare module PDFKit {
interface DocumentInfo {
Producer?: string;
Creator?: string;
CreationDate?: Date;
Title?: string;
Author?: string;
Keywords?: string;
ModDate?: Date;
}
interface PDFDocumentOptions {
compress?: boolean;
info?: DocumentInfo;
autoFirstPage?: boolean;
sizes?: number[];
margin?: { top: number; left: number; bottom: number; right: number }|number;
bufferPages?: boolean;
}
interface PDFDocument extends NodeJS.ReadableStream,
Mixins.PDFAnnotation<PDFDocument>, Mixins.PDFColor<PDFDocument>, Mixins.PDFImage,
Mixins.PDFText<PDFDocument>, Mixins.PDFVector<PDFDocument>, Mixins.PDFFont<PDFDocument> {
/**
* PDF Version
*/
version: number;
/**
* Wheter streams should be compressed
*/
compress: boolean;
/**
* PDF document Metadata
*/
info: DocumentInfo;
/**
* Options for the document
*/
options: PDFDocumentOptions;
/**
* Represent the current page.
*/
page: PDFPage;
x: number;
y: number;
new (options?: PDFDocumentOptions): PDFDocument;
addPage(options?: PDFDocumentOptions): PDFDocument;
bufferedPageRanges(): { start: number; count: number };
switchToPage(n?: number): PDFPage;
flushPages(): void;
ref(data: {}): PDFKitReference;
addContent(data: any): PDFDocument
/**
* Deprecated
*/
write(fileName: string, fn: any): void;
/**
* Deprecated. Throws exception
*/
output(fn: any): void;
end(): void;
toString(): string;
}
}
declare module "pdfkit" {
var doc: PDFKit.PDFDocument;
export = doc;
}
declare module "pdfkit/js/gradient" {
var gradient : {
PDFGradient: PDFKit.PDFGradient;
PDFLinearGradient: PDFKit.PDFLinearGradient;
PDFRadialGradiant: PDFKit.PDFRadialGradient;
}
export = gradient;
}
declare module PDFKit {
/**
* Represent a single page in the PDF document
*/
interface PDFPage {
size: string;
layout: string;
margin: { top: number; left: number; bottom: number; right: number }|number;
width: number;
height: number;
document: PDFDocument;
content: PDFKitReference;
/**
* The page dictionnary
*/
dictionary: PDFKitReference;
fonts: any;
xobjects: any;
ext_gstates: any;
patterns: any;
annotations: any;
maxY(): number;
write(chunk: any): void;
end(): void;
}
}
declare module "pdfkit/js/page" {
var PDFKitPage: PDFKit.PDFPage
export = PDFKitPage
}
declare module PDFKit {
/** PDFReference - represents a reference to another object in the PDF object heirarchy */
class PDFKitReference {
id: number;
gen: number;
deflate:any;
compress: boolean;
uncompressedLength: number;
chunks: any[];
data: { Font?: any; XObject?: any; ExtGState?: any; Pattern: any; Annots: any };
document: PDFDocument;
constructor(document: PDFDocument, id: number, data: {});
initDeflate(): void;
write(chunk: any): void;
end(chunk: any): void;
finalize(): void;
toString(): string;
}
}
declare module "pdfkit/js/reference" {
var PDFKitReference: PDFKit.PDFKitReference;
export = PDFKitReference;
}
declare module "pdfkit/js/mixins/annotations" {
var PDFKitAnnotation: PDFKit.Mixins.PDFAnnotation<void>;
export = PDFKitAnnotation;
}
declare module "pdfkit/js/mixins/color" {
var PDFKitColor: PDFKit.Mixins.PDFColor<void>;
export = PDFKitColor;
}
declare module "pdfkit/js/mixins/fonts" {
var PDFKitFont: PDFKit.Mixins.PDFFont<void>;
export = PDFKitFont;
}
declare module "pdfkit/js/mixins/images" {
var PDFKitImage: PDFKit.Mixins.PDFImage;
export = PDFKitImage;
}
declare module "pdfkit/js/mixins/text" {
var PDFKitText: PDFKit.Mixins.PDFText<void>;
export = PDFKitText;
}
declare module "pdfkit/js/mixins/vector" {
var PDFKitVector: PDFKit.Mixins.PDFVector<void>;
export = PDFKitVector;
}