-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcpdfdocs.js
2052 lines (1664 loc) · 67.6 KB
/
cpdfdocs.js
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// CHAPTER -1: Introduction
/**
Use
---
coherentpdf.js can be used from both node and the browser.
The file `cpdflibtest.js` uses every function in coherentpdf.js. Call `./run`
to run it in node.
For development server-side with node: `coherentpdf.js` (minified version
`coherentpdf.min.js`). Load with `const coherentpdf = require('coherentpdf')`
if installed in npm, or `const coherentpdf = require('./coherentpdf.js')` to
load from current directory.
For development client-side with the browser : `coherentpdf.browser.js`
(minified version for deployment : `coherentpdf.browser.min.js`). Load with
`<script src="coherentpdf.browser.js"></script>` or similar.
Data types
----------
Arguments are numbers, strings, or arrays (of type UInt8Array for data). Page
ranges are represented by arrays of numbers.
Memory Management
-----------------
A PDF p must be explicitly deallocated with deletePdf(p).
Errors
------
Any function may raise an exception, containing a string describing the problem.
Concurrency
-----------
coherentpdf.js is synchronous and non-re-entrant. In the browser, best used in a worker.
**/
// CHAPTER 0. Preliminaries
/** Returns a string giving the version number of the CPDF library.
@returns {string} version */
function version() {}
/** Some operations have a fast mode. The default is 'slow' mode, which works
even on old-fashioned files. For more details, see section 1.13 of the CPDF
manual. This function sets the mode to fast globally. */
function setFast() {}
/** Some operations have a fast mode. The default is 'slow' mode, which works
even on old-fashioned files. For more details, see section 1.13 of the CPDF
manual. This function sets the mode to slow globally. */
function setSlow() {}
/** Delete a PDF so the memory representing it may be recovered.
@arg {pdf} pdf PDF document to delete */
function deletePdf(pdf) {}
/* A debug function which prints some information about resource usage. This
can be used to detect if PDFs or ranges are being deallocated properly.
Contrary to its name, it may be run at any time. */
function onexit() {}
// CHAPTER 1. Basics
/** Loads a PDF file from a given file. Supply a user password (possibly blank)
in case the file is encrypted. It won't be decrypted, but sometimes the
password is needed just to load the file.
@arg {string} filename File name
@arg {string} userpw User password, or blank if none */
function fromFile(filename, userpw) {}
/** Loads a PDF from a file, doing only minimal parsing. The objects will be
read and parsed when they are actually needed. Use this when the whole file
won't be required. Also supply a user password (possibly blank) in case the
file is encrypted. It won't be decrypted, but sometimes the password is needed
just to load the file.
@arg {string} filename File name
@arg {string} userpw User password, or blank if none */
function fromFileLazy(filename, userpw) {}
/** Loads a file from memory given any user password.
@arg {Uint8Array} data PDF document as an array of bytes
@arg {string} userpw User password, or blank if none */
function fromMemory(data, userpw) {}
/** Loads a file from memory, given a pointer and a length, and the user
password, but lazily like fromFileLazy.
@arg {Uint8Array} data PDF document as an array of bytes
@arg {string} userpw User password, or blank if none */
function fromMemoryLazy(data, userpw) {}
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
clean up.
@return {number} number of PDFs */
function startEnumeratePDFs() {}
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
clean up.
@arg {n} index number
@return {number} PDF key */
function enumeratePDFsKey(n) {}
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
clean up.
@arg {n} index number
@return {number} PDF information */
function enumeratePDFsInfo(n) {}
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
clean up. */
function endEnumeratePDFs() {}
/** Converts a figure in centimetres to points (72 points to 1 inch)
@arg {number} i figure in centimetres
@return {number} figure in points */
function ptOfCm(i) {}
/** Converts a figure in millimetres to points (72 points to 1 inch)
@arg {number} i figure in millimetres
@return {number} figure in points */
function ptOfMm(i) {}
/** Converts a figure in inches to points (72 points to 1 inch)
@arg {number} i figure in inches
@return {number} figure in points */
function ptOfIn(i) {}
/** Converts a figure in points to centimetres (72 points to 1 inch)
@arg {number} i figure in points
@return {number} figure in centimetres */
function cmOfPt(i) {}
/** Converts a figure in points to millimetres (72 points to 1 inch)
@arg {number} i figure in points
@return {number} figure in millimetres */
function mmOfPt(i) {}
/** Converts a figure in points to inches (72 points to 1 inch)
@arg {number} i figure in points
@return {number} figure in inches */
function inOfPt(i) {}
/** Parses a page specification with reference to a given PDF (the PDF is
supplied so that page ranges which reference pages which do not exist are
rejected).
@arg {pdf} pdf PDF document
@arg {string} pagespec Page specification
@return {array} page range */
function parsePagespec(pdf, pagespec) {}
/** Validates a page specification so far as is possible in the absence of
the actual document. Result is true if valid.
@arg {string} pagespec Page specification
@return {boolean} validity or otherwise of page specification */
function validatePagespec(pagespec) {}
/** Builds a page specification from a page range. For example, the range
containing 1,2,3,6,7,8 in a document of 8 pages might yield "1-3,6-end"
@arg {pdf} pdf PDF document
@arg {array} r Page range
@return {string} Page specifcation */
function stringOfPagespec(pdf, r) {}
/** Creates a range with no pages in.
@return {array} Page range */
function blankRange() {}
/** Builds a range from one page to another inclusive. For example, range(3,7)
gives the range 3,4,5,6,7
@arg {number} f begining of page range
@arg {number} t end of page range
@return {array} page range */
function range(f, t) {}
/** The range containing all the pages in a given document.
@arg {pdf} pdf PDF document
@return {array} page range */
function all(pdf) {}
/** Makes a range which contains just the even pages of another range.
@arg {array} r_in page range
@return {array} page range */
function even(r_in) {}
/** Makes a range which contains just the odd pages of another range.
@arg {array} r_in page range
@return {array} page range */
function odd(r_in) {}
/** Makes the union of two ranges giving a range containing the pages in range
a and range b.
@arg {array} a page range
@arg {array} b page range
@return {array} page range */
function rangeUnion(a, b) {}
/** Makes the difference of two ranges, giving a range containing all the
pages in a except for those which are also in b.
@arg {array} a page range
@arg {array} b page range
@return {array} page range */
function difference(a, b) {}
/** Deduplicates a range, making a new one.
@arg {array} a page range
@return {array} page range */
function removeDuplicates(a) {}
/** Gives the number of pages in a range.
@arg {array} r page range
@return {number} length */
function rangeLength(r) {}
/** Gets the page number at position n in a range, where n runs from 0 to
rangeLength - 1.
@arg {array} r page range
@arg {number} n position
@return {number} page at given position */
function rangeGet(r, n) {}
/** Adds the page to a range, if it is not already there.
@arg {array} r page range
@arg {number} page page number */
function rangeAdd(r, page) {}
/** Returns true if the page is in the range, false otherwise.
@arg {array} r page range
@arg {number} page page number
@return {boolean} true if page in range, false otherwise */
function isInRange(r, page) {}
/** Returns the number of pages in a PDF.
@arg {pdf} pdf PDF document
@return {number} number of pages */
function pages(pdf) {}
/** Returns the number of pages in a given PDF, with given user password. It
tries to do this as fast as possible, without loading the whole file.
@arg {string} password user password
@arg {string} filename file name
@return {number} number of pages */
function pagesFast(password, filename) {}
/** Returns the number of pages in a given PDF, with given user password. It
tries to do this as fast as possible, without loading the whole file.
@arg {string} password user password
@arg {Uint8Array} data PDF file as a byte array
@return {number} number of pages */
function pagesFastMemory(password, data) {}
/** Writes the file to a given filename. If linearize is true, it will be
linearized if a linearizer is available. If make_id is true, it will be
given a new ID.
@arg {pdf} pdf PDF document
@arg {string} filename file name
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} make_id make a new /ID */
function toFile(pdf, filename, linearize, make_id) {}
/** Writes the file to a given filename. If make_id is true, it will be given
a new ID. If preserve_objstm is true, existing object streams will be
preserved. If generate_objstm is true, object streams will be generated even if
not originally present. If compress_objstm is true, object streams will be
compressed (what we usually want). WARNING: the pdf argument will be invalid
after this call, and should be not be used again.
@arg {pdf} pdf PDF document
@arg {string} filename file name
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} preserve_objstm preserve existing object streams
@arg {boolean} generate_objstm create new object streams
@arg {boolean} compress_objstm compress new object streams */
function toFileExt(pdf, filename, linearize, make_id, preserve_objstm, generate_objstm, compress_objstm) {}
/** Writes a PDF file and returns as an array of bytes.
@arg {pdf} pdf PDF document
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} make_id make a new /ID
@result {Uint8Array} PDF document as an array of bytes */
function toMemory(pdf, linearize, make_id) {}
/** Writes the file to memory. If make_id is true, it will be given
a new ID. If preserve_objstm is true, existing object streams will be
preserved. If generate_objstm is true, object streams will be generated even if
not originally present. If compress_objstm is true, object streams will be
compressed (what we usually want). WARNING: the pdf argument will be invalid
after this call, and should be not be used again.
@arg {pdf} pdf PDF document
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} preserve_objstm preserve existing object streams
@arg {boolean} generate_objstm create new object streams
@arg {boolean} compress_objstm compress new object streams
@result {Uint8Array} PDF file as a byte array */
function toMemoryExt(pdf, linearize, make_id, preserve_objstm, generate_objstm, compress_objstm) {}
/** Returns true if a document is encrypted, false otherwise.
@arg {pdf} pdf PDF document
@return {boolean} true if document encrypted, false otherwise */
function isEncrypted(pdf) {}
/** Attempts to decrypt a PDF using the given user password. An exception is
raised if the decryption fails.
@arg {pdf} pdf PDF document
@arg {string} userpw user password, or empty if none */
function decryptPdf(pdf, userpw) {}
/** Attempts to decrypt a PDF using the given owner password. Raises an
exception if the decryption fails.
@arg {pdf} pdf PDF document
@arg {string} ownerpw owner password, or empty if none */
function decryptPdfOwner(pdf, ownerpw) {}
/** Cannot edit the document */
var noEdit = 0;
/** Cannot print the document */
var noPrint = 1;
/** Cannot copy the document */
var noCopy = 2;
/** Cannot annotate the document */
var noAnnot = 3;
/** Cannot edit forms in the document */
var noForms = 4;
/** Cannot extract information */
var noExtract = 5;
/** Cannot assemble into a bigger document */
var noAssemble = 6;
/** Cannot print high quality */
var noHqPrint = 7;
/** 40 bit RC4 encryption */
var pdf40bit = 0;
/** 128 bit RC4 encryption */
var pdf128bit = 1;
/** 128 bit AES encryption, do not encrypt metadata */
var aes128bitfalse = 2;
/** 128 bit AES encryption, encrypt metadata */
var aes128bittrue = 3;
/** Deprecated. Do not use for new files */
var aes256bitfalse = 4;
/** Deprecated. Do not use for new files */
var aes256bittrue = 5;
/** 256 bit AES encryption, do not encrypt metadata */
var aes256bitisofalse = 6;
/** 256 bit AES encryption, encrypt metadata */
var aes256bitisotrue = 7;
/** Writes a file as encrypted.
@arg {pdf} pdf PDF document
@arg {"encryption method"} encryption_method encryption method
@arg {"permission array"} array of permissions
@arg {string} ownerpw owner password
@arg {string} userpw user password
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} makeid make a new /ID
@arg {string} filename file name */
function toFileEncrypted(pdf, encryption_method, permissions, ownerpw, userpw, linearize, makeid, filename) {}
/** Writes to memory as encrypted.
@arg {pdf} pdf PDF document
@arg {"encryption method"} encryption_method encryption method
@arg {"permission array"} array of permissions
@arg {string} ownerpw owner password
@arg {string} userpw user password
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} makeid make a new /ID
@return {Uint8Array} PDF file as a byte array */
function toMemoryEncrypted(pdf, encryption_method, permissions, ownerpw, userpw, linearize, makeid) {}
/** Writes a file as encrypted with extra parameters. WARNING: the pdf argument
will be invalid after this call, and should not be used again.
@arg {pdf} pdf PDF document
@arg {"encryption method"} encryption_method encryption method
@arg {"permission array"} array of permissions
@arg {string} ownerpw owner password
@arg {string} userpw user password
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} makeid make a new /ID
@arg {boolean} preserve_objstm preserve existing object streams
@arg {boolean} generate_objstm generate new object streams
@arg {boolean} compress_objstm compress object streams
@arg {string} filename file name */
function toFileEncryptedExt(pdf, encryption_method, permissions, ownerpw, userpw, linearize, makeid, preserve_objstm, generate_objstm, compress_objstm, filename) {}
/** Writes a file as encrypted with extra parameters. WARNING: the pdf argument
will be invalid after this call, and should not be used again.
@arg {pdf} pdf PDF document
@arg {"encryption method"} encryption_method encryption method
@arg {"permission array"} array of permissions
@arg {string} ownerpw owner password
@arg {string} userpw user password
@arg {boolean} linearize linearize if a linearizer is available
@arg {boolean} makeid make a new /ID
@arg {boolean} preserve_objstm preserve existing object streams
@arg {boolean} generate_objstm generate new object streams
@arg {boolean} compress_objstm compress object streams
@return {Uint8Array} PDF file as a byte array */
function toMemoryEncryptedExt(pdf, encryption_method, permissions, ownerpw, userpw, linearize, makeid, preserve_objstm, generate_objstm, compress_objstm) {}
/** Returns true if the given permission (restriction) is present.
@arg {pdf} pdf PDF document
@arg {permission} permission permission
@return {boolean} true if permission present */
function hasPermission(pdf, permission) {}
/** Returns the encryption method currently in use on a document.
@arg {pdf} pdf PDF document
@return {"encryption method"} encryption method */
function encryptionKind(pdf) {}
// CHAPTER 2. Merging and Splitting
/** Given a list of PDFs, merges the files into a new one, which is returned.
@arg {"array of pdfs"} pdfs array of PDF documents to merge
@return {pdf} merged PDF document */
function mergeSimple(pdfs) {}
/** Merges the PDFs. If retain_numbering is true page labels are not
rewritten. If remove_duplicate_fonts is true, duplicate fonts are merged.
This is useful when the source documents for merging originate from the same
source.
@arg {"array of pdfs"} pdfs array of PDF documents to merge
@arg {boolean} retain_numbering keep page numbering
@arg {boolean} remove_duplicate_fonts remove duplicate font data */
function merge(pdfs, retain_numbering, remove_duplicate_fonts) {}
/** The same as merge, except that it has an additional argument - a list of
page ranges. This is used to select the pages to pick from each PDF. This
avoids duplication of information when multiple discrete parts of a source PDF
are included.
@arg {"array of pdfs"} pdfs array of PDF documents to merge
@arg {boolean} retain_numbering keep page numbering
@arg {boolean} remove_duplicate_fonts remove duplicate font data
@arg {"array of arrays of numbers"} ranges page ranges, one for each input PDF */
function mergeSame(pdfs, retain_numbering, remove_duplicate_fonts, ranges) {}
/** Returns a new document with just those pages in the page range.
@arg {pdf} pdf PDF document
@arg {range} page range */
function selectPages(pdf, r) {}
// CHAPTER 3. Pages
/** Scales the page dimensions and content by the given scale, about (0, 0).
Other boxes (crop etc. are altered as appropriate)
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} sx x scale
@arg {number} sy y scale */
function scalePages(pdf, range, sx, sy) {}
/** Scales the content to fit new page dimensions (width x height) multiplied
by scale (typically 1.0). Other boxes (crop etc. are altered as appropriate).
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} sx x scale
@arg {number} sy y scale
@arg {number} scale scale */
function scaleToFit(pdf, range, sx, sy, scale) {}
/** A0 Portrait paper */
var a0portrait = 0;
/** A1 Portrait paper */
var a1portrait = 1;
/** A2 Portrait paper */
var a2portrait = 2;
/** A3 Portrait paper */
var a3portrait = 3;
/** A4 Portrait paper */
var a4portrait = 4;
/** A5 Portrait paper */
var a5portrait = 5;
/** A0 Landscape paper */
var a0landscape = 6;
/** A1 Landscape paper */
var a1landscape = 7;
/** A2 Landscape paper */
var a2landscape = 8;
/** A3 Landscape paper */
var a3landscape = 9;
/** A4 Landscape paper */
var a4landscape = 10;
/** A5 Landscape paper */
var a5landscape = 11;
/** US Letter Portrait paper */
var usletterportrait = 12;
/** US Letter Landscape paper */
var usletterlandscape = 13;
/** US Legal Portrait paper */
var uslegalportrait = 14;
/** US Legal Landscape paper */
var uslegallandscape = 15;
/** Scales the page content to fit the given page size, possibly multiplied by
scale (typically 1.0)
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {"paper size"} papersize paper size
@arg {number} s scale */
function scaleToFitPaper(pdf, range, papersize, s) {}
/** Positions on the page. Used for scaling about a point, and adding text.
A position is an anchor and zero or one or two parameters.
posCentre: Two parameters, x and y<br/>
posLeft: Two parameters, x and y<br/>
posRight: Two parameters, x and y<br/>
top: One parameter - distance from top<br/>
topLeft: One parameter - distance from top left<br/>
topRight: One parameter - distance from top right<br/>
left: One parameter - distance from left middle<br/>
bottomLeft: One parameter - distance from bottom left<br/>
bottom: One parameter - distance from bottom<br/>
bottomRight: One parameter - distance from bottom right<br/>
right: One parameter - distance from right<br/>
diagonal: Zero parameters<br/>
reverseDiagonal: Zero parameters */
/** Absolute centre */
var posCentre = 0;
/** Absolute left */
var posLeft = 1;
/** Absolute right */
var posRight = 2;
/** The top centre of the page */
var top = 3;
/** The top left of the page */
var topLeft = 4;
/** The top right of the page */
var topRight = 5;
/** The left hand side of the page, halfway down */
var left = 6;
/** The bottom left of the page */
var bottomLeft = 7;
/** The bottom middle of the page */
var bottom = 8;
/** The bottom right of the page */
var bottomRight = 9;
/** The right hand side of the page, halfway down */
var right = 10;
/** Diagonal, bottom left to top right */
var diagonal = 11;
/** Diagonal, top left to bottom right */
var reversediagonal = 12;
/** Scales the contents of the pages in the range about the point given by
the position, by the scale given.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {anchor} anchor anchor to scale contents about
@arg {number} p1 position argument 1
@arg {number} p2 position argument 2
@arg {number} scale scale */
function scaleContents(pdf, range, anchor, p1, p2, scale) {}
/** Shifts the content of the pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} dx x shift
@arg {number} dy y shift */
function shiftContents(pdf, range, dx, dy) {}
/** Changes the viewing rotation to an absolute value. Appropriate rotations
are 0, 90, 180, 270.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} rotation rotation */
function rotate(pdf, range, rotation) {}
/** Rotates the content about the centre of the page by the given number of
degrees, in a clockwise direction. Appropriate rotations
are 0, 90, 180, 270.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} rotation rotation */
function rotateBy(pdf, range, rotation) {}
/** Rotates the content about the centre of the page by the given number of
degrees, in a clockwise direction.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} angle angle */
function rotateContents(pdf, range, angle) {}
/** Changes the viewing rotation of the pages in the range, counter-rotating
the dimensions and content such that there is no visual change.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function upright(pdf, range) {}
/** Flips horizontally the pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function hFlip(pdf, range) {}
/** Flips vertically the pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function vFlip(pdf, range) {}
/** Crops a page, replacing any existing crop box. The dimensions are in
points.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {number} x x position
@arg {number} y y position
@arg {number} w width
@arg {number} h height */
function crop(pdf, range, x, y, w, h) {}
/** Removes any crop box from pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function removeCrop(pdf, range) {}
/** Removes any trim box from pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function removeTrim(pdf, range) {}
/** Removes any art box from pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function removeArt(pdf, range) {}
/** Removes any bleed box from pages in the range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function removeBleed(pdf, range) {}
/** Adds trim marks to the given pages, if the trimbox exists.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function trimMarks(pdf, range) {}
/** Shows the boxes on the given pages, for debug.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function showBoxes(pdf, range) {}
/** Makes a given box a 'hard box' i.e clips it explicitly.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {string} boxname box name */
function hardBox(pdf, range, boxname) {}
// CHAPTER 4. Encryption
// CHAPTER 5. Compression
/** Compresses any uncompressed streams in the given PDF using the Flate
algorithm.
@arg {pdf} pdf PDF document */
function compress(pdf) {}
/** Decompresses any streams in the given PDF, so long as the compression
method is supported.
@arg {pdf} pdf PDF document */
function decompress(pdf) {}
/** Squeezes a pdf in memory.
@arg {pdf} pdf PDF document */
function squeezeInMemory(pdf) {}
// CHAPTER 6. Bookmarks
/** Starts the bookmark retrieval process for a given PDF.
@arg {pdf} pdf PDF document */
function startGetBookmarkInfo(pdf) {}
/** Gets the number of bookmarks for the PDF given to startGetBookmarkInfo.
@return {number} number of bookmarks */
function numberBookmarks() {}
/** Gets the bookmark level for the given bookmark (0...(n - 1)).
@arg {number} n serial number
@return {number} bookmark level */
function getBookmarkLevel(n) {}
/** Gets the bookmark target page for the given PDF (which must be the same
as the PDF passed to startSetBookmarkInfo) and bookmark (0...(n - 1)).
@arg {pdf} pdf PDF document
@arg {number} n serial number
@return {number} bookmark page */
function getBookmarkPage(pdf, n) {}
/** Returns the text of bookmark (0...(n - 1)).
@arg {number} n serial number
@return {string} bookmark text */
function getBookmarkText(n) {}
/** True if the bookmark is open.
@arg {number} n serial number
@return {boolean} open status */
function getBookmarkOpenStatus(n) {}
/** Ends the bookmark retrieval process, cleaning up. */
function endGetBookmarkInfo() {}
/** Starts the bookmark setting process for n bookmarks.
@arg {number} n number of bookmarks required */
function startSetBookmarkInfo(n) {}
/** Set bookmark level for the given bookmark (0...(n - 1)).
@arg {number} n serial number
@arg {number} level bookmark level */
function setBookmarkLevel(n, level) {}
/** Sets the bookmark target page for the given PDF (which must be the same as
the PDF to be passed to endSetBookmarkInfo) and bookmark (0...(n - 1)).
@arg {pdf} pdf PDF document
@arg {number} n serial number
@arg {number} targetpage target page */
function setBookmarkPage(pdf, n, targetpage) {}
/** Sets the open status of bookmark (0...(n - 1)).
@arg {number} n serial number
@arg {boolean} status open status */
function setBookmarkOpenStatus(n, status) {}
/** Sets the text of bookmark (0...(n - 1)).
@arg {number} n serial number
@arg {string} text bookmark text */
function setBookmarkText(n, text) {}
/** Ends the bookmark setting process, writing the bookmarks to the given
PDF.
@arg {pdf} pdf PDF document */
function endSetBookmarkInfo(pdf) {}
/** Returns the bookmark data in JSON format.
@arg {pdf} pdf PDF document
@result {Uint8Array} result as a byte array */
function getBookmarksJSON(pdf) {}
/** Sets the bookmarks from JSON bookmark data.
@arg {pdf} pdf PDF document
@arg {Uint8Array} byte array of JSON bookmark data */
function setBookmarksJSON(pdf, data) {}
/** Typesets a table of contents from existing bookmarks and prepends it to
the document. If bookmark is set, the table of contents gets its own
bookmark.
@arg {pdf} pdf PDF document
@arg {font} font font
@arg {number} fontsize font size
@arg {string} title title
@arg {boolean} bookmark table of contents gets its own bookmark */
function tableOfContents(pdf, font, fontsize, title, bookmark) {}
// CHAPTER 7. Presentations
// CHAPTER 8. Logos, Watermarks and Stamps
/** Stamps stamp_pdf on all the pages in the document which are in the
range. The stamp is placed with its origin at the origin of the target
document.
@arg {pdf} stamp_pdf stamp
@arg {pdf} pdf PDF document
@arg {range} range page range */
function stampOn(stamp_pdf, pdf, range) {}
/** Stamps stamp_pdf under all the pages in the document which are in the
range. The stamp is placed with its origin at the origin of the target
document.
@arg {pdf} stamp_pdf stamp
@arg {pdf} pdf PDF document
@arg {range} range page range */
function stampUnder(stamp_pdf, pdf, range) {}
/** A stamping function with extra features.
@arg {pdf} pdf first PDF document
@arg {pdf} pdf second PDF document
@arg {boolean} isover pdf goes over pdf2, otherwise under
@arg {boolean} scale_stamp_to_fit scales the stamp to fit the page
@arg {anchor} anchor for position of stamp
@arg {number} p1 position argument 1
@arg {number} p2 position argument 2
@arg {boolean} relative_to_cropbox pos is relative to cropbox not mediabox. */
function stampExtended(pdf, pdf2, range, isover, scale_stamp_to_fit, position, relative_to_cropbox) {}
/** Combines the PDFs page-by-page, putting each page of 'over' over each page
of 'under'.
@arg {pdf} under PDF document
@arg {pdf} over PDF document
@result {pdf} resultant PDF document */
function combinePages(under, over) {}
/** Times Roman */
var timesRoman = 'Times-Roman';
/** Times Bold */
var timesBold = 'Times-Bold';
/** Times Italic */
var timesItalic = 'Times-Italic';
/** Times Bold Italic */
var timesBoldItalic = 'Times-BoldItalic';
/** Helvetica */
var helvetica = 'Helvetica';
/** Helvetica Bold */
var helveticaBold = 'Helvetica-Bold';
/** Helvetica Oblique */
var helveticaOblique = 'Helvetica-Oblique';
/** Helvetica Bold Oblique */
var helveticaBoldOblique = 'Helvetica-BoldOblique';
/** Courier */
var courier = 'Courier';
/** Courier Bold */
var courierBold = 'Courier-Bold';
/** Courier Oblique */
var courierOblique = 'Courier-Oblique';
/** Courier Bold Oblique */
var courierBoldOblique = 'Courier-BoldOblique';
/** Left justify */
var leftJustify = 0;
/** Centre justify */
var centreJustify = 1;
/** Right justify */
var rightJustify = 2;
/** Adds text to the pages in the given range.
@arg {boolean} metrics collect metrics only
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {string} text text to add \\n for newline
@arg {anchor} anchor anchor to add text at
@arg {number} p1 position argument 1
@arg {number} p2 position argument 2
@arg {number} linespacing line spacing
@arg {number} bates starting bates number
@arg {font} font font
@arg {number} fontsize font size
@arg {number} r red component of colour 0..1
@arg {number} g green component of colour 0..1
@arg {number} b blue component of colour 0..1
@arg {boolean} underneath put text under the page rather than over
@arg {boolean} relative_to_cropbox position is relative to crop box not media box
@arg {boolean} outline text is outline
@arg {number} opacity opacity 0..1
@arg {justification} justification justification
@arg {boolean} midline position is relative to midline not baseline
@arg {boolean} topline position is relative to topline not baseline
@arg {string} filename file name
@arg {number} linewidth line width
@arg {boolean} embed_fonts add font information
*/
function addText(metrics, pdf, range, text, anchor, p1, p2, linespacing,
bates, font, fontsize, r, g, b, underneath, relative_to_cropbox, outline,
opacity, justification, midline, topline, filename, linewidth, embed_fonts) {}
/** Adds text with most parameters default.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {string} text text to add. \\n for newline
@arg {anchor} anchor anchor to add text at
@arg {number} p1 position argument 1
@arg {number} p2 position argument 2
@arg {font} font font
@arg {number} fontsize font size */
function addTextSimple(pdf, range, text, anchor, p1, p2, font, fontsize) {}
/** Removes any text added by cpdf from the given pages.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function removeText(pdf, range) {}
/** Returns the width of a given string in the given font in thousandths of a
point.
@arg {font} font font
@arg {string} text text
@result {number} width */
function textWidth(font, text) {}
/** Adds page content before (if true) or after (if false) the existing
content to pages in the given range in the given PDF.
@arg {string} content content to add
@arg {boolean} before rather than after
@arg {pdf} pdf PDF document
@arg {range} range page range */
function addContent(content, before, pdf, range) {}
/** Stamps stamp_pdf onto the pages in the given range in pdf as a shared Form
XObject. The name of the newly-created XObject is returned.
@arg {pdf} pdf PDF document
@arg {range} range page range
@arg {pdf} stamp_pdf stamp pdf
@result {string} name of XObject */
function stampAsXObject(pdf, range, stamp_pdf) {}
// CHAPTER 9. Multipage facilities
/** Imposes a PDF. There are two modes: imposing x * y, or imposing to fit a
page of size x * y. This is controlled by fit. Columns imposes by columns
rather than rows. rtl is right-to-left, btt bottom-to-top. Center is unused
for now. Margin is the margin around the output, spacing the spacing between
imposed inputs.
@arg {pdf} pdf PDF document
@arg {number} x (explained above)
@arg {number} y (explained above)
@arg {boolean} fit (explained above)
@arg {boolean} rtl impose right to left
@arg {boolean} btt impose bottom to top
@arg {boolean} center unused
@arg {number} margin margin around output pages
@arg {number} spacing spacing between imposed pages
@arg {number} linewidth line width */
function impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing, linewidth) {}
/** Imposes a document two up. twoUp does so by shrinking the page size, to fit
two pages on one.
@arg {pdf} pdf PDF document */
function twoUp(pdf) {}
/** Impose a document two up. twoUpStack does so by doubling the page size,
to fit two pages on one.
@arg {pdf} pdf PDF document */
function twoUpStack(pdf) {}
/** Adds a blank page before each page in the given range.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function padBefore(pdf, range) {}
/** Adds a blank page after every n pages.
@arg {pdf} pdf PDF document
@arg {range} range page range */
function padAfter(pdf, range) {}
/** Adds a blank page after every n pages.
@arg {pdf} pdf PDF document