muhammara 2.3.0 → 2.6.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/muhammara.d.ts +261 -242
  3. package/muhammara.js +1 -1
  4. package/node_modules/concat-map/package.json +1 -1
  5. package/node_modules/console-control-strings/package.json +1 -1
  6. package/node_modules/delegates/package.json +1 -1
  7. package/node_modules/fs.realpath/package.json +1 -1
  8. package/node_modules/glob/common.js +2 -0
  9. package/node_modules/glob/glob.js +4 -1
  10. package/node_modules/glob/package.json +9 -6
  11. package/node_modules/glob/sync.js +6 -3
  12. package/node_modules/has-unicode/package.json +1 -1
  13. package/node_modules/inflight/package.json +1 -1
  14. package/node_modules/minimatch/package.json +5 -5
  15. package/node_modules/minipass/LICENSE +1 -1
  16. package/node_modules/minipass/README.md +122 -7
  17. package/node_modules/minipass/index.d.ts +149 -0
  18. package/node_modules/minipass/index.js +191 -102
  19. package/node_modules/minipass/package.json +23 -7
  20. package/node_modules/object-assign/package.json +1 -1
  21. package/node_modules/once/package.json +1 -1
  22. package/node_modules/path-is-absolute/package.json +1 -1
  23. package/node_modules/set-blocking/package.json +1 -1
  24. package/node_modules/tr46/package.json +1 -1
  25. package/node_modules/util-deprecate/package.json +1 -1
  26. package/node_modules/webidl-conversions/package.json +1 -1
  27. package/node_modules/whatwg-url/package.json +1 -1
  28. package/node_modules/wrappy/package.json +1 -1
  29. package/package.json +2 -1
  30. package/src/DocumentCopyingContextDriver.cpp +9 -9
  31. package/src/ObjectByteWriterWithPosition.cpp +15 -7
  32. package/src/ObjectsContextDriver.cpp +1 -1
  33. package/src/deps/PDFWriter/PDFDocumentHandler.cpp +4 -0
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;
@@ -157,7 +190,7 @@ declare module 'muhammara' {
157
190
  k(c: number, m: number, y: number, k: number): this;
158
191
  W(): this;
159
192
  WStar(): this;
160
- doXObject(xObject: string | any): this; // TODO
193
+ doXObject(xObject: string | FormXObject | ImageXObject): this;
161
194
  Tc(characterSpace: number): this;
162
195
  Tw(wordSpace: number): this;
163
196
  Tz(horizontalScaling: number): this;
@@ -171,18 +204,18 @@ declare module 'muhammara' {
171
204
  Tm(a: number, b: number, c: number, d: number, e: number, f: number): this;
172
205
  TStar(): this;
173
206
  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
207
+ Tj(text: string | Glyph): this;
208
+ Quote(text: string | Glyph): this;
209
+ DoubleQuote(wordSpacing: number, characterString: number, text: string | Glyph): this;
210
+ TJ(value: string | Glyph, options?: TextRenderOptions): this;
178
211
  writeFreeCode(freeCode: string): this;
179
212
  drawPath(...parameters: any[]): this; // This can't be materialized in TypeScript
180
213
  ////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;
214
+ drawCircle(x: PosX, y: PosY, r: number, options: GraphicOptions): this;
215
+ drawSquare(x: PosX, y: PosY, l: number, options: GraphicOptions): this;
216
+ drawRectangle(x: PosX, y: PosY, w: number, h: number, options: GraphicOptions): this;
217
+ writeText(text: string, x: PosX, y: PosY, options?: WriteTextOptions): this;
218
+ drawImage(x: PosX, y: PosY, imagePath: string, options?: ImageOptions): this;
186
219
  }
187
220
 
188
221
  export interface TransformationObject {
@@ -215,7 +248,7 @@ declare module 'muhammara' {
215
248
  }
216
249
 
217
250
  export interface PDFStreamForResponse extends WriteStream {
218
- new (res: any): PDFStreamForResponse;
251
+ new (res: PDFRStreamForFile): PDFStreamForResponse;
219
252
  }
220
253
 
221
254
  export interface PDFWStreamForBuffer extends WriteStream {
@@ -233,7 +266,7 @@ declare module 'muhammara' {
233
266
 
234
267
  export interface PDFWriterToContinueOptions {
235
268
  modifiedFilePath?: string;
236
- alternativeStream?: any; // TODO
269
+ modifiedStream?: PDFRStreamForFile; // TODO
237
270
  log?: string;
238
271
  }
239
272
 
@@ -272,6 +305,10 @@ declare module 'muhammara' {
272
305
  export const ePDFPageBoxArtBox = 4;
273
306
  export type PDFPageBoxType = 0 | 1 | 2 | 3 | 4;
274
307
 
308
+ export const eRangeTypeAll = 0;
309
+ export const eRangeTypeSpecific = 1;
310
+ export type eRangeType = 0 | 1;
311
+
275
312
  export interface PDFWriterOptions {
276
313
  version?: EPDFVersion;
277
314
  log?: string;
@@ -289,18 +326,17 @@ declare module 'muhammara' {
289
326
  }
290
327
 
291
328
  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
- */
329
+ addFormXObjectMapping(formXObject: FormXObject): string;
330
+ addImageXObjectMapping(imageXObject: ImageXObject|number): string;
331
+ addProcsetResource(procSetName: string): void;
332
+ addExtGStateMapping(stateObjectId: number): string;
333
+ addFontMapping(fontObjectId: number): string;
334
+ addColorSpaceMapping(colorSpaceId: number): string;
335
+ addPatternMapping(colorSpaceId: number): string;
336
+ addPatternMapping(patternObjectId: number): string;
337
+ addPropertyMapping(propertyObjectId: number): string;
338
+ addXObjectMapping(xObjectId: number): string;
339
+ addShadingMapping(xObjectId: number): string;
304
340
  }
305
341
 
306
342
  export type PDFBox = [PosX, PosY, Width, Height];
@@ -313,16 +349,6 @@ declare module 'muhammara' {
313
349
  artBox?: PDFBox;
314
350
  rotate?: number;
315
351
  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
352
  }
327
353
 
328
354
  export interface TextDimension {
@@ -348,21 +374,17 @@ declare module 'muhammara' {
348
374
  }
349
375
 
350
376
  export interface ByteReader {
351
- /*
352
- SET_PROTOTYPE_METHOD(t, "read", Read);
353
- SET_PROTOTYPE_METHOD(t, "notEnded", NotEnded);
354
- */
377
+ read(length: number): Array<number>;
378
+ notEnded(): boolean;
355
379
  }
356
380
 
357
381
  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
- */
382
+ read(length: number): Array<number>;
383
+ notEnded(): boolean;
384
+ getCurrentPosition(): number;
385
+ skip(length: number): this;
386
+ setPosition(position: number): this;
387
+ setPositionFromEnd(position: number): this;
366
388
  }
367
389
 
368
390
  export interface PDFReader {
@@ -370,24 +392,19 @@ declare module 'muhammara' {
370
392
  getPagesCount(): number;
371
393
  getTrailer(): PDFDictionary;
372
394
  queryDictionaryObject(dictionary: PDFDictionary, name: string): PDFObject;
373
- /*
374
- SET_PROTOTYPE_METHOD(t, "queryArrayObject", QueryArrayObject);
375
- */
395
+ queryArrayObject(objectList: PDFArray, index: number): undefined|PDFObject;
376
396
  parseNewObject(objectId: number): PDFObject;
377
- /*
378
- SET_PROTOTYPE_METHOD(t, "getPageObjectID", GetPageObjectID);
379
- SET_PROTOTYPE_METHOD(t, "parsePageDictionary", ParsePageDictionary);
380
- */
397
+ getPageObjectID(objectId: number): number;
398
+ parsePageDictionary(objectId: number): PDFDictionary;
381
399
  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
- */
400
+ getObjectsCount(): number;
401
+ isEncrypted(): boolean;
402
+ getXrefSize(): number;
403
+ getXrefEntry(objectId: number): { objectPosition: number, revision: number, type: number };
404
+ getXrefSize(): number;
405
+ getXrefPosition(objectId: number): number;
406
+ startReadingFromStream(inputStream: PDFStreamInput): ByteReader;
407
+ getParserStream(): ByteReaderWithPosition;
391
408
  }
392
409
 
393
410
  export interface PDFStream {
@@ -395,15 +412,11 @@ declare module 'muhammara' {
395
412
  }
396
413
 
397
414
  export interface PDFNull extends PDFObject {
398
- /*
399
- SET_ACCESSOR_METHOD(t, "value", GetValue);
400
- */
415
+ value: void;
401
416
  }
402
417
 
403
418
  export interface PDFName extends PDFObject {
404
- /*
405
- SET_ACCESSOR_METHOD(t, "value", GetValue);
406
- */
419
+ value: string;
407
420
  }
408
421
 
409
422
  export interface PDFLiteralString extends PDFObject {
@@ -412,9 +425,7 @@ declare module 'muhammara' {
412
425
  }
413
426
 
414
427
  export interface PDFInteger extends PDFObject {
415
- /*
416
- SET_ACCESSOR_METHOD(t, "value", GetValue);
417
- */
428
+ value: number;
418
429
  }
419
430
 
420
431
  export interface PDFIndirectObjectReference extends PDFObject {
@@ -423,9 +434,7 @@ declare module 'muhammara' {
423
434
  }
424
435
 
425
436
  export interface PDFHexString extends PDFObject {
426
- /*
427
- SET_ACCESSOR_METHOD(t, "value", GetValue);
428
- */
437
+ value: string;
429
438
  }
430
439
 
431
440
  export interface PDFDictionary extends PDFObject {
@@ -435,151 +444,145 @@ declare module 'muhammara' {
435
444
  }
436
445
 
437
446
  export interface PDFDate {
438
- /*
439
- SET_PROTOTYPE_METHOD(t, "toString", ToString);
440
- SET_PROTOTYPE_METHOD(t, "setToCurrentTime", SetToCurrentTime);
441
- */
447
+ toString(): string;
448
+ setToCurrentTime(): this;
442
449
  }
443
450
 
444
451
  export interface PDFBoolean extends PDFObject {
445
- /*
446
- SET_ACCESSOR_METHOD(t, "value", GetValue);
447
- */
452
+ value: boolean;
448
453
  }
449
454
 
450
455
  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
- */
456
+ toJSArray(): Array<any>;
457
+ queryObject(index: number): any;
458
+ getLength(): number;
456
459
  }
457
460
 
458
461
  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
- */
462
+ openFile(filePath: FilePath, append?: boolean): void;
463
+ closeFile(): void;
464
+ getFilePath(): string|undefined;
465
+ getOutputStream(): ByteWriterWithPosition|undefined;
465
466
  }
466
467
 
467
468
  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
- */
469
+ openFile(filePath: FilePath): void;
470
+ closeFile(): void;
471
+ getFilePath(): string|undefined;
472
+ getFileSize(): number|undefined;
473
+ getInputStream(): ByteReaderWithPosition|undefined;
475
474
  }
476
475
 
476
+ export enum EInfoTrapped {
477
+ EInfoTrappedTrue,
478
+ EInfoTrappedFalse,
479
+ EInfoTrappedUnknown
480
+ }
481
+
477
482
  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
- */
483
+ addAdditionalInfoEntry(key: string, value: string): void;
484
+ removeAdditionalInfoEntry(key: string): void;
485
+ clearAdditionalInfoEntries(): void;
486
+ getAdditionalInfoEntry(key: string): string;
487
+ getAdditionalInfoEntries(key: string): {[key: string]: string}
488
+ setCreationDate(date: string | Date): void;
489
+ setModDate(date: string | Date): void;
490
+
491
+ title: string;
492
+ author: string;
493
+ subject: string;
494
+ keywords: string;
495
+ creator: string;
496
+ producer: string;
497
+ trapped: EInfoTrapped;
494
498
  }
495
499
 
496
500
  export interface ImageXObject {
497
- /*
498
- SET_ACCESSOR_METHOD(t, "id", GetID);
499
- */
501
+ id: number;
500
502
  }
501
503
 
502
504
  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
- */
505
+ id: number;
506
+ getContentContext(): XObjectContentContext;
507
+ getResourcesDictinary(): ResourcesDictionary;
508
+ getContentStream(): PDFStream;
509
509
  }
510
510
 
511
511
  export interface DocumentCopyingContext {
512
512
  createFormXObjectFromPDFPage(
513
513
  sourcePageIndex: number,
514
514
  ePDFPageBox: PDFPageBoxType | PDFBox,
515
+ transformation?: TransformationMatrix
515
516
  ): number;
516
517
  mergePDFPageToPage(target: PDFPage, sourcePageIndex: number): void;
517
518
  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
- */
519
+ mergePDFPageToFormXObject(sourcePage: PDFPage, targetPageNumber: number): void;
520
+ getSourceDocumentParser(input: FilePath | ReadStream, options?: PDFReaderOptions): PDFReader;
521
+ copyDirectObjectAsIs(objectToCopy: PDFObject): void;
522
+ copyObject(objectId: number): number;
523
+ copyDirectObjectWithDeepCopy(objectToCopy: PDFObject): Array<number>;
524
+ copyNewObjectsForDirectObject(objectIds: Array<number>): void;
525
+ getCopiedObjectID(objectId: number): number;
526
+ getCopiedObjects(): {[key: string]: number};
527
+ replaceSourceObjects(replaceMap: {[key: string]: number}): void;
528
+ getSourceDocumentStream(): ByteReaderWithPosition;
530
529
  }
531
530
 
532
531
  export interface DocumentContext {
533
- /*
534
- SET_PROTOTYPE_METHOD(t, "getInfoDictionary", GetInfoDictionary);
535
- */
532
+ getInfoDictionary(): InfoDictionary;
536
533
  }
537
534
 
538
535
  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
- */
536
+ writeKey(): DictionaryContext;
537
+ writeNameValue(nameValue: string): this;
538
+ writeRectangleValue(values: Array<number>): this;
539
+ writeRectangleValue(a: number, b: number, c: number, d: number): this;
540
+ writeLiteralStringValue(literal: Array<number>|string): this;
541
+ writeBooleanValue(boolValue: boolean): this;
542
+ writeObjectReferenceValue(objectId: number): this;
547
543
  }
548
544
 
549
545
  export interface ByteWriterWithPosition {
550
- /*
551
- SET_PROTOTYPE_METHOD(t, "write", Write);
552
- SET_PROTOTYPE_METHOD(t, "getCurrentPosition", GetCurrentPosition);
553
- */
546
+ write(bytes: Array<number>): number;
547
+ getCurrentPosition(): number;
548
+ }
549
+
550
+ export type eTokenSeparatorSpace = 0;
551
+ export type eTokenSeparatorEndLine = 1;
552
+ export type eTokenSepratorNone = 2;
553
+
554
+ enum ETokenSeparator {
555
+ eTokenSeparatorSpace,
556
+ eTokenSeparatorEndLine,
557
+ eTokenSepratorNone
554
558
  }
555
559
 
556
560
  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
- */
561
+ allocateNewObjectID(): FormXObjectId;
562
+ startDictionary(): DictionaryContext;
563
+ startArray(): this;
564
+ writeNumber(value: number): this;
565
+ endArray(endType?: ETokenSeparator): this;
566
+ endLine(): this;
567
+ endDictionary(dictionary: DictionaryContext): this;
568
+ endIndirectObject(): this;
569
+ writeIndirectObjectReference(objectId: FormXObjectId, generationNumber?: number): this;
570
+ startNewIndirectObject(objectId: FormXObjectId): this;
571
+ startNewIndirectObject(): FormXObjectId;
572
+ startModifiedIndirectObject(objectId: FormXObjectId): this;
573
+ deleteObject(objectId: FormXObjectId): this;
574
+ writeName(name: string): this;
575
+ writeLiteralString(literal: string | number[]): this;
576
+ writeHexString(hex: string | number[]): this;
577
+ writeBoolean(bool: boolean): this;
578
+ writeKeyword(keyword: string): this;
579
+ writeComment(comment: string): this;
580
+ setCompressStreams(compress: true): this;
581
+ startPDFStream(dictionaryContext: DictionaryContext): PDFStream;
582
+ startUnfilteredPDFStream(stream: DictionaryContext): PDFStream;
583
+ endPDFStream(stream: PDFStream): this;
584
+ startFreeContext(): ByteWriterWithPosition;
585
+ endFreeContext(): this;
583
586
  }
584
587
 
585
588
  export interface PDFObject {
@@ -601,30 +604,22 @@ SET_PROTOTYPE_METHOD(t, "allocateNewObjectID", AllocateNewObjectID);
601
604
  }
602
605
 
603
606
  export interface PDFReal extends PDFObject {
604
- /*
605
- SET_ACCESSOR_METHOD(t, "value", GetValue);
606
- */
607
+ value: number;
607
608
  }
608
609
 
609
610
  export interface PDFSymbol extends PDFObject {
610
- /*
611
- SET_ACCESSOR_METHOD(t, "value", GetValue);
612
- */
611
+ value: string;
613
612
  }
614
613
 
615
614
  export interface PDFStreamInput extends PDFObject {
616
- /*
617
- SET_PROTOTYPE_METHOD(t, "getDictionary", GetDictionary);
618
- SET_PROTOTYPE_METHOD(t, "getStreamContentStart", GetStreamContentStart);
619
- */
615
+ getDictionary(): PDFDictionary;
616
+ getStreamContentStart(): number;
620
617
  }
621
618
 
622
619
  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
- */
620
+ toBytesArray(): Array<number>;
621
+ toString(): string;
622
+ fromString(value: string): void;
628
623
  }
629
624
 
630
625
  export interface PageContentContext extends AbstractContentContext {
@@ -632,56 +627,80 @@ SET_PROTOTYPE_METHOD(t, "allocateNewObjectID", AllocateNewObjectID);
632
627
  getAssociatedPage(): PDFPage;
633
628
  }
634
629
 
630
+ export interface JPEGInformation {
631
+ samplesWidth: number;
632
+ samplesHeight: number;
633
+ colorComponentsCount: number;
634
+ JFIFInformationExists: boolean;
635
+ JFIFUnit?: number;
636
+ JFIFXDensity?: number;
637
+ JFIFYDensity?: number;
638
+ ExifInformationExists: boolean;
639
+ ExifUnit?: number;
640
+ ExifXDensity?: number;
641
+ ExifYDensity?: number;
642
+ PhotoshopInformationExists: boolean;
643
+ PhotoshopXDensity?: number;
644
+ PhotoshopYDensity?: number;
645
+ }
646
+
647
+ export type PDFRectangle = [lowerLeftX: number, lowerLeftY: number, upperRightX: number, upperRightY: number];
648
+
649
+ export interface MergeOptions {
650
+ password?: string;
651
+ type?: eRangeType;
652
+ specificRanges?: [[number, number]];
653
+ }
654
+
655
+ export interface AppendOptions extends MergeOptions {}
656
+
657
+ export type inInterPagesCallback = () => {}
658
+
659
+
635
660
  export interface PDFWriter {
636
661
  end(): PDFWriter;
637
- createPage(x: number, y: number, width: number, height: number): PDFPage;
662
+ createPage(x: PosX, y: PosY, width: Width, height: Height): PDFPage;
638
663
  createPage(): PDFPage;
639
664
  writePage(page: PDFPage): this;
640
665
  writePageAndReturnID(page: PDFPage): number;
641
666
  startPageContentContext(page: PDFPage): PageContentContext;
642
667
  pausePageContentContext(pageContextContext: PageContentContext): this;
643
- /*
644
- createFormXObject();
645
- endFormXObject();
646
- createFormXObjectFromJPG();
647
- */
648
- // TODO: test streamas
649
- createFormXObjectFromPNG(filePath: FilePath | PDFRStreamForFile): FormXObject;
650
-
668
+ createFormXObject(x: PosX, y: PosY, width: Width, height: Height, objectId?: FormXObjectId): FormXObject;
669
+ endFormXObject(formXObject: FormXObject): this;
670
+ createFormXObjectFromJPG(file: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
651
671
  getFontForFile(inFontFilePath: FilePath, index?: number): UsedFont;
652
672
  getFontForFile(
653
673
  inFontFilePath: FilePath,
654
674
  inOptionalMetricsFile?: string,
655
675
  index?: number,
656
676
  ): 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
- */
677
+ attachURLLinktoCurrentPage(url: string, x: PosX, y: PosY, width: Width, height: Height): this;
678
+ shutdown(outputFilePath: FilePath): this;
679
+ createFormXObjectFromTIFF(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
680
+ createImageXObjectFromJPG(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): ImageXObject;
681
+ createFormXObjectFromPNG(filePath: FilePath | PDFRStreamForFile, objectId?: FormXObjectId): FormXObject;
682
+ retrieveJPGImageInformation(filePath: FilePath): JPEGInformation;
683
+ getObjectsContext(): ObjectsContext;
684
+ getDocumentContext(): DocumentContext;
685
+ appendPDFPagesFromPDF(source: FilePath | ReadStream, options?: AppendOptions): number[];
686
+ mergePDFPagesToPage(page: PDFPage, file: FilePath | PDFRStreamForFile, options?: MergeOptions, callback?: inInterPagesCallback): this;
687
+ mergePDFPagesToPage(page: PDFPage, file: FilePath | PDFRStreamForFile, callback?: inInterPagesCallback) : this;
670
688
  createPDFCopyingContext(source: FilePath | ReadStream): DocumentCopyingContext;
671
- /*
672
- createFormXObjectsFromPDF();
673
- createPDFCopyingContextForModifiedFile();
674
- createPDFTextString();
675
- createPDFDate();
676
- */
689
+ createFormXObjectsFromPDF(file: FilePath, box?: PDFBox | PDFPageBoxType, options?: MergeOptions, transformation?: TransformationMatrix, objectIds?: FormXObjectId[]): FormXObjectId[];
690
+ createPDFCopyingContextForModifiedFile(): DocumentCopyingContext;
691
+ createPDFTextString(): PDFTextString;
692
+ createPDFDate(): PDFDate;
677
693
  getImageDimensions(inFontFilePath: FilePath | ReadStream): RectangleDimension;
678
- /*
679
- getImagePagesCount();
680
- getImageType();
681
- getModifiedFileParser();
682
- getModifiedInputFile();
683
- getOutputFile();
684
- registerAnnotationReferenceForNextPageWrite();
685
- */
694
+ getImagePagesCount(imagePath: FilePath, options?: {password?: string}): number;
695
+ getImageType(imagePath: FilePath): PDFImageType | undefined;
696
+ getModifiedFileParser(): PDFReader;
697
+ getModifiedInputFile(): InputFile;
698
+ getOutputFile(): OutputFile;
699
+ registerAnnotationReferenceForNextPageWrite(annotationId: number): this;
700
+ requireCatalogUpdate(): void;
701
+
702
+ /* Js Extensions (in muhammara.js) */
703
+ getEvents(): EventEmitter;
704
+ triggerDocumentExtensionEvent(eventName: string | symbol, eventParams: any): void;
686
705
  }
687
706
  }