muhammara 2.4.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/muhammara.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare module 'muhammara' {
2
+ import EventEmitter = require("events");
2
3
  export type PosX = number;
3
4
  export type PosY = number;
4
5
  export type Width = number;
@@ -39,10 +40,10 @@ declare module 'muhammara' {
39
40
  options?: PDFRecryptOptions,
40
41
  ): void;
41
42
  export function recrypt(
42
- originalPdfStream: any,
43
- newPdfStream: any,
43
+ originalPdfStream: PDFRStreamForFile | PDFRStreamForBuffer,
44
+ newPdfStream: PDFWStreamForFile | PDFWStreamForBuffer,
44
45
  options?: PDFRecryptOptions,
45
- ): void; // TODO stream
46
+ ): void;
46
47
 
47
48
  export interface WriteStream {
48
49
  write(inBytesArray: any[]): number;
@@ -87,8 +88,10 @@ declare module 'muhammara' {
87
88
  writePage(): this;
88
89
  }
89
90
 
91
+ export type PDFImageType = 'JPG' | 'PDF' | 'PNG' | 'TIFF'
92
+
90
93
  export interface PDFRStreamForFile extends ReadStream {
91
- new (inPath: string): PDFRStreamForFile;
94
+ new (inPath: FilePath): PDFRStreamForFile;
92
95
  close(inCallback?: () => void): void;
93
96
  }
94
97
 
@@ -106,6 +109,36 @@ declare module 'muhammara' {
106
109
  width?: number;
107
110
  close?: boolean;
108
111
  }
112
+ export type TransformationMatrix = [a: number, b: number, c: number, d: number, e: number, f: number]
113
+
114
+
115
+ enum LineJoinStyle {
116
+ LINEJOIN_ROUND,
117
+ LINEJOIN_BEVEL,
118
+ LINEJOIN_MITER_VARIABLE,
119
+ LINEJOIN_MITER = 2,
120
+ LINEJOIN_MITER_FIXED = 3
121
+ }
122
+
123
+ enum EEncoding
124
+ {
125
+ EEncodingText = 'text',
126
+ EEncodingCode = 'code',
127
+ EEncodingHex = 'hex'
128
+ }
129
+
130
+ enum LineCapStyle {
131
+ LINECAP_BUTT = 0,
132
+ LINECAP_ROUND,
133
+ LINECAP_SQUARE
134
+ }
135
+
136
+ export interface TextRenderOptions {
137
+ encoding?: EEncoding
138
+ }
139
+
140
+ export type Glyph = Array<[number, number]>;
141
+
109
142
 
110
143
  export interface AbstractContentContext {
111
144
  b(): this;
@@ -118,13 +151,13 @@ declare module 'muhammara' {
118
151
  F(): this;
119
152
  fStar(): this;
120
153
  n(): this;
121
- m(x: number, y: number): this;
122
- l(x: number, y: number): this;
123
- c(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): number;
124
- v(x2: number, y2: number, x3: number, y3: number): this;
125
- y(x1: number, y1: number, x3: number, y3: number): this;
154
+ m(x: PosX, y: PosY): this;
155
+ l(x: PosX, y: PosY): this;
156
+ c(x1: PosX, y1: PosY, x2: PosX, y2: PosY, x3: PosX, y3: PosY): number;
157
+ v(x2: PosX, y2: PosY, x3: PosX, y3: PosY): this;
158
+ y(x1: PosX, y1: PosY, x3: PosX, y3: PosY): this;
126
159
  h(): this;
127
- re(left: number, bottom: number, width: number, height: number): this;
160
+ re(left: number, bottom: number, width: Width, height: Height): this;
128
161
  q(): this;
129
162
  Q(): this;
130
163
  /**
@@ -132,10 +165,10 @@ declare module 'muhammara' {
132
165
  * c d 0
133
166
  * e f 1
134
167
  */
135
- cm(a: number, b: number, c: number, d: number, e: number, f: number): this;
136
- w(lineWidth: number): this;
137
- J(lineCapStyle: number): this;
138
- j(lineJoinStyle: number): this;
168
+ cm(...args: TransformationMatrix): this;
169
+ w(lineWidth: Width): this;
170
+ J(lineCapStyle: LineCapStyle): this;
171
+ j(lineJoinStyle: LineJoinStyle): this;
139
172
  M(miterLimit: number): this;
140
173
  d(miterLimit: number[], dashPhase: number): this;
141
174
  ri(renderingIntentName: string): this;
@@ -146,9 +179,11 @@ declare module 'muhammara' {
146
179
  SC(...colorComponents: number[]): this;
147
180
  SCN(...parameters: any[]): this; // This can't be materialized in TypeScript
148
181
  ////SCN(...colorComponents: number[], patternName?: string): this;
182
+ SCN(colorComponents: number[], patternName?: string): this;
149
183
  sc(...colorComponents: number[]): this;
150
184
  scn(...parameters: any[]): this; // This can't be materialized in TypeScript
151
185
  ////scn(...colorComponents: number[], patternName?: string): this;
186
+ scn(colorComponents: number[], patternName?: string): this;
152
187
  G(gray: number): this;
153
188
  g(gray: number): this;
154
189
  RG(r: number, g: number, b: number): this;
@@ -157,7 +192,7 @@ declare module 'muhammara' {
157
192
  k(c: number, m: number, y: number, k: number): this;
158
193
  W(): this;
159
194
  WStar(): this;
160
- doXObject(xObject: string | any): this; // TODO
195
+ doXObject(xObject: string | FormXObject | ImageXObject): this;
161
196
  Tc(characterSpace: number): this;
162
197
  Tw(wordSpace: number): this;
163
198
  Tz(horizontalScaling: number): this;
@@ -171,18 +206,19 @@ declare module 'muhammara' {
171
206
  Tm(a: number, b: number, c: number, d: number, e: number, f: number): this;
172
207
  TStar(): this;
173
208
  Tf(fontReferenced: UsedFont | string, fontSize: number): this;
174
- Tj(text: string | any): this; // Glyph
175
- Quote(text: string | any): this; // Glyph
176
- DoubleQuote(wordSpacing: number, characterString: number, text: string | any): this; // Glyph
177
- TJ(stringsAndSpacing: any): this; // TODO
209
+ Tj(text: string | Glyph): this;
210
+ Quote(text: string | Glyph): this;
211
+ DoubleQuote(wordSpacing: number, characterString: number, text: string | Glyph): this;
212
+ TJ(value: string | Glyph, options?: TextRenderOptions): this;
178
213
  writeFreeCode(freeCode: string): this;
179
214
  drawPath(...parameters: any[]): this; // This can't be materialized in TypeScript
180
215
  ////drawPath(...xyPairs: number[], options: GraphicOptions): this;
181
- drawCircle(x: number, y: number, r: number, options: GraphicOptions): this;
182
- drawSquare(x: number, y: number, l: number, options: GraphicOptions): this;
183
- drawRectangle(x: number, y: number, w: number, h: number, options: GraphicOptions): this;
184
- writeText(text: string, x: number, y: number, options?: WriteTextOptions): this;
185
- drawImage(x: number, y: number, imagePath: string, options?: ImageOptions): this;
216
+ drawPath(xyPairs: Array<[number, number]>, options: GraphicOptions): this;
217
+ drawCircle(x: PosX, y: PosY, r: number, options: GraphicOptions): this;
218
+ drawSquare(x: PosX, y: PosY, l: number, options: GraphicOptions): this;
219
+ drawRectangle(x: PosX, y: PosY, w: number, h: number, options: GraphicOptions): this;
220
+ writeText(text: string, x: PosX, y: PosY, options?: WriteTextOptions): this;
221
+ drawImage(x: PosX, y: PosY, imagePath: string, options?: ImageOptions): this;
186
222
  }
187
223
 
188
224
  export interface TransformationObject {
@@ -215,7 +251,7 @@ declare module 'muhammara' {
215
251
  }
216
252
 
217
253
  export interface PDFStreamForResponse extends WriteStream {
218
- new (res: any): PDFStreamForResponse;
254
+ new (res: PDFRStreamForFile): PDFStreamForResponse;
219
255
  }
220
256
 
221
257
  export interface PDFWStreamForBuffer extends WriteStream {
@@ -233,7 +269,7 @@ declare module 'muhammara' {
233
269
 
234
270
  export interface PDFWriterToContinueOptions {
235
271
  modifiedFilePath?: string;
236
- alternativeStream?: any; // TODO
272
+ modifiedStream?: PDFRStreamForFile; // TODO
237
273
  log?: string;
238
274
  }
239
275
 
@@ -272,6 +308,10 @@ declare module 'muhammara' {
272
308
  export const ePDFPageBoxArtBox = 4;
273
309
  export type PDFPageBoxType = 0 | 1 | 2 | 3 | 4;
274
310
 
311
+ export const eRangeTypeAll = 0;
312
+ export const eRangeTypeSpecific = 1;
313
+ export type eRangeType = 0 | 1;
314
+
275
315
  export interface PDFWriterOptions {
276
316
  version?: EPDFVersion;
277
317
  log?: string;
@@ -289,18 +329,17 @@ declare module 'muhammara' {
289
329
  }
290
330
 
291
331
  export interface ResourcesDictionary {
292
- addFormXObjectMapping(formXObject: FormXObject): any;
293
- /*
294
- SET_PROTOTYPE_METHOD(t, "addImageXObjectMapping", AddImageXObjectMapping);
295
- SET_PROTOTYPE_METHOD(t, "addProcsetResource", AddProcsetResource);
296
- SET_PROTOTYPE_METHOD(t, "addExtGStateMapping", AddExtGStateMapping);
297
- SET_PROTOTYPE_METHOD(t, "addFontMapping", AddFontMapping);
298
- SET_PROTOTYPE_METHOD(t, "addColorSpaceMapping", AddColorSpaceMapping);
299
- SET_PROTOTYPE_METHOD(t, "addPatternMapping", AddPatternMapping);
300
- SET_PROTOTYPE_METHOD(t, "addPropertyMapping", AddPropertyMapping);
301
- SET_PROTOTYPE_METHOD(t, "addXObjectMapping", AddXObjectMapping);
302
- SET_PROTOTYPE_METHOD(t, "addShadingMapping", AddShadingMapping);
303
- */
332
+ addFormXObjectMapping(formXObject: FormXObject): string;
333
+ addImageXObjectMapping(imageXObject: ImageXObject|number): string;
334
+ addProcsetResource(procSetName: string): void;
335
+ addExtGStateMapping(stateObjectId: number): string;
336
+ addFontMapping(fontObjectId: number): string;
337
+ addColorSpaceMapping(colorSpaceId: number): string;
338
+ addPatternMapping(colorSpaceId: number): string;
339
+ addPatternMapping(patternObjectId: number): string;
340
+ addPropertyMapping(propertyObjectId: number): string;
341
+ addXObjectMapping(xObjectId: number): string;
342
+ addShadingMapping(xObjectId: number): string;
304
343
  }
305
344
 
306
345
  export type PDFBox = [PosX, PosY, Width, Height];
@@ -313,16 +352,6 @@ declare module 'muhammara' {
313
352
  artBox?: PDFBox;
314
353
  rotate?: number;
315
354
  getResourcesDictionary(): ResourcesDictionary;
316
-
317
- /*
318
- SET_ACCESSOR_METHODS(t, "mediaBox", GetMediaBox, SetMediaBox);
319
- SET_ACCESSOR_METHODS(t, "cropBox", GetCropBox, SetCropBox);
320
- SET_ACCESSOR_METHODS(t, "bleedBox", GetBleedBox, SetBleedBox);
321
- SET_ACCESSOR_METHODS(t, "trimBox", GetTrimBox, SetTrimBox);
322
- SET_ACCESSOR_METHODS(t, "artBox", GetArtBox, SetArtBox);
323
- SET_ACCESSOR_METHODS(t, "rotate",GetRotate, SetRotate);
324
- SET_PROTOTYPE_METHOD(t, "getResourcesDictionary", GetResourcesDictionary);
325
- */
326
355
  }
327
356
 
328
357
  export interface TextDimension {
@@ -348,21 +377,17 @@ declare module 'muhammara' {
348
377
  }
349
378
 
350
379
  export interface ByteReader {
351
- /*
352
- SET_PROTOTYPE_METHOD(t, "read", Read);
353
- SET_PROTOTYPE_METHOD(t, "notEnded", NotEnded);
354
- */
380
+ read(length: number): Array<number>;
381
+ notEnded(): boolean;
355
382
  }
356
383
 
357
384
  export interface ByteReaderWithPosition {
358
- /*
359
- SET_PROTOTYPE_METHOD(t, "read", Read);
360
- SET_PROTOTYPE_METHOD(t, "notEnded", NotEnded);
361
- SET_PROTOTYPE_METHOD(t, "setPosition", SetPosition);
362
- SET_PROTOTYPE_METHOD(t, "getCurrentPosition", GetCurrentPosition);
363
- SET_PROTOTYPE_METHOD(t, "setPositionFromEnd", SetPositionFromEnd);
364
- SET_PROTOTYPE_METHOD(t, "skip", Skip);
365
- */
385
+ read(length: number): Array<number>;
386
+ notEnded(): boolean;
387
+ getCurrentPosition(): number;
388
+ skip(length: number): this;
389
+ setPosition(position: number): this;
390
+ setPositionFromEnd(position: number): this;
366
391
  }
367
392
 
368
393
  export interface PDFReader {
@@ -370,24 +395,19 @@ declare module 'muhammara' {
370
395
  getPagesCount(): number;
371
396
  getTrailer(): PDFDictionary;
372
397
  queryDictionaryObject(dictionary: PDFDictionary, name: string): PDFObject;
373
- /*
374
- SET_PROTOTYPE_METHOD(t, "queryArrayObject", QueryArrayObject);
375
- */
398
+ queryArrayObject(objectList: PDFArray, index: number): undefined|PDFObject;
376
399
  parseNewObject(objectId: number): PDFObject;
377
- /*
378
- SET_PROTOTYPE_METHOD(t, "getPageObjectID", GetPageObjectID);
379
- SET_PROTOTYPE_METHOD(t, "parsePageDictionary", ParsePageDictionary);
380
- */
400
+ getPageObjectID(objectId: number): number;
401
+ parsePageDictionary(objectId: number): PDFDictionary;
381
402
  parsePage(page: number): PDFPageInput;
382
- /*
383
- SET_PROTOTYPE_METHOD(t, "getObjectsCount", GetObjectsCount);
384
- SET_PROTOTYPE_METHOD(t, "isEncrypted", IsEncrypted);
385
- SET_PROTOTYPE_METHOD(t, "getXrefSize", GetXrefSize);
386
- SET_PROTOTYPE_METHOD(t, "getXrefEntry", GetXrefEntry);
387
- SET_PROTOTYPE_METHOD(t, "getXrefPosition", GetXrefPosition);
388
- SET_PROTOTYPE_METHOD(t, "startReadingFromStream", StartReadingFromStream);
389
- SET_PROTOTYPE_METHOD(t, "getParserStream", GetParserStream);
390
- */
403
+ getObjectsCount(): number;
404
+ isEncrypted(): boolean;
405
+ getXrefSize(): number;
406
+ getXrefEntry(objectId: number): { objectPosition: number, revision: number, type: number };
407
+ getXrefSize(): number;
408
+ getXrefPosition(objectId: number): number;
409
+ startReadingFromStream(inputStream: PDFStreamInput): ByteReader;
410
+ getParserStream(): ByteReaderWithPosition;
391
411
  }
392
412
 
393
413
  export interface PDFStream {
@@ -395,15 +415,11 @@ declare module 'muhammara' {
395
415
  }
396
416
 
397
417
  export interface PDFNull extends PDFObject {
398
- /*
399
- SET_ACCESSOR_METHOD(t, "value", GetValue);
400
- */
418
+ value: void;
401
419
  }
402
420
 
403
421
  export interface PDFName extends PDFObject {
404
- /*
405
- SET_ACCESSOR_METHOD(t, "value", GetValue);
406
- */
422
+ value: string;
407
423
  }
408
424
 
409
425
  export interface PDFLiteralString extends PDFObject {
@@ -412,9 +428,7 @@ declare module 'muhammara' {
412
428
  }
413
429
 
414
430
  export interface PDFInteger extends PDFObject {
415
- /*
416
- SET_ACCESSOR_METHOD(t, "value", GetValue);
417
- */
431
+ value: number;
418
432
  }
419
433
 
420
434
  export interface PDFIndirectObjectReference extends PDFObject {
@@ -423,9 +437,7 @@ declare module 'muhammara' {
423
437
  }
424
438
 
425
439
  export interface PDFHexString extends PDFObject {
426
- /*
427
- SET_ACCESSOR_METHOD(t, "value", GetValue);
428
- */
440
+ value: string;
429
441
  }
430
442
 
431
443
  export interface PDFDictionary extends PDFObject {
@@ -435,151 +447,145 @@ declare module 'muhammara' {
435
447
  }
436
448
 
437
449
  export interface PDFDate {
438
- /*
439
- SET_PROTOTYPE_METHOD(t, "toString", ToString);
440
- SET_PROTOTYPE_METHOD(t, "setToCurrentTime", SetToCurrentTime);
441
- */
450
+ toString(): string;
451
+ setToCurrentTime(): this;
442
452
  }
443
453
 
444
454
  export interface PDFBoolean extends PDFObject {
445
- /*
446
- SET_ACCESSOR_METHOD(t, "value", GetValue);
447
- */
455
+ value: boolean;
448
456
  }
449
457
 
450
458
  export interface PDFArray extends PDFObject {
451
- /*
452
- SET_PROTOTYPE_METHOD(t, "toJSArray", ToJSArray);
453
- SET_PROTOTYPE_METHOD(t, "queryObject", QueryObject);
454
- SET_PROTOTYPE_METHOD(t, "getLength", GetLength);
455
- */
459
+ toJSArray(): Array<any>;
460
+ queryObject(index: number): any;
461
+ getLength(): number;
456
462
  }
457
463
 
458
464
  export interface OutputFile {
459
- /*
460
- SET_PROTOTYPE_METHOD(t, "openFile", OpenFile);
461
- SET_PROTOTYPE_METHOD(t, "closeFile", CloseFile);
462
- SET_PROTOTYPE_METHOD(t, "getFilePath", GetFilePath);
463
- SET_PROTOTYPE_METHOD(t, "getOutputStream", GetOutputStream);
464
- */
465
+ openFile(filePath: FilePath, append?: boolean): void;
466
+ closeFile(): void;
467
+ getFilePath(): string|undefined;
468
+ getOutputStream(): ByteWriterWithPosition|undefined;
465
469
  }
466
470
 
467
471
  export interface InputFile {
468
- /*
469
- SET_PROTOTYPE_METHOD(t, "openFile", OpenFile);
470
- SET_PROTOTYPE_METHOD(t, "closeFile", CloseFile);
471
- SET_PROTOTYPE_METHOD(t, "getFilePath", GetFilePath);
472
- SET_PROTOTYPE_METHOD(t, "getFileSize", GetFileSize);
473
- SET_PROTOTYPE_METHOD(t, "getInputStream", GetInputStream);
474
- */
472
+ openFile(filePath: FilePath): void;
473
+ closeFile(): void;
474
+ getFilePath(): string|undefined;
475
+ getFileSize(): number|undefined;
476
+ getInputStream(): ByteReaderWithPosition|undefined;
475
477
  }
476
478
 
479
+ export enum EInfoTrapped {
480
+ EInfoTrappedTrue,
481
+ EInfoTrappedFalse,
482
+ EInfoTrappedUnknown
483
+ }
484
+
477
485
  export interface InfoDictionary {
478
- /*
479
- SET_PROTOTYPE_METHOD(t, "addAdditionalInfoEntry", AddAdditionalInfoEntry);
480
- SET_PROTOTYPE_METHOD(t, "removeAdditionalInfoEntry", RemoveAdditionalInfoEntry);
481
- SET_PROTOTYPE_METHOD(t, "clearAdditionalInfoEntries", ClearAdditionalInfoEntries);
482
- SET_PROTOTYPE_METHOD(t, "getAdditionalInfoEntry", GetAdditionalInfoEntry);
483
- SET_PROTOTYPE_METHOD(t, "getAdditionalInfoEntries", GetAdditionalInfoEntries);
484
- SET_PROTOTYPE_METHOD(t, "setCreationDate", SetCreationDate);
485
- SET_PROTOTYPE_METHOD(t, "setModDate", SetModDate);
486
- SET_ACCESSOR_METHODS(t, "title", GetTitle, SetTitle);
487
- SET_ACCESSOR_METHODS(t, "author", GetAuthor, SetAuthor);
488
- SET_ACCESSOR_METHODS(t, "subject", GetSubject, SetSubject);
489
- SET_ACCESSOR_METHODS(t, "keywords", GetKeywords, SetKeywords);
490
- SET_ACCESSOR_METHODS(t, "creator", GetCreator, SetCreator);
491
- SET_ACCESSOR_METHODS(t, "producer", GetProducer, SetProducer);
492
- SET_ACCESSOR_METHODS(t, "trapped", GetTrapped, SetTrapped);
493
- */
486
+ addAdditionalInfoEntry(key: string, value: string): void;
487
+ removeAdditionalInfoEntry(key: string): void;
488
+ clearAdditionalInfoEntries(): void;
489
+ getAdditionalInfoEntry(key: string): string;
490
+ getAdditionalInfoEntries(key: string): {[key: string]: string}
491
+ setCreationDate(date: string | Date): void;
492
+ setModDate(date: string | Date): void;
493
+
494
+ title: string;
495
+ author: string;
496
+ subject: string;
497
+ keywords: string;
498
+ creator: string;
499
+ producer: string;
500
+ trapped: EInfoTrapped;
494
501
  }
495
502
 
496
503
  export interface ImageXObject {
497
- /*
498
- SET_ACCESSOR_METHOD(t, "id", GetID);
499
- */
504
+ id: number;
500
505
  }
501
506
 
502
507
  export interface FormObject {
503
- /*
504
- SET_ACCESSOR_METHOD(t,"id", GetID);
505
- SET_PROTOTYPE_METHOD(t, "getContentContext", GetContentContext);
506
- SET_PROTOTYPE_METHOD(t, "getResourcesDictinary", GetResourcesDictionary);
507
- SET_PROTOTYPE_METHOD(t, "getContentStream", GetContentStream);
508
- */
508
+ id: number;
509
+ getContentContext(): XObjectContentContext;
510
+ getResourcesDictinary(): ResourcesDictionary;
511
+ getContentStream(): PDFStream;
509
512
  }
510
513
 
511
514
  export interface DocumentCopyingContext {
512
515
  createFormXObjectFromPDFPage(
513
516
  sourcePageIndex: number,
514
517
  ePDFPageBox: PDFPageBoxType | PDFBox,
518
+ transformation?: TransformationMatrix
515
519
  ): number;
516
520
  mergePDFPageToPage(target: PDFPage, sourcePageIndex: number): void;
517
521
  appendPDFPageFromPDF(sourcePageNumber: number): number; // stream start bytes?
518
- mergePDFPageToFormXObject(sourcePage: PDFPage, targetPageNumber: number): any;
519
- /*
520
- SET_PROTOTYPE_METHOD(t, "getSourceDocumentParser", GetSourceDocumentParser);
521
- SET_PROTOTYPE_METHOD(t, "copyDirectObjectAsIs", CopyDirectObjectAsIs);
522
- SET_PROTOTYPE_METHOD(t, "copyObject", CopyObject);
523
- SET_PROTOTYPE_METHOD(t, "copyDirectObjectWithDeepCopy", CopyDirectObjectWithDeepCopy);
524
- SET_PROTOTYPE_METHOD(t, "copyNewObjectsForDirectObject", CopyNewObjectsForDirectObject);
525
- SET_PROTOTYPE_METHOD(t, "getCopiedObjectID", GetCopiedObjectID);
526
- SET_PROTOTYPE_METHOD(t, "getCopiedObjects", GetCopiedObjects);
527
- SET_PROTOTYPE_METHOD(t, "replaceSourceObjects", ReplaceSourceObjects);
528
- SET_PROTOTYPE_METHOD(t, "getSourceDocumentStream", GetSourceDocumentStream);
529
- */
522
+ mergePDFPageToFormXObject(sourcePage: PDFPage, targetPageNumber: number): void;
523
+ getSourceDocumentParser(input: FilePath | ReadStream, options?: PDFReaderOptions): PDFReader;
524
+ copyDirectObjectAsIs(objectToCopy: PDFObject): void;
525
+ copyObject(objectId: number): number;
526
+ copyDirectObjectWithDeepCopy(objectToCopy: PDFObject): Array<number>;
527
+ copyNewObjectsForDirectObject(objectIds: Array<number>): void;
528
+ getCopiedObjectID(objectId: number): number;
529
+ getCopiedObjects(): {[key: string]: number};
530
+ replaceSourceObjects(replaceMap: {[key: string]: number}): void;
531
+ getSourceDocumentStream(): ByteReaderWithPosition;
530
532
  }
531
533
 
532
534
  export interface DocumentContext {
533
- /*
534
- SET_PROTOTYPE_METHOD(t, "getInfoDictionary", GetInfoDictionary);
535
- */
535
+ getInfoDictionary(): InfoDictionary;
536
536
  }
537
537
 
538
538
  export interface DictionaryContext {
539
- /*
540
- SET_PROTOTYPE_METHOD(t, "writeKey", WriteKey);
541
- SET_PROTOTYPE_METHOD(t, "writeNameValue", WriteNameValue);
542
- SET_PROTOTYPE_METHOD(t, "writeRectangleValue", WriteRectangleValue);
543
- SET_PROTOTYPE_METHOD(t, "writeLiteralStringValue", WriteLiteralStringValue);
544
- SET_PROTOTYPE_METHOD(t, "writeBooleanValue", WriteBooleanValue);
545
- SET_PROTOTYPE_METHOD(t, "writeObjectReferenceValue", WriteObjectReferenceValue);
546
- */
539
+ writeKey(): DictionaryContext;
540
+ writeNameValue(nameValue: string): this;
541
+ writeRectangleValue(values: Array<number>): this;
542
+ writeRectangleValue(a: number, b: number, c: number, d: number): this;
543
+ writeLiteralStringValue(literal: Array<number>|string): this;
544
+ writeBooleanValue(boolValue: boolean): this;
545
+ writeObjectReferenceValue(objectId: number): this;
547
546
  }
548
547
 
549
548
  export interface ByteWriterWithPosition {
550
- /*
551
- SET_PROTOTYPE_METHOD(t, "write", Write);
552
- SET_PROTOTYPE_METHOD(t, "getCurrentPosition", GetCurrentPosition);
553
- */
549
+ write(bytes: Array<number>): number;
550
+ getCurrentPosition(): number;
551
+ }
552
+
553
+ export type eTokenSeparatorSpace = 0;
554
+ export type eTokenSeparatorEndLine = 1;
555
+ export type eTokenSeparatorNone = 2;
556
+
557
+ enum ETokenSeparator {
558
+ eTokenSeparatorSpace,
559
+ eTokenSeparatorEndLine,
560
+ eTokenSeparatorNone
554
561
  }
555
562
 
556
563
  export interface ObjectsContext {
557
- /*
558
- SET_PROTOTYPE_METHOD(t, "allocateNewObjectID", AllocateNewObjectID);
559
- SET_PROTOTYPE_METHOD(t, "startDictionary", StartDictionary);
560
- SET_PROTOTYPE_METHOD(t, "startArray", StartArray);
561
- SET_PROTOTYPE_METHOD(t, "writeNumber", WriteNumber);
562
- SET_PROTOTYPE_METHOD(t, "endArray", EndArray);
563
- SET_PROTOTYPE_METHOD(t, "endLine", EndLine);
564
- SET_PROTOTYPE_METHOD(t, "endDictionary", EndDictionary);
565
- SET_PROTOTYPE_METHOD(t, "endIndirectObject", EndIndirectObject);
566
- SET_PROTOTYPE_METHOD(t, "writeIndirectObjectReference", WriteIndirectObjectReference);
567
- SET_PROTOTYPE_METHOD(t, "startNewIndirectObject", StartNewIndirectObject);
568
- SET_PROTOTYPE_METHOD(t, "startModifiedIndirectObject", StartModifiedIndirectObject);
569
- SET_PROTOTYPE_METHOD(t, "deleteObject", DeleteObject);
570
- SET_PROTOTYPE_METHOD(t, "writeName", WriteName);
571
- SET_PROTOTYPE_METHOD(t, "writeLiteralString", WriteLiteralString);
572
- SET_PROTOTYPE_METHOD(t, "writeHexString", WriteHexString);
573
- SET_PROTOTYPE_METHOD(t, "writeBoolean", WriteBoolean);
574
- SET_PROTOTYPE_METHOD(t, "writeKeyword", WriteKeyword);
575
- SET_PROTOTYPE_METHOD(t, "writeComment", WriteComment);
576
- SET_PROTOTYPE_METHOD(t, "setCompressStreams", SetCompressStreams);
577
- SET_PROTOTYPE_METHOD(t, "startPDFStream", StartPDFStream);
578
- SET_PROTOTYPE_METHOD(t, "startUnfilteredPDFStream", StartUnfilteredPDFStream);
579
- SET_PROTOTYPE_METHOD(t, "endPDFStream", EndPDFStream);
580
- SET_PROTOTYPE_METHOD(t, "startFreeContext", StartFreeContext);
581
- SET_PROTOTYPE_METHOD(t, "endFreeContext", EndFreeContext);
582
- */
564
+ allocateNewObjectID(): FormXObjectId;
565
+ startDictionary(): DictionaryContext;
566
+ startArray(): this;
567
+ writeNumber(value: number): this;
568
+ endArray(endType?: ETokenSeparator): this;
569
+ endLine(): this;
570
+ endDictionary(dictionary: DictionaryContext): this;
571
+ endIndirectObject(): this;
572
+ writeIndirectObjectReference(objectId: FormXObjectId, generationNumber?: number): this;
573
+ startNewIndirectObject(objectId: FormXObjectId): this;
574
+ startNewIndirectObject(): FormXObjectId;
575
+ startModifiedIndirectObject(objectId: FormXObjectId): this;
576
+ deleteObject(objectId: FormXObjectId): this;
577
+ writeName(name: string): this;
578
+ writeLiteralString(literal: string | number[]): this;
579
+ writeHexString(hex: string | number[]): this;
580
+ writeBoolean(bool: boolean): this;
581
+ writeKeyword(keyword: string): this;
582
+ writeComment(comment: string): this;
583
+ setCompressStreams(compress: true): this;
584
+ startPDFStream(dictionaryContext: DictionaryContext): PDFStream;
585
+ startUnfilteredPDFStream(stream: DictionaryContext): PDFStream;
586
+ endPDFStream(stream: PDFStream): this;
587
+ startFreeContext(): ByteWriterWithPosition;
588
+ endFreeContext(): this;
583
589
  }
584
590
 
585
591
  export interface PDFObject {
@@ -601,30 +607,22 @@ SET_PROTOTYPE_METHOD(t, "allocateNewObjectID", AllocateNewObjectID);
601
607
  }
602
608
 
603
609
  export interface PDFReal extends PDFObject {
604
- /*
605
- SET_ACCESSOR_METHOD(t, "value", GetValue);
606
- */
610
+ value: number;
607
611
  }
608
612
 
609
613
  export interface PDFSymbol extends PDFObject {
610
- /*
611
- SET_ACCESSOR_METHOD(t, "value", GetValue);
612
- */
614
+ value: string;
613
615
  }
614
616
 
615
617
  export interface PDFStreamInput extends PDFObject {
616
- /*
617
- SET_PROTOTYPE_METHOD(t, "getDictionary", GetDictionary);
618
- SET_PROTOTYPE_METHOD(t, "getStreamContentStart", GetStreamContentStart);
619
- */
618
+ getDictionary(): PDFDictionary;
619
+ getStreamContentStart(): number;
620
620
  }
621
621
 
622
622
  export interface PDFTextString {
623
- /*
624
- SET_PROTOTYPE_METHOD(t, "toBytesArray", ToBytesArray);
625
- SET_PROTOTYPE_METHOD(t, "toString", ToString);
626
- SET_PROTOTYPE_METHOD(t, "fromString", FromString);
627
- */
623
+ toBytesArray(): Array<number>;
624
+ toString(): string;
625
+ fromString(value: string): void;
628
626
  }
629
627
 
630
628
  export interface PageContentContext extends AbstractContentContext {
@@ -632,56 +630,80 @@ SET_PROTOTYPE_METHOD(t, "allocateNewObjectID", AllocateNewObjectID);
632
630
  getAssociatedPage(): PDFPage;
633
631
  }
634
632
 
633
+ export interface JPEGInformation {
634
+ samplesWidth: number;
635
+ samplesHeight: number;
636
+ colorComponentsCount: number;
637
+ JFIFInformationExists: boolean;
638
+ JFIFUnit?: number;
639
+ JFIFXDensity?: number;
640
+ JFIFYDensity?: number;
641
+ ExifInformationExists: boolean;
642
+ ExifUnit?: number;
643
+ ExifXDensity?: number;
644
+ ExifYDensity?: number;
645
+ PhotoshopInformationExists: boolean;
646
+ PhotoshopXDensity?: number;
647
+ PhotoshopYDensity?: number;
648
+ }
649
+
650
+ export type PDFRectangle = [lowerLeftX: number, lowerLeftY: number, upperRightX: number, upperRightY: number];
651
+
652
+ export interface MergeOptions {
653
+ password?: string;
654
+ type?: eRangeType;
655
+ specificRanges?: [[number, number]];
656
+ }
657
+
658
+ export interface AppendOptions extends MergeOptions {}
659
+
660
+ export type inInterPagesCallback = () => {}
661
+
662
+
635
663
  export interface PDFWriter {
636
664
  end(): PDFWriter;
637
- createPage(x: number, y: number, width: number, height: number): PDFPage;
665
+ createPage(x: PosX, y: PosY, width: Width, height: Height): PDFPage;
638
666
  createPage(): PDFPage;
639
667
  writePage(page: PDFPage): this;
640
668
  writePageAndReturnID(page: PDFPage): number;
641
669
  startPageContentContext(page: PDFPage): PageContentContext;
642
670
  pausePageContentContext(pageContextContext: PageContentContext): this;
643
- /*
644
- createFormXObject();
645
- endFormXObject();
646
- createFormXObjectFromJPG();
647
- */
648
- // TODO: test streamas
649
- createFormXObjectFromPNG(filePath: FilePath | PDFRStreamForFile): FormXObject;
650
-
671
+ createFormXObject(x: PosX, y: PosY, width: Width, height: Height, objectId?: FormXObjectId): FormXObject;
672
+ endFormXObject(formXObject: FormXObject): this;
673
+ createFormXObjectFromJPG(file: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
651
674
  getFontForFile(inFontFilePath: FilePath, index?: number): UsedFont;
652
675
  getFontForFile(
653
676
  inFontFilePath: FilePath,
654
677
  inOptionalMetricsFile?: string,
655
678
  index?: number,
656
679
  ): UsedFont;
657
- /*
658
- attachURLLinktoCurrentPage();
659
- shutdown();
660
- createFormXObjectFromTIFF();
661
- createImageXObjectFromJPG();
662
- retrieveJPGImageInformation();
663
- getObjectsContext();
664
- getDocumentContext();
665
- */
666
- appendPDFPagesFromPDF(source: FilePath | ReadStream): number[];
667
- /*
668
- mergePDFPagesToPage();
669
- */
680
+ attachURLLinktoCurrentPage(url: string, x: PosX, y: PosY, width: Width, height: Height): this;
681
+ shutdown(outputFilePath: FilePath): this;
682
+ createFormXObjectFromTIFF(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
683
+ createImageXObjectFromJPG(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): ImageXObject;
684
+ createFormXObjectFromPNG(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
685
+ retrieveJPGImageInformation(filePath: FilePath): JPEGInformation;
686
+ getObjectsContext(): ObjectsContext;
687
+ getDocumentContext(): DocumentContext;
688
+ appendPDFPagesFromPDF(source: FilePath | ReadStream, options?: AppendOptions): number[];
689
+ mergePDFPagesToPage(page: PDFPage, file: FilePath | PDFRStreamForFile, options?: MergeOptions, callback?: inInterPagesCallback): this;
690
+ mergePDFPagesToPage(page: PDFPage, file: FilePath | PDFRStreamForFile, callback?: inInterPagesCallback) : this;
670
691
  createPDFCopyingContext(source: FilePath | ReadStream): DocumentCopyingContext;
671
- /*
672
- createFormXObjectsFromPDF();
673
- createPDFCopyingContextForModifiedFile();
674
- createPDFTextString();
675
- createPDFDate();
676
- */
692
+ createFormXObjectsFromPDF(file: FilePath, box?: PDFBox | PDFPageBoxType, options?: MergeOptions, transformation?: TransformationMatrix, objectIds?: FormXObjectId[]): FormXObjectId[];
693
+ createPDFCopyingContextForModifiedFile(): DocumentCopyingContext;
694
+ createPDFTextString(): PDFTextString;
695
+ createPDFDate(): PDFDate;
677
696
  getImageDimensions(inFontFilePath: FilePath | ReadStream): RectangleDimension;
678
- /*
679
- getImagePagesCount();
680
- getImageType();
681
- getModifiedFileParser();
682
- getModifiedInputFile();
683
- getOutputFile();
684
- registerAnnotationReferenceForNextPageWrite();
685
- */
697
+ getImagePagesCount(imagePath: FilePath, options?: {password?: string}): number;
698
+ getImageType(imagePath: FilePath): PDFImageType | undefined;
699
+ getModifiedFileParser(): PDFReader;
700
+ getModifiedInputFile(): InputFile;
701
+ getOutputFile(): OutputFile;
702
+ registerAnnotationReferenceForNextPageWrite(annotationId: number): this;
703
+ requireCatalogUpdate(): void;
704
+
705
+ /* Js Extensions (in muhammara.js) */
706
+ getEvents(): EventEmitter;
707
+ triggerDocumentExtensionEvent(eventName: string | symbol, eventParams: any): void;
686
708
  }
687
709
  }