@chilkat/react-native 11.6.1 → 11.7.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/chilkat-checksums.json +4 -4
- package/cpp/HybridAi.cpp +12 -12
- package/cpp/HybridAi.hpp +6 -6
- package/cpp/HybridDns.cpp +7 -7
- package/cpp/HybridDns.hpp +3 -3
- package/cpp/HybridFormats.cpp +100 -0
- package/cpp/HybridFormats.hpp +39 -0
- package/cpp/HybridHashtable.cpp +4 -4
- package/cpp/HybridHashtable.hpp +2 -2
- package/cpp/HybridHttp.cpp +9 -0
- package/cpp/HybridHttp.hpp +2 -0
- package/cpp/HybridHttpCurl.cpp +17 -0
- package/cpp/HybridHttpCurl.hpp +3 -0
- package/cpp/HybridPdf.cpp +152 -0
- package/cpp/HybridPdf.hpp +36 -0
- package/cpp/HybridSocket.cpp +56 -0
- package/cpp/HybridSocket.hpp +13 -0
- package/cpp/HybridSpider.cpp +14 -14
- package/cpp/HybridSpider.hpp +6 -6
- package/cpp/HybridStringBuilder.cpp +8 -0
- package/cpp/HybridStringBuilder.hpp +2 -0
- package/cpp/HybridZipEntry.cpp +8 -8
- package/cpp/HybridZipEntry.hpp +4 -4
- package/cpp/runtime/ProgLang.hpp +1 -1
- package/nitro.json +1 -0
- package/nitrogen/generated/android/ChilkatRN+autolinking.cmake +1 -0
- package/nitrogen/generated/android/ChilkatRNOnLoad.cpp +10 -0
- package/nitrogen/generated/ios/ChilkatRNAutolinking.mm +10 -0
- package/nitrogen/generated/shared/c++/HybridAiSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridDnsSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridFormatsSpec.cpp +32 -0
- package/nitrogen/generated/shared/c++/HybridFormatsSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridHashtableSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHttpCurlSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridHttpCurlSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/HybridHttpSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridHttpSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridPdfSpec.cpp +19 -0
- package/nitrogen/generated/shared/c++/HybridPdfSpec.hpp +19 -0
- package/nitrogen/generated/shared/c++/HybridSocketSpec.cpp +10 -0
- package/nitrogen/generated/shared/c++/HybridSocketSpec.hpp +10 -0
- package/nitrogen/generated/shared/c++/HybridSpiderSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridStringBuilderSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridStringBuilderSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridZipEntrySpec.hpp +2 -2
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/specs/Ai.nitro.ts +3 -12
- package/src/specs/Cert.nitro.ts +24 -6
- package/src/specs/CodeSign.nitro.ts +88 -20
- package/src/specs/Compression.nitro.ts +9 -1
- package/src/specs/Dns.nitro.ts +2 -8
- package/src/specs/FileAccess.nitro.ts +12 -2
- package/src/specs/Formats.nitro.ts +170 -0
- package/src/specs/Hashtable.nitro.ts +1 -4
- package/src/specs/Http.nitro.ts +39 -3
- package/src/specs/HttpCurl.nitro.ts +119 -3
- package/src/specs/Jwe.nitro.ts +12 -5
- package/src/specs/MailMan.nitro.ts +7 -0
- package/src/specs/Pdf.nitro.ts +1482 -11
- package/src/specs/Socket.nitro.ts +181 -2
- package/src/specs/Spider.nitro.ts +4 -16
- package/src/specs/Ssh.nitro.ts +31 -13
- package/src/specs/StringBuilder.nitro.ts +55 -0
- package/src/specs/ZipEntry.nitro.ts +2 -8
package/src/specs/Pdf.nitro.ts
CHANGED
|
@@ -149,6 +149,12 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
149
149
|
* such as issuer certs or root CA certs, are not included and not available to check. In this
|
|
150
150
|
* case, you can add the `NO_VERIFY_CERT_SIGNATURES` to skip the existing signature certificate
|
|
151
151
|
* validations.
|
|
152
|
+
*
|
|
153
|
+
* - **SIGN_IGNORE_PERMISSIONS** - (v11.7.0) Sign an encrypted PDF even when it was not opened
|
|
154
|
+
* with owner rights and its permissions do not allow the signature. Starting in v11.7.0 the
|
|
155
|
+
* signing methods refuse such a PDF (see {@link Pdf.signPdf}); this keyword restores the
|
|
156
|
+
* earlier behavior for applications that depend on it. It does not help with a PDF that could
|
|
157
|
+
* not be opened at all: that one cannot be signed.
|
|
152
158
|
*/
|
|
153
159
|
uncommonOptions: string
|
|
154
160
|
|
|
@@ -195,6 +201,25 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
195
201
|
*/
|
|
196
202
|
userPassword: string
|
|
197
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Controls what Chilkat may do to a PDF that contains digital signatures. The default is `true`.
|
|
206
|
+
*
|
|
207
|
+
* A signature covers the bytes of the file as they were when it was signed, so a PDF can only be
|
|
208
|
+
* changed afterwards by appending an incremental update that leaves those bytes untouched. Some
|
|
209
|
+
* changes cannot be made that way: rewriting page content ({@link Pdf.textReplace}, and most
|
|
210
|
+
* {@link Pdf.watermark} approaches), changing the encryption, passwords or permissions ({@link
|
|
211
|
+
* Pdf.protection}), and rewriting the file ({@link Pdf.optimize}). While this property is `true`,
|
|
212
|
+
* such operations are refused on a signed PDF and the reason is given in the LastErrorText; the
|
|
213
|
+
* operations that only append (adding a {@link Pdf.watermark} with the `annotation` approach,
|
|
214
|
+
* adding signatures, embedded files or metadata) remain available.
|
|
215
|
+
*
|
|
216
|
+
* Set this property to `false` to allow any change, accepting that the existing signatures become
|
|
217
|
+
* invalid: the saved PDF is a full rewrite and viewers report the signatures as broken. The
|
|
218
|
+
* property is also read when the PDF is written: with it `false`, {@link Pdf.writeFile} and
|
|
219
|
+
* {@link Pdf.writeBd} may rewrite a signed PDF instead of appending to it.
|
|
220
|
+
*/
|
|
221
|
+
preserveSignatures: boolean
|
|
222
|
+
|
|
198
223
|
// ---- Methods ----
|
|
199
224
|
|
|
200
225
|
/**
|
|
@@ -226,8 +251,23 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
226
251
|
|
|
227
252
|
/**
|
|
228
253
|
* Signs the open PDF and if successful writes the signed PDF to the ARG3. The `jsonOptions`
|
|
229
|
-
* contains information and instructions about the signature.
|
|
230
|
-
*
|
|
254
|
+
* contains information and instructions about the signature. This object keeps its state from
|
|
255
|
+
* before the call; to sign the loaded document in place (and sign again, or add a DocTimeStamp,
|
|
256
|
+
* without reloading), use {@link Pdf.signPdf2}. Starting in v11.7.0, changes pending from other
|
|
257
|
+
* methods are committed before the signature is added. See the examples below for more detailed
|
|
258
|
+
* information about the JSON options listed here.
|
|
259
|
+
*
|
|
260
|
+
* **Signing an encrypted PDF** - An encrypted PDF can be signed, with an approval or a
|
|
261
|
+
* certification signature, and stays encrypted: the signature is added with the document's own
|
|
262
|
+
* key and everything it adds is encrypted, except the signature value itself, which PDF never
|
|
263
|
+
* encrypts. The PDF must have been opened (load it with its `UserPassword` or `OwnerPassword`).
|
|
264
|
+
* Starting in v11.7.0, a PDF that was not opened with owner rights is signed only if its
|
|
265
|
+
* permissions allow it: adding a new signature field needs both the `modify` and the `annotate`
|
|
266
|
+
* permission, and filling in an existing unsigned signature field
|
|
267
|
+
* (`appearance.fillUnsignedSignatureField`) needs the `fillForms` or the `annotate` permission.
|
|
268
|
+
* Otherwise the call fails and the `LastErrorText` names what is missing; load the PDF with its
|
|
269
|
+
* owner password to sign it regardless of its permissions. (See {@link Pdf.protection} for a
|
|
270
|
+
* PDF's permissions, and the `SIGN_IGNORE_PERMISSIONS` keyword of {@link Pdf.uncommonOptions}.)
|
|
231
271
|
*
|
|
232
272
|
* **Summary of PDF Signing Options**
|
|
233
273
|
*
|
|
@@ -364,13 +404,26 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
364
404
|
* Can be a keyword such as `left`, `right`, or `middle` to specify a typical placement with
|
|
365
405
|
* default margins. Otherwise can be a floating point number where 0.0 is the leftmost
|
|
366
406
|
* coordinate of a page, and 612.0 is the right most. Can also be the keyword `after` to place
|
|
367
|
-
* the signature just to the right of the rightmost signature on the page.
|
|
407
|
+
* the signature just to the right of the rightmost signature on the page. Starting in v11.7.0,
|
|
408
|
+
* if the signature would not fit on the page there, it continues as a line of text does: to the
|
|
409
|
+
* right of the signatures in the lowest row if there is room, and otherwise at the left margin
|
|
410
|
+
* in a new row under the existing signatures. (In earlier versions it was placed to the right
|
|
411
|
+
* of the rightmost signature regardless, and could lie partly or entirely off the page.)
|
|
368
412
|
*
|
|
369
413
|
* - **appearance.y** - The vertical position on the page of the top edge of the signature box.
|
|
370
414
|
* Can be one of the keywords `top` or `bottom` to specify a typical placement with default
|
|
371
415
|
* margins. Otherwise can be a floating point number where 0.0 is the bottom coordinate of a
|
|
372
416
|
* page, and 792.0 is the top. Can also be the keyword `under` to place the signature just under
|
|
373
|
-
* the bottommost signature on the page.
|
|
417
|
+
* the bottommost signature on the page. Invisible signatures are not counted (starting in
|
|
418
|
+
* v11.7.0; in earlier versions a signature placed `under` on a page that had an invisible
|
|
419
|
+
* signature was put below the bottom of the page).
|
|
420
|
+
*
|
|
421
|
+
* **Rotated pages** - On a page that is displayed rotated (a page with a /Rotate of 90, 180 or
|
|
422
|
+
* 270), **appearance.x**, **appearance.y**, the keywords and the margins all refer to the page as
|
|
423
|
+
* it is displayed: x is measured from the displayed left edge and y from the displayed bottom
|
|
424
|
+
* edge, and the signature is upright as the page is read. Starting in v11.7.0 this holds for
|
|
425
|
+
* every rotation. In earlier versions a page rotated by 180 or 270 was treated as if it were not
|
|
426
|
+
* rotated, and on a page rotated by 90 a numeric appearance.y was misplaced.
|
|
374
427
|
*
|
|
375
428
|
* - **contactInfo** - Optional to provide free-form text with contact information about the
|
|
376
429
|
* signer.
|
|
@@ -437,7 +490,11 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
437
490
|
* authenticated attribute that should be included with or without the addition of
|
|
438
491
|
* time-stamping.
|
|
439
492
|
*
|
|
440
|
-
* - **sigTextLabel** - Set to provide free-form text for the signatures annotation text label
|
|
493
|
+
* - **sigTextLabel** - Set to provide free-form text for the signatures annotation text label,
|
|
494
|
+
* which is the name of the new signature field. If not set, the field is named `Signature2`,
|
|
495
|
+
* `Signature3`, and so on. Starting in v11.7.0 a name that a field of the PDF already has is
|
|
496
|
+
* skipped; in earlier versions a PDF with an unsigned field of that name got a second field of
|
|
497
|
+
* the same name, and viewers did not show the new signature.
|
|
441
498
|
*
|
|
442
499
|
* - **subFilter** - Set to `/ETSI.CAdES.detached`, `/adbe.pkcs7.detached`, or something else.
|
|
443
500
|
*
|
|
@@ -586,6 +643,11 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
586
643
|
* Pass an empty `jsonOptions`. The `jsonOptions` exists as a placeholder for adding options if
|
|
587
644
|
* needed.
|
|
588
645
|
*
|
|
646
|
+
* This object keeps its state from before the call; to add the verification information to the
|
|
647
|
+
* loaded document in place (and go on to other operations without reloading), use {@link
|
|
648
|
+
* Pdf.addVerificationInfo2}. Starting in v11.7.0, changes pending from other methods are
|
|
649
|
+
* committed before the verification information is added.
|
|
650
|
+
*
|
|
589
651
|
* This call blocks the JavaScript thread until Chilkat returns; from UI code prefer
|
|
590
652
|
* {@link Pdf.addVerificationInfoAsync}.
|
|
591
653
|
*
|
|
@@ -605,10 +667,31 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
605
667
|
*/
|
|
606
668
|
addVerificationInfoAsync(jsonOptions: JsonObject, outFilePath: string): Promise<void>
|
|
607
669
|
|
|
670
|
+
/**
|
|
671
|
+
* The same as {@link Pdf.addVerificationInfo}, except that the updated PDF stays in memory
|
|
672
|
+
* instead of being written to a file. Call {@link Pdf.writeFile} or {@link Pdf.writeBd} to write
|
|
673
|
+
* it, or go on to other operations first: the DSS (Document Security Store) with the
|
|
674
|
+
* certificates, OCSP responses and CRLs of the existing signatures is part of the loaded document
|
|
675
|
+
* as soon as this method returns.
|
|
676
|
+
*
|
|
677
|
+
* Changes pending from other methods are committed first; the DSS itself is added as an
|
|
678
|
+
* incremental update, which leaves the existing signatures valid. Pass an empty `jsonOptions` (a
|
|
679
|
+
* placeholder for future options).
|
|
680
|
+
*
|
|
681
|
+
* Returns `true` on success and `false` on failure.
|
|
682
|
+
*
|
|
683
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
684
|
+
* {@link Pdf.lastErrorText}.
|
|
685
|
+
*/
|
|
686
|
+
addVerificationInfo2(jsonOptions: JsonObject): void
|
|
687
|
+
|
|
608
688
|
/**
|
|
609
689
|
* Signs the open PDF and if successful writes the signed PDF to the `bd`. The `jsonOptions`
|
|
610
|
-
* contains information and instructions about the signature.
|
|
611
|
-
* the
|
|
690
|
+
* contains information and instructions about the signature. This object keeps its state from
|
|
691
|
+
* before the call; to sign the loaded document in place (and sign again, or add a DocTimeStamp,
|
|
692
|
+
* without reloading), use {@link Pdf.signPdf2}. Starting in v11.7.0, changes pending from other
|
|
693
|
+
* methods are committed before the signature is added. See the reference documentation for the
|
|
694
|
+
* SignPdf method for details about `jsonOptions`.
|
|
612
695
|
*
|
|
613
696
|
* This call blocks the JavaScript thread until Chilkat returns; from UI code prefer
|
|
614
697
|
* {@link Pdf.signPdfBdAsync}.
|
|
@@ -629,6 +712,25 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
629
712
|
*/
|
|
630
713
|
signPdfBdAsync(jsonOptions: JsonObject, bd: BinData): Promise<void>
|
|
631
714
|
|
|
715
|
+
/**
|
|
716
|
+
* The same as {@link Pdf.signPdf}, except that the signed PDF stays in memory instead of being
|
|
717
|
+
* written to a file. Call {@link Pdf.writeFile} or {@link Pdf.writeBd} to write it, or go on to
|
|
718
|
+
* other operations first: the signature is part of the loaded document as soon as this method
|
|
719
|
+
* returns, so {@link Pdf.numSignatures} and {@link Pdf.verifySignature} see it, and a second call
|
|
720
|
+
* adds another signature (or a DocTimeStamp) on top of it.
|
|
721
|
+
*
|
|
722
|
+
* Changes pending from other methods (a watermark added, a security change, an optimization,
|
|
723
|
+
* replaced text) are committed first, so the signature covers the document's current state; the
|
|
724
|
+
* signature itself is added as an incremental update, which leaves earlier signatures valid. See
|
|
725
|
+
* {@link Pdf.signPdf} for the members of `jsonOptions`.
|
|
726
|
+
*
|
|
727
|
+
* Returns `true` on success and `false` on failure.
|
|
728
|
+
*
|
|
729
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
730
|
+
* {@link Pdf.lastErrorText}.
|
|
731
|
+
*/
|
|
732
|
+
signPdf2(jsonOptions: JsonObject): void
|
|
733
|
+
|
|
632
734
|
/**
|
|
633
735
|
* Gets information about the Nth embedded file contained in the currently open PDF. The `index`
|
|
634
736
|
* specifies the index of the embedded file. The 1st embedded file is at index 0. The `json` is
|
|
@@ -688,8 +790,11 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
688
790
|
addEmbeddedFilesBd(json: JsonObject, bd: BinData): void
|
|
689
791
|
|
|
690
792
|
/**
|
|
691
|
-
* Updates or adds XMP
|
|
692
|
-
* with updated or inserted metadata is written to `outFilePath
|
|
793
|
+
* Updates or adds XMP metadata to a PDF. The metadata is passed in `sb`. If successful, the PDF
|
|
794
|
+
* with updated or inserted metadata is written to `outFilePath`, and the loaded document is the
|
|
795
|
+
* updated PDF. To update the metadata of the loaded document without writing a file, use {@link
|
|
796
|
+
* Pdf.updateMetadata2}. Starting in v11.7.0, changes pending from other methods are committed
|
|
797
|
+
* before the metadata is updated.
|
|
693
798
|
*
|
|
694
799
|
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
695
800
|
* {@link Pdf.lastErrorText}.
|
|
@@ -697,8 +802,26 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
697
802
|
updateMetadata(sb: StringBuilder, outFilePath: string): void
|
|
698
803
|
|
|
699
804
|
/**
|
|
700
|
-
*
|
|
701
|
-
*
|
|
805
|
+
* The same as {@link Pdf.updateMetadata}, except that the updated PDF stays in memory instead of
|
|
806
|
+
* being written to a file. The XMP metadata is passed in `sb` and replaces the document's
|
|
807
|
+
* metadata (or is added when the document has none). Call {@link Pdf.writeFile} or {@link
|
|
808
|
+
* Pdf.writeBd} to write it, or go on to other operations first: the new metadata is part of the
|
|
809
|
+
* loaded document as soon as this method returns ({@link Pdf.getMetadata} returns it).
|
|
810
|
+
*
|
|
811
|
+
* Changes pending from other methods are committed first; the metadata itself is added as an
|
|
812
|
+
* incremental update, which leaves existing signatures valid.
|
|
813
|
+
*
|
|
814
|
+
* Returns `true` on success and `false` on failure.
|
|
815
|
+
*
|
|
816
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
817
|
+
* {@link Pdf.lastErrorText}.
|
|
818
|
+
*/
|
|
819
|
+
updateMetadata2(sb: StringBuilder): void
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Updates or adds XMP metadata to a PDF. The metadata is passed in `sb`. If successful, the PDF
|
|
823
|
+
* with updated or inserted metadata is written to `bd`, and the loaded document is the updated
|
|
824
|
+
* PDF. See {@link Pdf.updateMetadata}.
|
|
702
825
|
*
|
|
703
826
|
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
704
827
|
* {@link Pdf.lastErrorText}.
|
|
@@ -713,6 +836,1354 @@ export interface Pdf extends HybridObject<{ ios: 'c++', android: 'c++' }> {
|
|
|
713
836
|
*/
|
|
714
837
|
getLastJsonData(json: JsonObject): void
|
|
715
838
|
|
|
839
|
+
/**
|
|
840
|
+
* Measures and shrinks the loaded PDF without changing how any page looks. The `op` selects the
|
|
841
|
+
* operation, the `jsonIn` holds the options, and the `jsonOut` receives the report. Returns
|
|
842
|
+
* `true` on success and `false` on failure.
|
|
843
|
+
*
|
|
844
|
+
* **Operations (`op`)**
|
|
845
|
+
*
|
|
846
|
+
* - **audit** - Reports where the file's bytes go, by category, and what each option would save.
|
|
847
|
+
* Changes nothing, and is allowed on any PDF. The same options as `optimize` select which
|
|
848
|
+
* savings to estimate.
|
|
849
|
+
*
|
|
850
|
+
* - **optimize** - Applies the selected options to the PDF in memory and reports what was done
|
|
851
|
+
* and the bytes saved per option. The result is written by {@link Pdf.writeFile} or {@link
|
|
852
|
+
* Pdf.writeBd}.
|
|
853
|
+
*
|
|
854
|
+
* Every option is lossless: pages render identically before and after. JPEG, JPEG 2000, JBIG2 and
|
|
855
|
+
* CCITT image data are never re-encoded. Most of the work is done in memory during the `optimize`
|
|
856
|
+
* call, so its savings are exact; two options (`objectStreams` and `dropOldRevisions`) take
|
|
857
|
+
* effect when the PDF is written, so their savings are estimates until then.
|
|
858
|
+
*
|
|
859
|
+
* **Summary of JSON Options (`jsonIn`)**
|
|
860
|
+
*
|
|
861
|
+
* An empty `jsonIn` applies the `lossless` preset, which is every option below at its default.
|
|
862
|
+
* Any option can be set to override the preset.
|
|
863
|
+
*
|
|
864
|
+
* \*General\*
|
|
865
|
+
*
|
|
866
|
+
* - **preset** - `lossless`, the only preset and the default.
|
|
867
|
+
*
|
|
868
|
+
* - **pages** - Limits the page-level work (page content and resources) to these pages: a list of
|
|
869
|
+
* 1-based pages and ranges such as `1,3,5-9,12-`. The default is all pages. Document-wide work
|
|
870
|
+
* always applies to the whole file.
|
|
871
|
+
*
|
|
872
|
+
* \*Streams\*
|
|
873
|
+
*
|
|
874
|
+
* - **compressUncompressed** - Boolean (default \*true\*). Flate-encodes streams stored with no
|
|
875
|
+
* filter.
|
|
876
|
+
*
|
|
877
|
+
* - **recompressFlate** - Boolean (default \*true\*). Re-deflates Flate streams at
|
|
878
|
+
* `compressionLevel`, keeping the result only if it is smaller.
|
|
879
|
+
*
|
|
880
|
+
* - **replaceLegacyFilters** - Boolean (default \*true\*). Re-encodes LZW, ASCIIHex, ASCII85 and
|
|
881
|
+
* RunLength streams as Flate, including chains of several such stages (a RunLength stream that
|
|
882
|
+
* was then Flate-encoded, say), which become one Flate stream. These streams are always
|
|
883
|
+
* re-encoded, even in the rare case where the Flate stream comes out a little larger than the
|
|
884
|
+
* original chain. A chain that includes an image filter or an unknown filter is left as it is.
|
|
885
|
+
*
|
|
886
|
+
* - **imagePredictors** - Boolean (default \*true\*). Tries PNG predictors on uncompressed and
|
|
887
|
+
* Flate images, keeping the result only if it is smaller.
|
|
888
|
+
*
|
|
889
|
+
* - **compressionLevel** - The Flate level, 1 to 9, used by the options above. The default is
|
|
890
|
+
* `9`.
|
|
891
|
+
*
|
|
892
|
+
* \*Duplicates\*
|
|
893
|
+
*
|
|
894
|
+
* - **dedupeStreams** - Boolean (default \*true\*). Stores byte-identical streams with identical
|
|
895
|
+
* dictionaries once: images, embedded fonts, form XObjects, ICC profiles and page content.
|
|
896
|
+
*
|
|
897
|
+
* - **dedupeObjects** - Boolean (default \*true\*). Stores identical non-stream objects (font
|
|
898
|
+
* dictionaries, color spaces, graphics states) once.
|
|
899
|
+
*
|
|
900
|
+
* - **mergeFontSubsets** - Boolean (default \*false\*). Reserved for merging several subsets of
|
|
901
|
+
* the same font into one; not implemented in this release and reported in `skipped` when set.
|
|
902
|
+
*
|
|
903
|
+
* \*Unused content\*
|
|
904
|
+
*
|
|
905
|
+
* - **removeUnreferenced** - Boolean (default \*true\*). Drops objects not reachable from the
|
|
906
|
+
* document catalog.
|
|
907
|
+
*
|
|
908
|
+
* - **removeUnusedResources** - Boolean (default \*true\*). Drops entries in page and form
|
|
909
|
+
* resource dictionaries that the content never uses.
|
|
910
|
+
*
|
|
911
|
+
* - **removeUnusedLayers** - Boolean (default \*true\*). Drops optional-content layers that no
|
|
912
|
+
* content refers to, such as the empty "Watermark" layer Acrobat leaves behind after removing a
|
|
913
|
+
* watermark.
|
|
914
|
+
*
|
|
915
|
+
* \*Page content\*
|
|
916
|
+
*
|
|
917
|
+
* - **coalesceContent** - Boolean (default \*true\*). Merges a page's multiple content streams
|
|
918
|
+
* into one, so that they compress together.
|
|
919
|
+
*
|
|
920
|
+
* - **tidyContent** - Boolean (default \*true\*). Removes redundant white space, empty q/Q pairs
|
|
921
|
+
* and graphics-state operators that change nothing. Numbers are never rounded and
|
|
922
|
+
* marked-content tags are never dropped.
|
|
923
|
+
*
|
|
924
|
+
* \*Fonts\*
|
|
925
|
+
*
|
|
926
|
+
* - **subsetFonts** - Boolean (default \*true\*). Reduces fully embedded TrueType/OpenType fonts
|
|
927
|
+
* (CIDFontType2 with a FontFile2 program) to the glyphs used. Fonts that form fields need for
|
|
928
|
+
* newly typed text are left whole, as are Type 1, CFF and already-subset fonts.
|
|
929
|
+
*
|
|
930
|
+
* - **compactType1Fonts** - Boolean (default \*false\*). Reserved for converting embedded Type 1
|
|
931
|
+
* fonts to CFF; not implemented in this release and reported in `skipped` when set.
|
|
932
|
+
*
|
|
933
|
+
* \*File structure\*
|
|
934
|
+
*
|
|
935
|
+
* - **objectStreams** - `generate` (the default), `preserve`, or `disable`. `generate` packs
|
|
936
|
+
* small objects into compressed object streams with a cross-reference stream (PDF 1.5; the
|
|
937
|
+
* file's version is raised to 1.5 if lower, never lowered). `preserve` generates them only if
|
|
938
|
+
* the file already had them. `disable` writes classic objects and a classic cross-reference
|
|
939
|
+
* table, for consumers that cannot read object streams.
|
|
940
|
+
*
|
|
941
|
+
* - **dropOldRevisions** - Boolean (default \*true\*). Saves a single revision, discarding the
|
|
942
|
+
* superseded content kept by earlier incremental updates. This is also a privacy gain, since
|
|
943
|
+
* old revisions can hold deleted text.
|
|
944
|
+
*
|
|
945
|
+
* **Results (`jsonOut`)**
|
|
946
|
+
*
|
|
947
|
+
* For `audit`:
|
|
948
|
+
*
|
|
949
|
+
* - **fileSize**, **pdfVersion**, **pdfa** - The file size in bytes, the PDF version, and the
|
|
950
|
+
* PDF/A part and conformance the file claims (such as `2b`), or `none`.
|
|
951
|
+
*
|
|
952
|
+
* - **usage** - Where the bytes go, as stored (compressed) in the file: **images**, **fonts**,
|
|
953
|
+
* **pageContent**, **formXObjects**, **annotations**, **structureTree**, **metadata**,
|
|
954
|
+
* **embeddedFiles**, **oldRevisions** and **overhead** (cross-reference data, object headers
|
|
955
|
+
* and everything not counted elsewhere), each with **bytes** and, where it makes sense,
|
|
956
|
+
* **count**. The categories cover the whole file, including those the lossless options cannot
|
|
957
|
+
* touch.
|
|
958
|
+
*
|
|
959
|
+
* - **estimatedSavings** - **total**, and the estimated bytes saved by each option, by option
|
|
960
|
+
* name. Options that would save nothing are omitted.
|
|
961
|
+
*
|
|
962
|
+
* For `optimize`:
|
|
963
|
+
*
|
|
964
|
+
* - **fileSize** - The size of the PDF as loaded, so that the saving can be measured against the
|
|
965
|
+
* file written afterwards.
|
|
966
|
+
*
|
|
967
|
+
* - **bytesSaved** - The bytes the options above account for. The file written afterwards is
|
|
968
|
+
* usually smaller still: rewriting the document also packs objects into object streams, writes
|
|
969
|
+
* a compact cross-reference stream and leaves the old cross-reference sections behind, none of
|
|
970
|
+
* which belongs to a particular option. The exact saving is **fileSize** minus the size of the
|
|
971
|
+
* written file.
|
|
972
|
+
*
|
|
973
|
+
* - **bytesSavedIsEstimate** - Boolean: `true` while a save-time option (`objectStreams`,
|
|
974
|
+
* `dropOldRevisions`) contributes.
|
|
975
|
+
*
|
|
976
|
+
* - **actions** - Per option name: **count** (the objects affected, where it makes sense),
|
|
977
|
+
* **bytesSaved**, and **estimate** \*true\* for the save-time options.
|
|
978
|
+
*
|
|
979
|
+
* For both:
|
|
980
|
+
*
|
|
981
|
+
* - **skipped\[i\]** - Options that were requested but not applied: **option**, **pages** (when
|
|
982
|
+
* page-specific) and **reason**, such as page content that could not be parsed, a reserved
|
|
983
|
+
* option, or `objectStreams` on a PDF/A-1 file.
|
|
984
|
+
*
|
|
985
|
+
* **Signed, encrypted and PDF/A files**
|
|
986
|
+
*
|
|
987
|
+
* Optimizing rewrites the whole file. With {@link Pdf.preserveSignatures} \*true\* (the default),
|
|
988
|
+
* `optimize` fails on a signed PDF; with it \*false\*, the file is optimized and its signatures
|
|
989
|
+
* are invalidated. An encrypted PDF is saved with its original security unchanged, and `optimize`
|
|
990
|
+
* requires owner rights or the modify permission. A PDF/A file stays within its part's rules: for
|
|
991
|
+
* PDF/A-1 object streams are skipped, the output intent and XMP metadata are kept, and fonts stay
|
|
992
|
+
* embedded (subsetting is allowed). The structure tree of a tagged PDF is never touched.
|
|
993
|
+
*
|
|
994
|
+
* **Example: audit**
|
|
995
|
+
*
|
|
996
|
+
* ```
|
|
997
|
+
* jsonOut: { "fileSize": 4831022, "pdfVersion": "1.4", "pdfa": "none",
|
|
998
|
+
* "usage": { "images": { "bytes": 3120455, "count": 41 }, "fonts": { "bytes": 1204310, "count": 12 },
|
|
999
|
+
* "pageContent": { "bytes": 288112, "count": 60 }, "formXObjects": { "bytes": 61200, "count": 9 },
|
|
1000
|
+
* "annotations": { "bytes": 8400, "count": 22 }, "structureTree": { "bytes": 51020 },
|
|
1001
|
+
* "metadata": { "bytes": 6400 }, "embeddedFiles": { "bytes": 0, "count": 0 },
|
|
1002
|
+
* "oldRevisions": { "bytes": 18210 }, "overhead": { "bytes": 72915 } },
|
|
1003
|
+
* "estimatedSavings": { "total": 1290410, "subsetFonts": 942000, "dedupeStreams": 211800,
|
|
1004
|
+
* "objectStreams": 54300, "recompressFlate": 41210, "dropOldRevisions": 18210,
|
|
1005
|
+
* "removeUnreferenced": 12890, "coalesceContent": 10000 } }
|
|
1006
|
+
* ```
|
|
1007
|
+
*
|
|
1008
|
+
* **Example: optimize with the defaults, then write the file**
|
|
1009
|
+
*
|
|
1010
|
+
* ```
|
|
1011
|
+
* jsonIn: { }
|
|
1012
|
+
* pdf.Optimize("optimize", jsonIn, jsonOut)
|
|
1013
|
+
* pdf.WriteFile("out.pdf")
|
|
1014
|
+
* jsonOut: { "fileSize": 4831022, "bytesSaved": 1236110, "bytesSavedIsEstimate": true,
|
|
1015
|
+
* "actions": { "subsetFonts": { "count": 7, "bytesSaved": 942000 },
|
|
1016
|
+
* "dedupeStreams": { "count": 39, "bytesSaved": 211800 },
|
|
1017
|
+
* "objectStreams": { "bytesSaved": 54300, "estimate": true },
|
|
1018
|
+
* "recompressFlate": { "count": 88, "bytesSaved": 41210 },
|
|
1019
|
+
* "removeUnreferenced": { "count": 17, "bytesSaved": 12890 } },
|
|
1020
|
+
* "skipped": [ { "option": "tidyContent", "pages": "12", "reason": "content could not be parsed; left unchanged" } ] }
|
|
1021
|
+
* ```
|
|
1022
|
+
*
|
|
1023
|
+
* **Example: override individual options**
|
|
1024
|
+
*
|
|
1025
|
+
* ```
|
|
1026
|
+
* jsonIn: { "objectStreams": "disable", "dropOldRevisions": false }
|
|
1027
|
+
* ```
|
|
1028
|
+
*
|
|
1029
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1030
|
+
* {@link Pdf.lastErrorText}.
|
|
1031
|
+
*/
|
|
1032
|
+
optimize(op: string, jsonIn: JsonObject, jsonOut: JsonObject): void
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Writes the loaded PDF, with every change made since it was loaded, to the file at `path`. The
|
|
1036
|
+
* changes written are those made by {@link Pdf.watermark} (`add` and `remove`), {@link
|
|
1037
|
+
* Pdf.protection}, {@link Pdf.optimize} and {@link Pdf.textReplace} (`apply`), which are kept in
|
|
1038
|
+
* memory until this method or {@link Pdf.writeBd} is called. Files embedded with {@link
|
|
1039
|
+
* Pdf.addEmbeddedFiles2} are already part of the loaded document and are written as well. Returns
|
|
1040
|
+
* `true` on success and `false` on failure.
|
|
1041
|
+
*
|
|
1042
|
+
* When nothing requires more, the PDF is written as an incremental update: the original bytes are
|
|
1043
|
+
* kept and the changes are appended, which leaves existing digital signatures valid. The file is
|
|
1044
|
+
* written in full (a rewrite) when a change requires it: an {@link Pdf.optimize} with
|
|
1045
|
+
* `dropOldRevisions` or generated object streams, a change of security by {@link Pdf.protection},
|
|
1046
|
+
* or a {@link Pdf.textReplace} `apply`. A rewrite invalidates existing signatures, which is why
|
|
1047
|
+
* those operations are refused on a signed PDF while {@link Pdf.preserveSignatures} is `true`.
|
|
1048
|
+
*
|
|
1049
|
+
* After writing, this object reloads the PDF it wrote, so that later calls work on the saved
|
|
1050
|
+
* state. With no changes pending, the PDF is written as it was loaded.
|
|
1051
|
+
*
|
|
1052
|
+
* To sign a PDF, use {@link Pdf.signPdf2}, which adds the signature to the loaded document (this
|
|
1053
|
+
* method then writes it), or {@link Pdf.signPdf} / {@link Pdf.signPdfBd}, which write the signed
|
|
1054
|
+
* PDF themselves.
|
|
1055
|
+
*
|
|
1056
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1057
|
+
* {@link Pdf.lastErrorText}.
|
|
1058
|
+
*/
|
|
1059
|
+
writeFile(path: string): void
|
|
1060
|
+
|
|
1061
|
+
/**
|
|
1062
|
+
* The same as {@link Pdf.writeFile}, but the PDF is written to `bd` (a BinData object) instead of
|
|
1063
|
+
* a file. See {@link Pdf.writeFile} for what is written and when the file is rewritten in full.
|
|
1064
|
+
*
|
|
1065
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1066
|
+
* {@link Pdf.lastErrorText}.
|
|
1067
|
+
*/
|
|
1068
|
+
writeBd(bd: BinData): void
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Adds, detects, lists and removes watermarks in the loaded PDF. The `op` selects the operation,
|
|
1072
|
+
* the `jsonIn` holds the options or the filter, and the `jsonOut` receives the result. Returns
|
|
1073
|
+
* `true` on success and `false` on failure. Finding nothing is still success: `detect` returns
|
|
1074
|
+
* `true` with `found` false, and `remove` returns `true` with `removed` 0. Changes are made in
|
|
1075
|
+
* memory and are written when {@link Pdf.writeFile} or {@link Pdf.writeBd} is called.
|
|
1076
|
+
*
|
|
1077
|
+
* **Operations (`op`)**
|
|
1078
|
+
*
|
|
1079
|
+
* - **add** - Adds one watermark (text, an image, or a page of another PDF) to the selected
|
|
1080
|
+
* pages. `jsonOut` receives the `id` of the new watermark and the `pages` it was added to. A
|
|
1081
|
+
* text watermark plus a logo is two calls.
|
|
1082
|
+
*
|
|
1083
|
+
* - **detect** - Answers whether any watermark matching the filter is present. `jsonOut` receives
|
|
1084
|
+
* `found` and `count`.
|
|
1085
|
+
*
|
|
1086
|
+
* - **list** - Enumerates the matching watermarks with their properties. `jsonOut` receives
|
|
1087
|
+
* `count` and a `watermarks` array.
|
|
1088
|
+
*
|
|
1089
|
+
* - **remove** - Removes the matching watermarks. `jsonOut` receives `removed`, the number
|
|
1090
|
+
* removed. An empty filter is refused unless `all` is \*true\*.
|
|
1091
|
+
*
|
|
1092
|
+
* **How a watermark is stored (the approach)**
|
|
1093
|
+
*
|
|
1094
|
+
* The `approach` member of `jsonIn` selects how an added watermark is stored, which decides
|
|
1095
|
+
* whether it can be found and removed later:
|
|
1096
|
+
*
|
|
1097
|
+
* - **artifact** - (the default) Marked content tagged as a Watermark or Background artifact.
|
|
1098
|
+
* Visible in all viewers, removable later, skipped by text extraction.
|
|
1099
|
+
*
|
|
1100
|
+
* - **annotation** - A Watermark annotation. Always drawn on top, removable later; the only
|
|
1101
|
+
* approach allowed on a signed PDF while {@link Pdf.preserveSignatures} is \*true\*.
|
|
1102
|
+
*
|
|
1103
|
+
* - **layer** - An optional-content layer, which the viewer's layers panel can hide, and which
|
|
1104
|
+
* can be made print-only. Removable later.
|
|
1105
|
+
*
|
|
1106
|
+
* - **content** - Drawn directly into the page content with no identifying marker. Visible in all
|
|
1107
|
+
* viewers and the tamper-resistant choice, but by design it cannot be listed or removed
|
|
1108
|
+
* afterwards.
|
|
1109
|
+
*
|
|
1110
|
+
* For every approach except `content`, Chilkat stores a private identifier with the watermark;
|
|
1111
|
+
* that is what lets `list` and `remove` target it later.
|
|
1112
|
+
*
|
|
1113
|
+
* **Summary of JSON Options for add (`jsonIn`)**
|
|
1114
|
+
*
|
|
1115
|
+
* Only `type` and the content for that type are required; every other member has a default.
|
|
1116
|
+
* Members are given as dotted paths, as used with the JsonObject update methods.
|
|
1117
|
+
*
|
|
1118
|
+
* \*General\*
|
|
1119
|
+
*
|
|
1120
|
+
* - **approach** - `artifact` (the default), `annotation`, `layer`, or `content`. See above.
|
|
1121
|
+
*
|
|
1122
|
+
* - **id** - A string identifying the watermark, returned in `jsonOut` and used by `list` and
|
|
1123
|
+
* `remove`. Generated when not given. An id already present in the document is refused. Not
|
|
1124
|
+
* stored for the `content` approach.
|
|
1125
|
+
*
|
|
1126
|
+
* - **label** - A free-form description stored with the watermark and returned by `list`.
|
|
1127
|
+
*
|
|
1128
|
+
* - **zOrder** - `front` (the default) or `back`: in front of or behind the existing page
|
|
1129
|
+
* content. Ignored for the `annotation` approach, which is always in front.
|
|
1130
|
+
*
|
|
1131
|
+
* - **pages** - The pages to stamp. Can be `all` (the default), `first`, `last`, `odd`, `even`,
|
|
1132
|
+
* or a list of 1-based pages and ranges such as `1,3,5-9,12-`.
|
|
1133
|
+
*
|
|
1134
|
+
* - **excludePages** - A range list of pages to leave out, applied after `pages`.
|
|
1135
|
+
*
|
|
1136
|
+
* - **units** - `pt` (the default), `in`, `mm`, or `cm`: the units of the image size, wrap width,
|
|
1137
|
+
* padding, margins, offsets, maximum sizes and tile spacing. Font size, outline width and
|
|
1138
|
+
* border width are always in points.
|
|
1139
|
+
*
|
|
1140
|
+
* - **pageBox** - `crop` (the default) or `media`: the page box that placement is measured
|
|
1141
|
+
* against.
|
|
1142
|
+
*
|
|
1143
|
+
* - **followPageRotation** - Boolean (default \*true\*). Keeps the watermark upright for the
|
|
1144
|
+
* reader on pages that have a /Rotate setting.
|
|
1145
|
+
*
|
|
1146
|
+
* \*Content\*
|
|
1147
|
+
*
|
|
1148
|
+
* - **type** - Required: `text`, `image`, or `pdfPage`. Any type can be stored with any approach.
|
|
1149
|
+
* (`barcode` is reserved for a later release; an existing barcode or QR image can be added as
|
|
1150
|
+
* an `image`.)
|
|
1151
|
+
*
|
|
1152
|
+
* - **text** - Required for `text`. A newline breaks lines. Placeholders are replaced per page:
|
|
1153
|
+
* `{page}` (the page number), `{pages}` (the page count), `{date:FORMAT}` (the current local
|
|
1154
|
+
* date/time, with `yyyy`, `yy`, `M`/`MM`, `d`/`dd`, `H`/`HH`, `h`/`hh`, `m`/`mm`, `s`/`ss` and
|
|
1155
|
+
* `tt` for AM/PM; the format defaults to `yyyy-MM-dd`), and `{filename}` (the name of the file
|
|
1156
|
+
* loaded by {@link Pdf.loadFile}). `{{` gives a literal brace.
|
|
1157
|
+
*
|
|
1158
|
+
* - **image.path** or **image.base64** - Required for `image`: the path of a JPEG or PNG file, or
|
|
1159
|
+
* its data in base64. PNG transparency is kept. Interlaced PNGs are not supported.
|
|
1160
|
+
*
|
|
1161
|
+
* - **image.width**, **image.height** - The size to draw the image at. Give one of the two to
|
|
1162
|
+
* keep the aspect ratio; the default is the image's natural size.
|
|
1163
|
+
*
|
|
1164
|
+
* - **pdf.path** or **pdf.base64** - Required for `pdfPage`: another PDF whose page is placed as
|
|
1165
|
+
* the watermark, such as a letterhead, a cover overlay, or a vector logo saved as PDF.
|
|
1166
|
+
*
|
|
1167
|
+
* - **pdf.password** - The password of the source PDF, if it is encrypted.
|
|
1168
|
+
*
|
|
1169
|
+
* - **pdf.page** - The 1-based page of the source PDF to use (default `1`), or `match` to place
|
|
1170
|
+
* source page n on target page n, cycling when the source has fewer pages.
|
|
1171
|
+
*
|
|
1172
|
+
* \*Text styling (type = text)\*
|
|
1173
|
+
*
|
|
1174
|
+
* - **font.name** - `Helvetica` (the default), another standard-14 font name such as
|
|
1175
|
+
* `Times-Roman` or `Courier`, or the path of a TTF/OTF font file, which is embedded as a
|
|
1176
|
+
* subset. Symbol and ZapfDingbats are not supported.
|
|
1177
|
+
*
|
|
1178
|
+
* - **font.size** - The size in points (default `48`), or `auto` to size the text to the box
|
|
1179
|
+
* chosen by `scale.fit`.
|
|
1180
|
+
*
|
|
1181
|
+
* - **font.bold**, **font.italic**, **font.underline**, **font.strikeout** - Booleans (default
|
|
1182
|
+
* \*false\*). Bold and italic select the matching standard-14 face, or are synthesized for an
|
|
1183
|
+
* embedded font file.
|
|
1184
|
+
*
|
|
1185
|
+
* - **color** - The fill color: `#RRGGBB`, `#RGB`, or a color name such as `red` or `gray`. The
|
|
1186
|
+
* default is `#808080`.
|
|
1187
|
+
*
|
|
1188
|
+
* - **render** - `fill` (the default), `stroke` (outlined, hollow text), `fillStroke`, or
|
|
1189
|
+
* `invisible` (present and searchable, but not seen).
|
|
1190
|
+
*
|
|
1191
|
+
* - **outline.color**, **outline.width** - The outline color (default `#000000`) and width in
|
|
1192
|
+
* points (default `1`), used by `stroke` and `fillStroke`.
|
|
1193
|
+
*
|
|
1194
|
+
* - **textAlign** - `center` (the default), `left`, or `right`: the alignment of multi-line text
|
|
1195
|
+
* within its own box.
|
|
1196
|
+
*
|
|
1197
|
+
* - **lineSpacing** - The line spacing as a multiple of the font size. The default is `1.2`.
|
|
1198
|
+
*
|
|
1199
|
+
* - **wrapWidth** - Wraps long text to this width. The default is no wrapping.
|
|
1200
|
+
*
|
|
1201
|
+
* - **pageNumber.start** - The value of `{page}` on the first page. The default is `1`.
|
|
1202
|
+
*
|
|
1203
|
+
* - **pageNumber.style** - The format of `{page}` and `{pages}`: `decimal` (the default),
|
|
1204
|
+
* `romanUpper`, `romanLower`, `letterUpper`, or `letterLower`.
|
|
1205
|
+
*
|
|
1206
|
+
* - **background.color**, **background.opacity**, **background.padding** - A box filled behind
|
|
1207
|
+
* the stamp (text or image): its color (none by default), opacity (default `1.0`) and the space
|
|
1208
|
+
* between the content and the box edge (default `0`).
|
|
1209
|
+
*
|
|
1210
|
+
* - **border.color**, **border.width** - A box stroked around the stamp: its color (none by
|
|
1211
|
+
* default) and width in points (default `1`).
|
|
1212
|
+
*
|
|
1213
|
+
* \*Appearance\*
|
|
1214
|
+
*
|
|
1215
|
+
* - **opacity** - From 0.0 to 1.0 (default `1.0`), applied to the whole stamp.
|
|
1216
|
+
*
|
|
1217
|
+
* - **rotation** - Degrees counter-clockwise (default `0`), or `diagonal` (bottom-left to
|
|
1218
|
+
* top-right, computed per page size) or `diagonalReverse`.
|
|
1219
|
+
*
|
|
1220
|
+
* - **blendMode** - `normal` (the default), `multiply`, `darken`, `lighten`, `screen`, or
|
|
1221
|
+
* `overlay`. `multiply` makes a front watermark read as if it were behind scanned pages.
|
|
1222
|
+
*
|
|
1223
|
+
* \*Placement and scaling\*
|
|
1224
|
+
*
|
|
1225
|
+
* - **position.align** - `center` (the default), `top`, `bottom`, `left`, `right`, `topLeft`,
|
|
1226
|
+
* `topRight`, `bottomLeft`, or `bottomRight`.
|
|
1227
|
+
*
|
|
1228
|
+
* - **position.margin** - The inset from the page edges, used for alignment and fitting: a single
|
|
1229
|
+
* number, or an object with `left`, `top`, `right` and `bottom`. The default is `0`.
|
|
1230
|
+
*
|
|
1231
|
+
* - **position.offsetX**, **position.offsetY** - A nudge from the aligned position (default `0`);
|
|
1232
|
+
* positive values move right and down.
|
|
1233
|
+
*
|
|
1234
|
+
* - **scale.factor** - Multiplies the natural size. The default is `1.0`.
|
|
1235
|
+
*
|
|
1236
|
+
* - **scale.fit** - `none` (the default), `page`, `width`, or `height`: fits the rotated stamp
|
|
1237
|
+
* inside the margin box.
|
|
1238
|
+
*
|
|
1239
|
+
* - **scale.fitPercent** - The share of the fit box to fill. The default is `100`.
|
|
1240
|
+
*
|
|
1241
|
+
* - **scale.maxWidth**, **scale.maxHeight** - Caps on the final size. No cap by default.
|
|
1242
|
+
*
|
|
1243
|
+
* - **tile.enabled** - Boolean (default \*false\*). Repeats the stamp across the page, which
|
|
1244
|
+
* overrides `position.align`.
|
|
1245
|
+
*
|
|
1246
|
+
* - **tile.spacingX**, **tile.spacingY** - The gaps between tiles. The default is `72` points for
|
|
1247
|
+
* each.
|
|
1248
|
+
*
|
|
1249
|
+
* - **tile.stagger** - Boolean (default \*true\*). Offsets alternate rows by half a tile.
|
|
1250
|
+
*
|
|
1251
|
+
* \*Approach-specific\*
|
|
1252
|
+
*
|
|
1253
|
+
* - **annotation.view**, **annotation.print** - Booleans (default \*true\*). `view` false with
|
|
1254
|
+
* `print` true gives a print-only watermark.
|
|
1255
|
+
*
|
|
1256
|
+
* - **annotation.locked** - Boolean (default \*true\*). Users cannot move or delete the
|
|
1257
|
+
* annotation in a viewer.
|
|
1258
|
+
*
|
|
1259
|
+
* - **annotation.fixedPrint** - Boolean (default \*false\*). Keeps the printed size and position
|
|
1260
|
+
* fixed whatever the paper size.
|
|
1261
|
+
*
|
|
1262
|
+
* - **artifact.subtype** - `Watermark` (the default) or `Background`: the artifact subtype
|
|
1263
|
+
* written to the marked content.
|
|
1264
|
+
*
|
|
1265
|
+
* - **artifact.acrobatCompatible** - Boolean (default \*false\*). Also writes the structure that
|
|
1266
|
+
* Acrobat's own watermark tool uses, so that Acrobat can update or remove the watermark.
|
|
1267
|
+
*
|
|
1268
|
+
* - **layer.name** - The name shown in the viewer's layers panel. The default is `Watermark`. An
|
|
1269
|
+
* existing layer of the same name is reused.
|
|
1270
|
+
*
|
|
1271
|
+
* - **layer.view**, **layer.print** - `on` (the default) or `off`. `view` off with `print` on
|
|
1272
|
+
* gives a print-only watermark.
|
|
1273
|
+
*
|
|
1274
|
+
* - **layer.locked** - Boolean (default \*false\*). Prevents users from toggling the layer in the
|
|
1275
|
+
* layers panel.
|
|
1276
|
+
*
|
|
1277
|
+
* \*Extras\*
|
|
1278
|
+
*
|
|
1279
|
+
* - **link.url** - Adds a link annotation over the stamp's area on each page, opening this URL.
|
|
1280
|
+
*
|
|
1281
|
+
* **The filter for detect, list and remove (`jsonIn`)**
|
|
1282
|
+
*
|
|
1283
|
+
* An empty filter means every watermark in the document. These operations recognize Chilkat's own
|
|
1284
|
+
* watermarks and the standard forms other tools write: Watermark annotations from any producer,
|
|
1285
|
+
* marked content tagged as a Watermark or Background artifact, Acrobat watermarks and backgrounds
|
|
1286
|
+
* (Acrobat headers and footers are not watermarks and are ignored), and optional-content layers
|
|
1287
|
+
* whose name contains "watermark".
|
|
1288
|
+
*
|
|
1289
|
+
* - **pages** - Restricts the operation to these pages; the same syntax as for `add`. The default
|
|
1290
|
+
* is `all`.
|
|
1291
|
+
*
|
|
1292
|
+
* - **approach** - `any` (the default), or one of `annotation`, `artifact`, `layer`, `content`.
|
|
1293
|
+
*
|
|
1294
|
+
* - **source** - `any` (the default), `chilkat`, `acrobat`, or `other`: who produced the
|
|
1295
|
+
* watermark.
|
|
1296
|
+
*
|
|
1297
|
+
* - **id** - An exact match on the watermark's id.
|
|
1298
|
+
*
|
|
1299
|
+
* - **label** - An exact match on a Chilkat label.
|
|
1300
|
+
*
|
|
1301
|
+
* - **textContains** - A case-insensitive match on the watermark's text.
|
|
1302
|
+
*
|
|
1303
|
+
* - **heuristic** - Boolean (default \*false\*). Reserved for finding untagged page content that
|
|
1304
|
+
* looks like a watermark; accepted but not implemented in this release.
|
|
1305
|
+
*
|
|
1306
|
+
* - **all** - Boolean (default \*false\*). For `remove` only: required to remove with an
|
|
1307
|
+
* otherwise empty filter.
|
|
1308
|
+
*
|
|
1309
|
+
* **Results (`jsonOut`)**
|
|
1310
|
+
*
|
|
1311
|
+
* - **add** - **id** (the watermark's id, generated or as given) and **pages** (the pages it was
|
|
1312
|
+
* added to, such as `1-12`).
|
|
1313
|
+
*
|
|
1314
|
+
* - **detect** - **found** and **count**.
|
|
1315
|
+
*
|
|
1316
|
+
* - **list** - **count** and **watermarks\[i\]** with **id**, **label**, **source** (`chilkat`,
|
|
1317
|
+
* `acrobat` or `other`), **approach**, **type**, **text**, **zOrder**, **opacity**,
|
|
1318
|
+
* **rotation**, **removable** and **pages**. Watermarks from other producers have no id of
|
|
1319
|
+
* their own, so Chilkat assigns one (`ext1`, `ext2`, ...) that stays valid until the PDF is
|
|
1320
|
+
* changed, so that a `list` followed by a `remove` by id works. Properties that cannot be read
|
|
1321
|
+
* back are omitted rather than guessed.
|
|
1322
|
+
*
|
|
1323
|
+
* - **remove** - **removed**, the number of watermarks removed. An annotation is deleted; an
|
|
1324
|
+
* artifact's marked content, and any form XObject used only by it, is deleted; a layer's
|
|
1325
|
+
* content is deleted, and the layer itself once nothing else uses it. `content` watermarks are
|
|
1326
|
+
* never removable.
|
|
1327
|
+
*
|
|
1328
|
+
* **Signed and encrypted PDFs**
|
|
1329
|
+
*
|
|
1330
|
+
* On a signed PDF with {@link Pdf.preserveSignatures} \*true\* (the default), only the
|
|
1331
|
+
* `annotation` approach can be added and nothing can be removed, because any other change to the
|
|
1332
|
+
* page content would invalidate the signatures. Set {@link Pdf.preserveSignatures} to \*false\*
|
|
1333
|
+
* to allow such changes. An encrypted PDF must have been opened (see the {@link
|
|
1334
|
+
* Pdf.ownerPassword} and {@link Pdf.userPassword} properties), and adding or removing requires
|
|
1335
|
+
* owner rights or the modify permission.
|
|
1336
|
+
*
|
|
1337
|
+
* **Example: diagonal CONFIDENTIAL across every page, removable later**
|
|
1338
|
+
*
|
|
1339
|
+
* ```
|
|
1340
|
+
* jsonIn: { "type": "text", "text": "CONFIDENTIAL", "id": "conf",
|
|
1341
|
+
* "color": "#C00000", "opacity": 0.25, "rotation": "diagonal",
|
|
1342
|
+
* "scale": { "fit": "page", "fitPercent": 80 } }
|
|
1343
|
+
* jsonOut: { "id": "conf", "pages": "1-12" }
|
|
1344
|
+
* ```
|
|
1345
|
+
*
|
|
1346
|
+
* **Example: company logo bottom-right, printed only**
|
|
1347
|
+
*
|
|
1348
|
+
* ```
|
|
1349
|
+
* jsonIn: { "approach": "layer", "type": "image", "image": { "path": "logo.png", "width": 1.5 },
|
|
1350
|
+
* "units": "in", "layer": { "name": "Print logo", "view": "off", "print": "on" },
|
|
1351
|
+
* "position": { "align": "bottomRight", "margin": 0.5 } }
|
|
1352
|
+
* ```
|
|
1353
|
+
*
|
|
1354
|
+
* **Example: tiled user ID behind the content**
|
|
1355
|
+
*
|
|
1356
|
+
* ```
|
|
1357
|
+
* jsonIn: { "type": "text", "text": "jdoe@example.com {date:yyyy-MM-dd}", "zOrder": "back",
|
|
1358
|
+
* "font": { "size": 14 }, "opacity": 0.15, "rotation": 30,
|
|
1359
|
+
* "tile": { "enabled": true, "spacingX": 60, "spacingY": 80 } }
|
|
1360
|
+
* ```
|
|
1361
|
+
*
|
|
1362
|
+
* **Example: letterhead behind page 1 from another PDF**
|
|
1363
|
+
*
|
|
1364
|
+
* ```
|
|
1365
|
+
* jsonIn: { "approach": "artifact", "artifact": { "subtype": "Background" },
|
|
1366
|
+
* "type": "pdfPage", "zOrder": "back", "pages": "first",
|
|
1367
|
+
* "pdf": { "path": "letterhead.pdf", "page": 1 }, "scale": { "fit": "page" } }
|
|
1368
|
+
* ```
|
|
1369
|
+
*
|
|
1370
|
+
* **Example: list, then remove every Acrobat watermark**
|
|
1371
|
+
*
|
|
1372
|
+
* ```
|
|
1373
|
+
* list: jsonIn: { "source": "acrobat" }
|
|
1374
|
+
* jsonOut: { "count": 1, "watermarks": [ { "id": "ext1", "source": "acrobat", "approach": "artifact",
|
|
1375
|
+
* "type": "text", "text": "DRAFT", "opacity": 0.3, "rotation": 45, "removable": true, "pages": "1-4" } ] }
|
|
1376
|
+
* remove: jsonIn: { "source": "acrobat" }
|
|
1377
|
+
* jsonOut: { "removed": 1 }
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1381
|
+
* {@link Pdf.lastErrorText}.
|
|
1382
|
+
*/
|
|
1383
|
+
watermark(op: string, jsonIn: JsonObject, jsonOut: JsonObject): void
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* Encrypts the loaded PDF, removes or changes its encryption, passwords and permissions, or
|
|
1387
|
+
* reports its security settings. The `op` selects the operation, the `jsonIn` holds the options,
|
|
1388
|
+
* and the `jsonOut` receives the resulting security settings. Returns `true` on success and
|
|
1389
|
+
* `false` on failure.
|
|
1390
|
+
*
|
|
1391
|
+
* Every operation except `getInfo` changes the \*pending\* security: the settings the PDF will be
|
|
1392
|
+
* saved with. Nothing is encrypted or decrypted until {@link Pdf.writeFile} or {@link
|
|
1393
|
+
* Pdf.writeBd} is called, and if no operation changed anything, the PDF is saved with exactly the
|
|
1394
|
+
* security it was loaded with. An operation that changes nothing is still success
|
|
1395
|
+
* (`removeEncryption` on an unencrypted PDF returns `true`).
|
|
1396
|
+
*
|
|
1397
|
+
* **Owner rights**
|
|
1398
|
+
*
|
|
1399
|
+
* Every operation except `getInfo` requires owner rights, which means the PDF was not encrypted,
|
|
1400
|
+
* or was loaded with its owner password (set the {@link Pdf.ownerPassword} property before
|
|
1401
|
+
* calling {@link Pdf.loadFile} or {@link Pdf.loadBd}), or, under certificate security, was opened
|
|
1402
|
+
* by a recipient that has the `changeSecurity` permission. Chilkat does not offer a way to ignore
|
|
1403
|
+
* owner restrictions. An operation refused for lack of owner rights returns `false` and says why
|
|
1404
|
+
* in the LastErrorText.
|
|
1405
|
+
*
|
|
1406
|
+
* **Operations (`op`)**
|
|
1407
|
+
*
|
|
1408
|
+
* - **encrypt** - Replaces the pending security entirely: method, algorithm, scope and
|
|
1409
|
+
* permissions from `jsonIn`, and the passwords from the {@link Pdf.userPassword} and {@link
|
|
1410
|
+
* Pdf.ownerPassword} properties as they are at the time of the call (or the recipients added
|
|
1411
|
+
* with {@link Pdf.addEncryptCert}, for the certificate method). An empty `jsonIn` encrypts
|
|
1412
|
+
* everything with AES-256 (revision 6) using the two password properties and grants every
|
|
1413
|
+
* permission.
|
|
1414
|
+
*
|
|
1415
|
+
* - **removeEncryption** - The PDF will be saved unencrypted, with no passwords and no
|
|
1416
|
+
* restrictions.
|
|
1417
|
+
*
|
|
1418
|
+
* - **removeRestrictions** - Grants every permission; keeps the user password and the algorithm.
|
|
1419
|
+
* With an empty user password the result is unencrypted, the same as `removeEncryption`.
|
|
1420
|
+
*
|
|
1421
|
+
* - **changePasswords** - Takes the new user and owner passwords from the {@link
|
|
1422
|
+
* Pdf.userPassword} and {@link Pdf.ownerPassword} properties; the algorithm, scope and
|
|
1423
|
+
* permissions are kept. Password security only.
|
|
1424
|
+
*
|
|
1425
|
+
* - **changePermissions** - Takes new permissions from the `permissions` object in `jsonIn` (the
|
|
1426
|
+
* same object as for `encrypt`); passwords, algorithm and scope are kept. The object is the
|
|
1427
|
+
* complete new set of permissions, not a change to the existing ones: as for `encrypt`, a
|
|
1428
|
+
* permission it does not mention is granted, whatever the PDF had before.
|
|
1429
|
+
*
|
|
1430
|
+
* - **getInfo** - Changes nothing; reports the security the PDF was loaded with and the security
|
|
1431
|
+
* it will be saved with.
|
|
1432
|
+
*
|
|
1433
|
+
* Note: for AES-256 PDFs opened with the owner password alone, the user password cannot be
|
|
1434
|
+
* recovered from the file, so `changePermissions` and `removeRestrictions` are refused unless
|
|
1435
|
+
* {@link Pdf.userPassword} was also set when the PDF was loaded; `changePasswords` and `encrypt`
|
|
1436
|
+
* work because they set both passwords afresh.
|
|
1437
|
+
*
|
|
1438
|
+
* **Summary of JSON Options for encrypt (`jsonIn`)**
|
|
1439
|
+
*
|
|
1440
|
+
* - **method** - `password` (the default) or `certificate`. The certificate method encrypts for
|
|
1441
|
+
* the recipients whose certificates were added with {@link Pdf.addEncryptCert}; a recipient
|
|
1442
|
+
* opens the PDF with the matching certificate and private key (see {@link Pdf.setDecryptCert}).
|
|
1443
|
+
*
|
|
1444
|
+
* - **algorithmChoice** - The encryption algorithm. The PDF version in the file header is raised
|
|
1445
|
+
* to what the algorithm requires when the PDF is saved, and never lowered. It can also be
|
|
1446
|
+
* raised by the form the file is written in, because object streams and a cross-reference
|
|
1447
|
+
* stream are both PDF 1.5 features. The two RC4 choices are the exception: they exist for
|
|
1448
|
+
* readers older than PDF 1.5, so a PDF saved with either is always written with a classic
|
|
1449
|
+
* cross-reference table and no object streams -- even when {@link Pdf.optimize}'s
|
|
1450
|
+
* `objectStreams` asked for them -- and its header keeps to the version RC4 itself needs.
|
|
1451
|
+
*
|
|
1452
|
+
* - `aes-256` - (the default) AES-256, revision 6. Saved as PDF 1.7 with Adobe extension level 8,
|
|
1453
|
+
* or as PDF 2.0 if the PDF is already 2.0.
|
|
1454
|
+
*
|
|
1455
|
+
* - `aes-256-gcm` - AES-256-GCM (ISO/TS 32003), authenticated encryption. Saved as PDF 2.0. Few
|
|
1456
|
+
* viewers can open it yet.
|
|
1457
|
+
*
|
|
1458
|
+
* - `aes-128` - AES-128, revision 4. Saved as PDF 1.6.
|
|
1459
|
+
*
|
|
1460
|
+
* - `aes-256-r5` - AES-256, Adobe revision 5. Saved as PDF 1.7 with Adobe extension level 3.
|
|
1461
|
+
* Deprecated; only for readers that predate revision 6.
|
|
1462
|
+
*
|
|
1463
|
+
* - `rc4-128` - RC4 128-bit, revision 3. Saved as PDF 1.4, or the document's own version if that
|
|
1464
|
+
* is higher, with a classic cross-reference table. Broken; for legacy compatibility only.
|
|
1465
|
+
*
|
|
1466
|
+
* - `rc4-40` - RC4 40-bit, revision 2. Saved as PDF 1.3, or the document's own version if that is
|
|
1467
|
+
* higher, with a classic cross-reference table. Broken; for legacy compatibility only.
|
|
1468
|
+
*
|
|
1469
|
+
* - **scope** - What is encrypted.
|
|
1470
|
+
*
|
|
1471
|
+
* - `all` - (the default) Everything.
|
|
1472
|
+
*
|
|
1473
|
+
* - `allExceptMetadata` - Everything except the XMP metadata stream, which stays readable so that
|
|
1474
|
+
* indexers can read the title, author and keywords. Needs `aes-128` or later.
|
|
1475
|
+
*
|
|
1476
|
+
* - `attachmentsOnly` - Only the embedded files; pages, metadata and everything else stay
|
|
1477
|
+
* readable, and viewers ask for the password when an attachment is opened. Needs `aes-128` or
|
|
1478
|
+
* later and a non-empty {@link Pdf.userPassword}.
|
|
1479
|
+
*
|
|
1480
|
+
* - **permissions** - An object with what a user who opens the PDF without the owner password may
|
|
1481
|
+
* do. Every permission is granted by default.
|
|
1482
|
+
*
|
|
1483
|
+
* - **print** - `full` (the default), `lowQuality`, or `none`. `lowQuality` is honored from
|
|
1484
|
+
* `rc4-128` on.
|
|
1485
|
+
*
|
|
1486
|
+
* - **modify** - Boolean. Changes other than those covered by the permissions below.
|
|
1487
|
+
*
|
|
1488
|
+
* - **copy** - Boolean. Copying and extracting text and graphics.
|
|
1489
|
+
*
|
|
1490
|
+
* - **accessibility** - Boolean. Extraction for screen readers. PDF 2.0 readers always allow it,
|
|
1491
|
+
* so it has no effect with `aes-256` or `aes-256-gcm`.
|
|
1492
|
+
*
|
|
1493
|
+
* - **annotate** - Boolean. Adding or changing annotations; also allows filling forms.
|
|
1494
|
+
*
|
|
1495
|
+
* - **fillForms** - Boolean. Filling existing form fields even when `annotate` is false.
|
|
1496
|
+
*
|
|
1497
|
+
* - **assemble** - Boolean. Inserting, deleting and rotating pages, and creating bookmarks.
|
|
1498
|
+
*
|
|
1499
|
+
* - **changeSecurity** - Boolean (default \*false\*). Certificate method only: the recipient has
|
|
1500
|
+
* owner rights (may change or remove the security), and every other permission is implied. The
|
|
1501
|
+
* encrypting program normally gives its own certificate this permission so that the file can be
|
|
1502
|
+
* managed later.
|
|
1503
|
+
*
|
|
1504
|
+
* With `rc4-40` only `print` (as none or full), `modify`, `copy` and `annotate` exist; the rest
|
|
1505
|
+
* are ignored.
|
|
1506
|
+
*
|
|
1507
|
+
* - **recipientPermissions\[n\]** - Certificate method only: a permissions object (as above) for
|
|
1508
|
+
* the nth certificate added with {@link Pdf.addEncryptCert}, overriding `permissions` for that
|
|
1509
|
+
* recipient.
|
|
1510
|
+
*
|
|
1511
|
+
* **Passwords**
|
|
1512
|
+
*
|
|
1513
|
+
* `encrypt` and `changePasswords` read the {@link Pdf.userPassword} and {@link Pdf.ownerPassword}
|
|
1514
|
+
* properties at the time of the call. An empty {@link Pdf.userPassword} gives a PDF that opens
|
|
1515
|
+
* without a prompt but keeps its restrictions. `encrypt` with the password method refuses an
|
|
1516
|
+
* empty {@link Pdf.ownerPassword} whenever any permission is restricted, since anyone would then
|
|
1517
|
+
* have owner rights and the restrictions would mean nothing; an empty {@link Pdf.ownerPassword}
|
|
1518
|
+
* is allowed when every permission is granted. With `aes-256` and `aes-256-gcm` a password can be
|
|
1519
|
+
* any Unicode text up to 127 bytes as UTF-8; with the older algorithms it is limited to 32 Latin
|
|
1520
|
+
* characters, and `encrypt` fails if a password cannot be represented.
|
|
1521
|
+
*
|
|
1522
|
+
* **Results (`jsonOut`)**
|
|
1523
|
+
*
|
|
1524
|
+
* `getInfo` returns **changed** (whether the pending security differs from the loaded security;
|
|
1525
|
+
* when `false`, saving keeps the original security), **loaded** (the security the PDF was loaded
|
|
1526
|
+
* with) and **pending** (the security it will be saved with). Every other operation returns
|
|
1527
|
+
* **changed** and **pending**. While `changed` is `false`, `pending` is the loaded security
|
|
1528
|
+
* exactly as the file has it: the same as `loaded`, without `openedWith`. Each of `loaded` and
|
|
1529
|
+
* `pending` is an object with:
|
|
1530
|
+
*
|
|
1531
|
+
* - **encrypted** - Boolean. An unencrypted state is just `{ "encrypted": false }`.
|
|
1532
|
+
*
|
|
1533
|
+
* - **method** - `password` or `certificate`.
|
|
1534
|
+
*
|
|
1535
|
+
* - **algorithm** - The same values as `algorithmChoice`.
|
|
1536
|
+
*
|
|
1537
|
+
* - **pdfVersion** - The PDF version, such as `1.7`, with **adobeExtensionLevel** or
|
|
1538
|
+
* **isoExtensionLevel** when one applies.
|
|
1539
|
+
*
|
|
1540
|
+
* - **scope** - `all`, `allExceptMetadata`, or `attachmentsOnly`.
|
|
1541
|
+
*
|
|
1542
|
+
* - **userPasswordRequired**, **ownerPasswordSet** - Password method: whether a password is
|
|
1543
|
+
* needed to open the PDF, and whether the owner password is non-empty (when `false`, anyone has
|
|
1544
|
+
* owner rights).
|
|
1545
|
+
*
|
|
1546
|
+
* - **openedWith** - In `loaded` only: `owner`, `user`, `emptyPassword`, `certificate`,
|
|
1547
|
+
* `notOpened`, or `notEncrypted`.
|
|
1548
|
+
*
|
|
1549
|
+
* - **permissions** - Password method: the permissions object as above (without
|
|
1550
|
+
* `changeSecurity`).
|
|
1551
|
+
*
|
|
1552
|
+
* - **recipients\[i\]** - Certificate method: each recipient's **issuer** and **serialNumber**,
|
|
1553
|
+
* and its **permissions** (including `changeSecurity`). In `loaded`, only the recipient that
|
|
1554
|
+
* opened the PDF has readable permissions; in `pending`, every recipient shows its permissions.
|
|
1555
|
+
*
|
|
1556
|
+
* Passwords are never returned.
|
|
1557
|
+
*
|
|
1558
|
+
* **Signed PDFs**
|
|
1559
|
+
*
|
|
1560
|
+
* A change of security means rewriting the whole file, which invalidates every signature. With
|
|
1561
|
+
* {@link Pdf.preserveSignatures} \*true\* (the default), every operation except `getInfo` fails
|
|
1562
|
+
* on a signed PDF; with it \*false\*, the change is allowed and the signatures are invalidated.
|
|
1563
|
+
*
|
|
1564
|
+
* **Example: open password, no copying, low-quality printing**
|
|
1565
|
+
*
|
|
1566
|
+
* ```
|
|
1567
|
+
* pdf.UserPassword = "open-me"
|
|
1568
|
+
* pdf.OwnerPassword = "admin-secret"
|
|
1569
|
+
* jsonIn: { "permissions": { "print": "lowQuality", "copy": false } }
|
|
1570
|
+
* pdf.Protection("encrypt", jsonIn, jsonOut) -- AES-256 revision 6 by default
|
|
1571
|
+
* pdf.WriteFile("protected.pdf") -- saved as PDF 1.7, Adobe extension level 8
|
|
1572
|
+
* ```
|
|
1573
|
+
*
|
|
1574
|
+
* **Example: getInfo**
|
|
1575
|
+
*
|
|
1576
|
+
* ```
|
|
1577
|
+
* jsonOut: { "changed": true,
|
|
1578
|
+
* "loaded": { "encrypted": true, "method": "password", "algorithm": "aes-128", "pdfVersion": "1.6",
|
|
1579
|
+
* "scope": "all", "userPasswordRequired": true, "ownerPasswordSet": true, "openedWith": "owner",
|
|
1580
|
+
* "permissions": { "print": "lowQuality", "modify": false, "copy": false, "accessibility": true,
|
|
1581
|
+
* "annotate": false, "fillForms": true, "assemble": false } },
|
|
1582
|
+
* "pending": { "encrypted": true, "method": "password", "algorithm": "aes-256", "pdfVersion": "1.7",
|
|
1583
|
+
* "adobeExtensionLevel": 8, "scope": "all", "userPasswordRequired": true, "ownerPasswordSet": true,
|
|
1584
|
+
* "permissions": { "print": "full", "modify": false, "copy": false, "accessibility": true,
|
|
1585
|
+
* "annotate": false, "fillForms": true, "assemble": false } } }
|
|
1586
|
+
* ```
|
|
1587
|
+
*
|
|
1588
|
+
* **Example: encrypt for two recipients**
|
|
1589
|
+
*
|
|
1590
|
+
* ```
|
|
1591
|
+
* pdf.AddEncryptCert(aliceCert)
|
|
1592
|
+
* pdf.AddEncryptCert(bobCert)
|
|
1593
|
+
* jsonIn: { "method": "certificate",
|
|
1594
|
+
* "recipientPermissions": [ { "changeSecurity": true }, { "modify": false } ] }
|
|
1595
|
+
* pdf.Protection("encrypt", jsonIn, jsonOut)
|
|
1596
|
+
* ```
|
|
1597
|
+
*
|
|
1598
|
+
* **Example: remove encryption (needs the owner password)**
|
|
1599
|
+
*
|
|
1600
|
+
* ```
|
|
1601
|
+
* pdf.OwnerPassword = "admin-secret"
|
|
1602
|
+
* pdf.LoadFile("protected.pdf")
|
|
1603
|
+
* pdf.Protection("removeEncryption", jsonIn, jsonOut)
|
|
1604
|
+
* pdf.WriteFile("plain.pdf")
|
|
1605
|
+
* ```
|
|
1606
|
+
*
|
|
1607
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1608
|
+
* {@link Pdf.lastErrorText}.
|
|
1609
|
+
*/
|
|
1610
|
+
protection(op: string, jsonIn: JsonObject, jsonOut: JsonObject): void
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Extracts the text of the loaded PDF. The `op` selects what is returned, the `jsonIn` holds the
|
|
1614
|
+
* options (an empty JSON object extracts all pages in automatic reading order with the default
|
|
1615
|
+
* clean-up), and the `jsonOut` receives the result together with a `quality` report that says how
|
|
1616
|
+
* trustworthy the text is. Returns `true` on success and `false` on failure. A page without
|
|
1617
|
+
* extractable text (such as a scanned image) is not a failure: the quality report identifies it.
|
|
1618
|
+
* Chilkat does not perform OCR.
|
|
1619
|
+
*
|
|
1620
|
+
* See the examples below for more detailed information about the operations and JSON members
|
|
1621
|
+
* listed here.
|
|
1622
|
+
*
|
|
1623
|
+
* **Operations (`op`)**
|
|
1624
|
+
*
|
|
1625
|
+
* - **text** - Plain text, as flowing paragraphs, visual lines, or a layout-preserving grid (see
|
|
1626
|
+
* the `layout` option).
|
|
1627
|
+
*
|
|
1628
|
+
* - **markdown** - Markdown with headings, emphasis, lists, links, code, ruled tables, image
|
|
1629
|
+
* placeholders and page markers. Suited to AI and search pipelines.
|
|
1630
|
+
*
|
|
1631
|
+
* - **search** - The matches for a string or regular expression, each with its page and the text
|
|
1632
|
+
* around it.
|
|
1633
|
+
*
|
|
1634
|
+
* - **tables** - The tables detected on the pages, as rows and cells with spans.
|
|
1635
|
+
*
|
|
1636
|
+
* - **assess** - Only the quality report, computed without producing text. Use it to triage
|
|
1637
|
+
* documents before extracting: is the text trustworthy, and which pages need OCR.
|
|
1638
|
+
*
|
|
1639
|
+
* **Summary of JSON Options (`jsonIn`)**
|
|
1640
|
+
*
|
|
1641
|
+
* The options under \*Scope\*, \*Reading order\*, \*Filters\* and \*Clean-up\* apply to all
|
|
1642
|
+
* operations. The groups that follow them apply only to the operation named.
|
|
1643
|
+
*
|
|
1644
|
+
* \*Scope (all operations)\*
|
|
1645
|
+
*
|
|
1646
|
+
* - **pages** - The pages to extract. Can be `all` (the default), `first`, `last`, `odd`, `even`,
|
|
1647
|
+
* or a list of 1-based pages and ranges such as `1,3,5-9,12-`.
|
|
1648
|
+
*
|
|
1649
|
+
* - **label** - Restricts the operation to the text belonging to a label found on the page, such
|
|
1650
|
+
* as `Invoice Number:` or `Bill To`, so that fields can be captured without coordinates.
|
|
1651
|
+
* Matching ignores case, extra spaces and a trailing colon. Works with every operation: `text`
|
|
1652
|
+
* returns the value, `markdown` returns it as Markdown, `search` looks only inside the labelled
|
|
1653
|
+
* text, and `tables` returns only the tables inside it.
|
|
1654
|
+
*
|
|
1655
|
+
* - **labelValue** - Which text belongs to the label. Can be `auto` (the default), `right`,
|
|
1656
|
+
* `below`, or `section`.
|
|
1657
|
+
*
|
|
1658
|
+
* - `auto` - The rest of the label's line if there is text there, otherwise the block directly
|
|
1659
|
+
* below the label.
|
|
1660
|
+
*
|
|
1661
|
+
* - `right` - The rest of the label's line.
|
|
1662
|
+
*
|
|
1663
|
+
* - `below` - The block directly below the label, ending at the next gap or heading.
|
|
1664
|
+
*
|
|
1665
|
+
* - `section` - Everything after the label up to the next heading of the same or higher level
|
|
1666
|
+
* (the label is itself a heading). Most reliable on tagged PDFs.
|
|
1667
|
+
*
|
|
1668
|
+
* - **labelOccurrence** - Which occurrences of the label on the selected pages are used. Can be
|
|
1669
|
+
* `first` (the default), `all`, or a number (`2` for the second occurrence). Occurrences are
|
|
1670
|
+
* counted in reading order.
|
|
1671
|
+
*
|
|
1672
|
+
* - **labelRegex** - Set to \*true\* to treat `label` as a regular expression. The default is
|
|
1673
|
+
* \*false\*.
|
|
1674
|
+
*
|
|
1675
|
+
* \*Reading order (all operations)\*
|
|
1676
|
+
*
|
|
1677
|
+
* - **readingOrder** - Can be `auto` (the default), `structure`, `visual`, or `content`. `auto`
|
|
1678
|
+
* follows the structure tree when the PDF is tagged and the tree is usable, otherwise it reads
|
|
1679
|
+
* in visual order. `visual` detects columns and reads top to bottom within each column.
|
|
1680
|
+
* `content` is the order in which the text is drawn.
|
|
1681
|
+
*
|
|
1682
|
+
* - **columns** - Can be `auto` (the default) or `none`. `none` switches off column detection and
|
|
1683
|
+
* reads the full page width line by line.
|
|
1684
|
+
*
|
|
1685
|
+
* \*Filters (all operations)\*
|
|
1686
|
+
*
|
|
1687
|
+
* Each filter can be `include` or `exclude` and decides whether a kind of text appears in the
|
|
1688
|
+
* output.
|
|
1689
|
+
*
|
|
1690
|
+
* - **artifacts** - Tagged artifacts, Acrobat and Chilkat watermarks and backgrounds, and Acrobat
|
|
1691
|
+
* headers and footers. The default is `exclude`.
|
|
1692
|
+
*
|
|
1693
|
+
* - **repeatedHeadersFooters** - Untagged text repeated at the same position on most pages, such
|
|
1694
|
+
* as running heads and page numbers. The default is `exclude`.
|
|
1695
|
+
*
|
|
1696
|
+
* - **invisibleText** - Text drawn in an invisible rendering mode. Can be `auto` (the default),
|
|
1697
|
+
* `include`, or `exclude`. `auto` includes invisible text only on pages that have no visible
|
|
1698
|
+
* text, which is exactly an OCR layer over a scanned image.
|
|
1699
|
+
*
|
|
1700
|
+
* - **clippedText** - Text hidden by a clipping path. The default is `exclude`.
|
|
1701
|
+
*
|
|
1702
|
+
* - **offPageText** - Text outside the page's crop box. The default is `exclude`.
|
|
1703
|
+
*
|
|
1704
|
+
* - **obscuredText** - Text drawn in the same color as a filled area directly beneath it (white
|
|
1705
|
+
* on white). The default is `exclude`.
|
|
1706
|
+
*
|
|
1707
|
+
* - **rotatedText** - Text not aligned with the page, such as vertical margin labels. The default
|
|
1708
|
+
* is `include`.
|
|
1709
|
+
*
|
|
1710
|
+
* - **formFields** - The values of form fields, placed at the field's position in reading order.
|
|
1711
|
+
* The default is `exclude`.
|
|
1712
|
+
*
|
|
1713
|
+
* - **annotations** - Free-text annotations and comment text. The default is `exclude`.
|
|
1714
|
+
*
|
|
1715
|
+
* \*Clean-up (all operations)\*
|
|
1716
|
+
*
|
|
1717
|
+
* - **expandLigatures** - Boolean (default \*true\*). Ligatures are expanded, so that "fi" becomes
|
|
1718
|
+
* "fi".
|
|
1719
|
+
*
|
|
1720
|
+
* - **dehyphenate** - Boolean (default \*true\*). Rejoins words split by a hyphen at the end of a
|
|
1721
|
+
* line, while keeping hyphens that belong to the word.
|
|
1722
|
+
*
|
|
1723
|
+
* - **actualText** - Boolean (default \*true\*). Uses the PDF's ActualText replacements where
|
|
1724
|
+
* present (common for symbols and decorative letters).
|
|
1725
|
+
*
|
|
1726
|
+
* - **bidi** - Boolean (default \*true\*). Reorders right-to-left scripts into logical order.
|
|
1727
|
+
*
|
|
1728
|
+
* - **normalize** - Unicode normalization of the output. Can be `NFC` (the default), `NFKC`, or
|
|
1729
|
+
* `none`.
|
|
1730
|
+
*
|
|
1731
|
+
* - **lineEnding** - The line ending used in the text. Can be `\n` (the default) or `\r\n`. The
|
|
1732
|
+
* keywords `lf` and `crlf` are also accepted.
|
|
1733
|
+
*
|
|
1734
|
+
* \*Options for the text operation only\*
|
|
1735
|
+
*
|
|
1736
|
+
* - **layout** - Can be `flow` (the default), `lines`, or `grid`. `flow` joins the lines of each
|
|
1737
|
+
* paragraph; `lines` keeps each visual line on its own line; `grid` pads with spaces so that
|
|
1738
|
+
* the horizontal positions are preserved, as in a fixed-pitch rendering of the page.
|
|
1739
|
+
*
|
|
1740
|
+
* - **pageSeparator** - The string inserted between pages in the joined `text`. The default is a
|
|
1741
|
+
* form feed (`\f`).
|
|
1742
|
+
*
|
|
1743
|
+
* \*Options for the markdown operation only\*
|
|
1744
|
+
*
|
|
1745
|
+
* - **headings** - Boolean (default \*true\*). Headings come from the structure tree when the PDF
|
|
1746
|
+
* is tagged; otherwise they are inferred from the font size and weight relative to the body
|
|
1747
|
+
* text.
|
|
1748
|
+
*
|
|
1749
|
+
* - **maxHeadingLevel** - An integer from 1 to 6 (default `3`). Deeper inferred heading levels
|
|
1750
|
+
* are folded into the last level.
|
|
1751
|
+
*
|
|
1752
|
+
* - **emphasis** - Boolean (default \*true\*). Bold and italic spans.
|
|
1753
|
+
*
|
|
1754
|
+
* - **lists** - Boolean (default \*true\*). Bullets, numbering and hanging indents become
|
|
1755
|
+
* Markdown lists.
|
|
1756
|
+
*
|
|
1757
|
+
* - **links** - Boolean (default \*true\*). Link annotations over the text become Markdown links.
|
|
1758
|
+
*
|
|
1759
|
+
* - **code** - Boolean (default \*true\*). Monospaced runs become code spans and monospaced
|
|
1760
|
+
* blocks become code blocks.
|
|
1761
|
+
*
|
|
1762
|
+
* - **tables** - Can be `ruled` (the default), `all`, or `none`. `ruled` converts tables that
|
|
1763
|
+
* have drawn cell borders. `all` is accepted for tables detected from column alignment alone,
|
|
1764
|
+
* but this release detects only ruled tables.
|
|
1765
|
+
*
|
|
1766
|
+
* - **images** - Can be `placeholder` (the default) or `none`. A placeholder such as
|
|
1767
|
+
* `` marks where an image sits in the flow.
|
|
1768
|
+
*
|
|
1769
|
+
* - **pageBreaks** - Can be `comment` (the default), `rule`, or `none`. Pages are separated by an
|
|
1770
|
+
* HTML comment such as `<!-- page 3 -->`, by a horizontal rule (`---`), or by nothing.
|
|
1771
|
+
*
|
|
1772
|
+
* - **footnotes** - Can be `inline` (the default), `end`, or `none`. Small-print notes at the
|
|
1773
|
+
* foot of a page are kept in place, gathered at the end of the document (after the last page,
|
|
1774
|
+
* in the joined Markdown), or dropped.
|
|
1775
|
+
*
|
|
1776
|
+
* \*Options for the search operation only\*
|
|
1777
|
+
*
|
|
1778
|
+
* - **query** - The string or regular expression to find. Required.
|
|
1779
|
+
*
|
|
1780
|
+
* - **regex** - Boolean (default \*false\*). Set to \*true\* to treat `query` as a regular
|
|
1781
|
+
* expression.
|
|
1782
|
+
*
|
|
1783
|
+
* - **caseSensitive** - Boolean (default \*false\*).
|
|
1784
|
+
*
|
|
1785
|
+
* - **wholeWord** - Boolean (default \*false\*). Matches only whole words.
|
|
1786
|
+
*
|
|
1787
|
+
* - **maxResults** - The maximum number of matches to return. The default is to return all
|
|
1788
|
+
* matches.
|
|
1789
|
+
*
|
|
1790
|
+
* - **context** - The number of characters of text returned before and after each match. The
|
|
1791
|
+
* default is `40`.
|
|
1792
|
+
*
|
|
1793
|
+
* \*Options for the tables operation only\*
|
|
1794
|
+
*
|
|
1795
|
+
* - **detection** - Can be `ruled` (the default) or `all`. As for the markdown `tables` option;
|
|
1796
|
+
* this release detects only ruled tables.
|
|
1797
|
+
*
|
|
1798
|
+
* - **minRows**, **minColumns** - Grids smaller than this are not reported as tables. The default
|
|
1799
|
+
* for each is `2`.
|
|
1800
|
+
*
|
|
1801
|
+
* **Results (`jsonOut`)**
|
|
1802
|
+
*
|
|
1803
|
+
* - **text** - The joined text of all selected pages (text operation), and **pages\[i\].page** /
|
|
1804
|
+
* **pages\[i\].text** with each page's text.
|
|
1805
|
+
*
|
|
1806
|
+
* - **markdown** - The joined Markdown (markdown operation), and **pages\[i\].page** /
|
|
1807
|
+
* **pages\[i\].markdown** with each page's Markdown.
|
|
1808
|
+
*
|
|
1809
|
+
* - **labelMatches\[i\]** - When `label` is set: one entry per label occurrence used, with
|
|
1810
|
+
* **page**, **label** (the label as found) and the value as **text** or **markdown**. The
|
|
1811
|
+
* top-level `text` or `markdown` holds the values joined. A label that is not found is still
|
|
1812
|
+
* success: `labelMatches` is empty and the quality report carries the issue `labelNotFound`.
|
|
1813
|
+
*
|
|
1814
|
+
* - **count** and **matches\[i\]** - Search results: each match has **page**, **text** (the
|
|
1815
|
+
* matched text), **before** and **after** (the context).
|
|
1816
|
+
*
|
|
1817
|
+
* - **count** and **tables\[i\]** - Each table has **page**, **detectedBy** (`ruled`, `aligned`
|
|
1818
|
+
* or `structure`), **rows**, **columns**, and **cells\[j\]** with **row**, **col**,
|
|
1819
|
+
* **rowSpan**, **colSpan** and **text**. Rows and columns are counted from 0.
|
|
1820
|
+
*
|
|
1821
|
+
* - **quality** - Returned by every operation. **quality.rating** is `good`, `fair`, `poor`, or
|
|
1822
|
+
* `none` for the document as a whole (the worst page rating among the pages that have text).
|
|
1823
|
+
* **quality.tagged** and **quality.structureUsable** tell whether the PDF has a structure tree
|
|
1824
|
+
* and whether it could be used. **quality.pagesNeedingOcr** lists the image-only pages, such as
|
|
1825
|
+
* `4,9`. **quality.pages\[i\]** rates each page:
|
|
1826
|
+
*
|
|
1827
|
+
* - **page**, **rating**
|
|
1828
|
+
*
|
|
1829
|
+
* - **textSource** - `text` (real text), `ocrLayer` (invisible text over an image), `imageOnly`
|
|
1830
|
+
* (needs OCR), `mixed`, or `empty`.
|
|
1831
|
+
*
|
|
1832
|
+
* - **unicodeCoverage** - The share of glyphs with a reliable Unicode mapping, from 0 to 1.
|
|
1833
|
+
*
|
|
1834
|
+
* - **unmappedFonts** - Fonts whose glyphs could not be mapped, so their text is likely wrong.
|
|
1835
|
+
*
|
|
1836
|
+
* - **suspiciousCharRatio** - The share of replacement, private-use and control characters in the
|
|
1837
|
+
* output.
|
|
1838
|
+
*
|
|
1839
|
+
* - **readingOrderSource** - `structure`, `visual`, or `content`: how the reading order was
|
|
1840
|
+
* decided.
|
|
1841
|
+
*
|
|
1842
|
+
* - **columns** - The number of columns detected.
|
|
1843
|
+
*
|
|
1844
|
+
* - **structure.headings** - `structure`, `inferred`, or `none`; **structure.tables.ruled** and
|
|
1845
|
+
* **structure.tables.aligned** count the tables of each kind.
|
|
1846
|
+
*
|
|
1847
|
+
* - **issues\[j\].code**, **issues\[j\].message** - Machine-readable codes with a sentence each:
|
|
1848
|
+
* `imageOnly`, `ocrLayer`, `missingUnicode`, `suspiciousCharacters`, `multiColumn`,
|
|
1849
|
+
* `unruledTable`, `structureTreeUnusable`, `rotatedText`, `obscuredTextSkipped`,
|
|
1850
|
+
* `clippedTextSkipped`, `labelNotFound`, `structureTreeMisaligned`, `layoutUncertain`.
|
|
1851
|
+
*
|
|
1852
|
+
* - **uncertain** - The layout decisions on the page that were borderline (an empty array when
|
|
1853
|
+
* none): `columns` (a gutter close to the minimum width, or sides whose line lengths barely
|
|
1854
|
+
* pass or fail the test that tells two text columns from a caption column beside its values),
|
|
1855
|
+
* `heading` (a heading candidate whose size is close to the cut-off, or an accepted heading
|
|
1856
|
+
* long enough to be a pull quote), `table` (a ruled grid with more empty cells than filled
|
|
1857
|
+
* ones, or of the smallest size detected), `paragraph` (a paragraph break decided by a line
|
|
1858
|
+
* spacing close to the block's own). The decision is still made; the entry says the output
|
|
1859
|
+
* around it deserves a look. When the array is not empty the page also carries the issue
|
|
1860
|
+
* `layoutUncertain`.
|
|
1861
|
+
*
|
|
1862
|
+
* A rating of `good` means the coverage is at least 0.99 with no suspicious characters to speak
|
|
1863
|
+
* of; `fair` means coverage between 0.95 and 0.99 or structure inferred on a complex page
|
|
1864
|
+
* (columns, unruled tables, rotated text); `poor` means coverage below 0.95 or suspicious
|
|
1865
|
+
* characters above 1%, so the text should not be trusted without review; `none` means there is no
|
|
1866
|
+
* text to extract.
|
|
1867
|
+
*
|
|
1868
|
+
* **Permissions**
|
|
1869
|
+
*
|
|
1870
|
+
* Extraction is read-only and never affects signatures or the saved output. For an encrypted PDF,
|
|
1871
|
+
* every operation except `assess` requires owner rights or the copy permission; load the PDF with
|
|
1872
|
+
* the {@link Pdf.ownerPassword} property set to extract from a PDF that restricts copying.
|
|
1873
|
+
* `assess` reports only counts and ratings, never text, and is always allowed. Whole-document
|
|
1874
|
+
* Markdown can be large; use {@link Pdf.extractTextSb} to receive it in a StringBuilder.
|
|
1875
|
+
*
|
|
1876
|
+
* **Example: capture a field by its label**
|
|
1877
|
+
*
|
|
1878
|
+
* ```
|
|
1879
|
+
* jsonIn: { "label": "Invoice Number" }
|
|
1880
|
+
* jsonOut: { "text": "INV-2026-0412",
|
|
1881
|
+
* "pages": [ { "page": 1, "text": "INV-2026-0412" } ],
|
|
1882
|
+
* "labelMatches": [ { "page": 1, "label": "Invoice Number:", "text": "INV-2026-0412" } ],
|
|
1883
|
+
* "quality": { "rating": "good", ... } }
|
|
1884
|
+
* ```
|
|
1885
|
+
*
|
|
1886
|
+
* **Example: find a total with a regular expression**
|
|
1887
|
+
*
|
|
1888
|
+
* ```
|
|
1889
|
+
* jsonIn: { "query": "Total\\s+\\$?[0-9,]+\\.[0-9]{2}", "regex": true }
|
|
1890
|
+
* jsonOut: { "count": 1,
|
|
1891
|
+
* "matches": [ { "page": 2, "text": "Total $1,234.56", "before": "... ", "after": " ..." } ],
|
|
1892
|
+
* "quality": { ... } }
|
|
1893
|
+
* ```
|
|
1894
|
+
*
|
|
1895
|
+
* **Example: triage before extracting**
|
|
1896
|
+
*
|
|
1897
|
+
* ```
|
|
1898
|
+
* jsonIn: { }
|
|
1899
|
+
* jsonOut (assess): { "quality": { "rating": "fair", "tagged": true, "structureUsable": false, "pagesNeedingOcr": "4,9",
|
|
1900
|
+
* "pages": [ { "page": 3, "rating": "fair", "textSource": "text", "unicodeCoverage": 0.97,
|
|
1901
|
+
* "unmappedFonts": [ "F12+Wingdings" ], "suspiciousCharRatio": 0.004,
|
|
1902
|
+
* "readingOrderSource": "visual", "columns": 2,
|
|
1903
|
+
* "structure": { "headings": "inferred", "tables": { "ruled": 1, "aligned": 0 } },
|
|
1904
|
+
* "issues": [ { "code": "multiColumn", "message": "Multi-column layout; reading order inferred" } ] },
|
|
1905
|
+
* { "page": 4, "rating": "none", "textSource": "imageOnly",
|
|
1906
|
+
* "issues": [ { "code": "imageOnly", "message": "No text; page is a scanned image" } ] } ] } }
|
|
1907
|
+
* ```
|
|
1908
|
+
*
|
|
1909
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1910
|
+
* {@link Pdf.lastErrorText}.
|
|
1911
|
+
*/
|
|
1912
|
+
extractText(op: string, jsonIn: JsonObject, jsonOut: JsonObject): void
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* The same as {@link Pdf.extractText}, except that the joined text or Markdown is written to
|
|
1916
|
+
* `sbOut` instead of being returned in the `text` or `markdown` member of `jsonOut`. Use this
|
|
1917
|
+
* method for large documents, where whole-document text or Markdown would be an unwieldy JSON
|
|
1918
|
+
* string. `jsonOut` still receives everything else: the `pages` array (the page numbers only; the
|
|
1919
|
+
* pages' text is in the StringBuilder), `labelMatches`, the search or table results, and the
|
|
1920
|
+
* `quality` report.
|
|
1921
|
+
*
|
|
1922
|
+
* See the {@link Pdf.extractText} method for the operations, the JSON options and the results.
|
|
1923
|
+
*
|
|
1924
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1925
|
+
* {@link Pdf.lastErrorText}.
|
|
1926
|
+
*/
|
|
1927
|
+
extractTextSb(op: string, jsonIn: JsonObject, sbOut: StringBuilder, jsonOut: JsonObject): void
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Adds a recipient certificate for certificate-based encryption. Call it once per recipient
|
|
1931
|
+
* before calling {@link Pdf.protection} with the `encrypt` operation and `"method":
|
|
1932
|
+
* "certificate"`; the PDF is then encrypted so that any one of the recipients can open it with
|
|
1933
|
+
* the matching certificate and private key (see {@link Pdf.setDecryptCert}). Only the public
|
|
1934
|
+
* certificate is needed here. The order of the calls matters: the nth certificate added
|
|
1935
|
+
* corresponds to `recipientPermissions[n-1]` in the {@link Pdf.protection} options.
|
|
1936
|
+
*
|
|
1937
|
+
* The certificates stay in effect for later `encrypt` operations until {@link
|
|
1938
|
+
* Pdf.clearEncryptCerts} is called.
|
|
1939
|
+
*
|
|
1940
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1941
|
+
* {@link Pdf.lastErrorText}.
|
|
1942
|
+
*/
|
|
1943
|
+
addEncryptCert(cert: Cert): void
|
|
1944
|
+
|
|
1945
|
+
/**
|
|
1946
|
+
* Removes every recipient certificate added with {@link Pdf.addEncryptCert}.
|
|
1947
|
+
*/
|
|
1948
|
+
clearEncryptCerts(): void
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* Sets the certificate (with its private key) used to open a certificate-encrypted PDF. Call it
|
|
1952
|
+
* before {@link Pdf.loadFile} or {@link Pdf.loadBd}. The certificate must be one of the PDF's
|
|
1953
|
+
* recipients and must have its private key available, such as a certificate loaded from a
|
|
1954
|
+
* PFX/.p12 file or from the Windows certificate store. Use {@link Pdf.preLoadCheck} to learn
|
|
1955
|
+
* whether a PDF is certificate-encrypted and which recipient certificates (by issuer and serial
|
|
1956
|
+
* number) can open it.
|
|
1957
|
+
*
|
|
1958
|
+
* On Windows, calling this method is not needed for a certificate that is installed with its
|
|
1959
|
+
* private key in the Windows certificate store (Current User or Local Machine): the store is
|
|
1960
|
+
* searched for the private key of each recipient when a certificate-encrypted PDF is loaded.
|
|
1961
|
+
*
|
|
1962
|
+
* For password-encrypted PDFs, set the {@link Pdf.ownerPassword} or {@link Pdf.userPassword}
|
|
1963
|
+
* property instead.
|
|
1964
|
+
*
|
|
1965
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
1966
|
+
* {@link Pdf.lastErrorText}.
|
|
1967
|
+
*/
|
|
1968
|
+
setDecryptCert(cert: Cert): void
|
|
1969
|
+
|
|
1970
|
+
/**
|
|
1971
|
+
* Reports what can be known about a PDF file's encryption before it is loaded, so that an
|
|
1972
|
+
* application can decide which password or certificate it needs: whether the file is encrypted,
|
|
1973
|
+
* by which method and algorithm, whether a password is needed to open it, what a user may do with
|
|
1974
|
+
* it, or which certificates can open it. Nothing is loaded into this object, and no password is
|
|
1975
|
+
* needed. Returns `false` only when the file cannot be read or is not a PDF; an unencrypted PDF
|
|
1976
|
+
* returns `true` with `encrypted` false.
|
|
1977
|
+
*
|
|
1978
|
+
* **Results (`jsonOut`)**
|
|
1979
|
+
*
|
|
1980
|
+
* - **encrypted** - Boolean. When `false`, nothing else is returned.
|
|
1981
|
+
*
|
|
1982
|
+
* - **method** - `password`, or `certificate` (a certificate with its private key is needed to
|
|
1983
|
+
* open the file; see {@link Pdf.setDecryptCert}).
|
|
1984
|
+
*
|
|
1985
|
+
* - **algorithm** - `rc4-40`, `rc4-128`, `aes-128`, `aes-256-r5`, `aes-256`, or `aes-256-gcm`.
|
|
1986
|
+
*
|
|
1987
|
+
* - **pdfVersion** - The version in the file header, such as `1.7`, with **adobeExtensionLevel**
|
|
1988
|
+
* or **isoExtensionLevel** when the file declares one. The declaration is in the document
|
|
1989
|
+
* catalog, which an encrypted PDF often stores encrypted (inside an object stream), so the
|
|
1990
|
+
* extension level is frequently not reported for a PDF that needs a password to open. {@link
|
|
1991
|
+
* Pdf.protection} with `getInfo` reports it once the PDF is loaded.
|
|
1992
|
+
*
|
|
1993
|
+
* - **scope** - `all`, `allExceptMetadata`, or `attachmentsOnly`.
|
|
1994
|
+
*
|
|
1995
|
+
* - **openPasswordRequired** - Password method only: `false` when the file opens with an empty
|
|
1996
|
+
* user password (it may still have restrictions).
|
|
1997
|
+
*
|
|
1998
|
+
* - **permissions** - Password method only (readable without any password): **print** (`full`,
|
|
1999
|
+
* `lowQuality` or `none`) and the booleans **modify**, **copy**, **accessibility**,
|
|
2000
|
+
* **annotate**, **fillForms** and **assemble**.
|
|
2001
|
+
*
|
|
2002
|
+
* - **recipients\[i\]** - Certificate method only: the **issuer** and **serialNumber** of each
|
|
2003
|
+
* recipient certificate, which tells the application which certificate it needs.
|
|
2004
|
+
*
|
|
2005
|
+
* **Example**
|
|
2006
|
+
*
|
|
2007
|
+
* ```
|
|
2008
|
+
* jsonOut: { "encrypted": true, "method": "password", "algorithm": "aes-256", "pdfVersion": "1.7",
|
|
2009
|
+
* "adobeExtensionLevel": 8, "scope": "all", "openPasswordRequired": false,
|
|
2010
|
+
* "permissions": { "print": "full", "modify": false, "copy": true, "accessibility": true,
|
|
2011
|
+
* "annotate": false, "fillForms": true, "assemble": false } }
|
|
2012
|
+
* ```
|
|
2013
|
+
*
|
|
2014
|
+
* Then, typically: if `method` is `certificate`, call {@link Pdf.setDecryptCert}; otherwise if
|
|
2015
|
+
* `openPasswordRequired` is `true`, set the {@link Pdf.userPassword} (or {@link
|
|
2016
|
+
* Pdf.ownerPassword}) property; then call {@link Pdf.loadFile}.
|
|
2017
|
+
*
|
|
2018
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
2019
|
+
* {@link Pdf.lastErrorText}.
|
|
2020
|
+
*/
|
|
2021
|
+
preLoadCheck(path: string, jsonOut: JsonObject): void
|
|
2022
|
+
|
|
2023
|
+
/**
|
|
2024
|
+
* The same as {@link Pdf.preLoadCheck}, but examines the PDF contained in `bd` instead of a file.
|
|
2025
|
+
* See {@link Pdf.preLoadCheck} for the members returned in `jsonOut`.
|
|
2026
|
+
*
|
|
2027
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
2028
|
+
* {@link Pdf.lastErrorText}.
|
|
2029
|
+
*/
|
|
2030
|
+
preLoadCheckBd(bd: BinData, jsonOut: JsonObject): void
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Replaces text in the page content of the loaded PDF: placeholders such as `{{name}}`, and the
|
|
2034
|
+
* values that follow labels such as `Invoice #:`. The `op` selects the operation, the `jsonIn`
|
|
2035
|
+
* names the values to put in, and the `jsonOut` receives a report. Returns `true` on success and
|
|
2036
|
+
* `false` on failure; for `apply`, `false` also when the replacements could not be made, in which
|
|
2037
|
+
* case the PDF is unchanged and the report says why.
|
|
2038
|
+
*
|
|
2039
|
+
* A PDF stores positioned glyphs drawn with particular fonts, not editable text, so a replacement
|
|
2040
|
+
* is only possible when the new text can be drawn with the font the original used. Chilkat finds
|
|
2041
|
+
* each placeholder or label on the assembled lines of the selected pages, encodes the new value
|
|
2042
|
+
* with that font and size, recomputes its width, and rewrites the content stream in place. The
|
|
2043
|
+
* font rule: a standard-14 font (Helvetica, Times, Courier and their faces, or a non-embedded
|
|
2044
|
+
* font that every viewer substitutes with one of them: Arial, Times New Roman, Courier New) can
|
|
2045
|
+
* draw any character its encoding has; an embedded font can draw any character it has a glyph
|
|
2046
|
+
* for; any other font that is not embedded cannot be used. Every replacement is checked first,
|
|
2047
|
+
* and `apply` is all or nothing: if any replacement fails the rule, nothing is changed.
|
|
2048
|
+
*
|
|
2049
|
+
* **Operations (`op`)**
|
|
2050
|
+
*
|
|
2051
|
+
* - **check** - Finds every placeholder and label and applies the font rule, but changes nothing.
|
|
2052
|
+
* The report says whether `apply` would succeed (`ok`) and lists the problems.
|
|
2053
|
+
*
|
|
2054
|
+
* - **apply** - The same, then makes the replacements when there are no problems. The changes are
|
|
2055
|
+
* written when {@link Pdf.writeFile} or {@link Pdf.writeBd} is called; the PDF is then saved as
|
|
2056
|
+
* a full rewrite, so that the old values do not survive in an earlier revision of the file.
|
|
2057
|
+
*
|
|
2058
|
+
* **Summary of JSON Options (`jsonIn`)**
|
|
2059
|
+
*
|
|
2060
|
+
* - **pages** - The pages to search. Can be `all` (the default), `first`, `last`, `odd`, `even`,
|
|
2061
|
+
* or a list of 1-based pages and ranges such as `1,3,5-9,12-`.
|
|
2062
|
+
*
|
|
2063
|
+
* - **placeholders** - An object whose member names are placeholder names and whose values are
|
|
2064
|
+
* the text to put in, such as `{ "customer": "Acme Corp", "total": "$1,234.56" }` for the
|
|
2065
|
+
* placeholders `{{customer}}` and `{{total}}`. A value may be a string, number or boolean;
|
|
2066
|
+
* `null` means an empty string. Every occurrence of a placeholder on the selected pages is
|
|
2067
|
+
* replaced.
|
|
2068
|
+
*
|
|
2069
|
+
* - **placeholderSyntax** - The delimiters around a placeholder name, written around the word
|
|
2070
|
+
* `name`: the default is `{{name}}`; `[[name]]` or `<<name>>` are other choices.
|
|
2071
|
+
*
|
|
2072
|
+
* - **labels** - An array of objects, each with:
|
|
2073
|
+
*
|
|
2074
|
+
* - **label** - The label text as it appears on the page, such as `Invoice #:`. Matching ignores
|
|
2075
|
+
* case, extra spaces and a trailing colon.
|
|
2076
|
+
*
|
|
2077
|
+
* - **value** - The new text. It replaces the rest of the label's line; when nothing follows the
|
|
2078
|
+
* label, the value is inserted after it.
|
|
2079
|
+
*
|
|
2080
|
+
* - **occurrence** - `first` (the default), `all`, or a number (`2` for the second occurrence).
|
|
2081
|
+
* Occurrences are counted in reading order across the selected pages.
|
|
2082
|
+
*
|
|
2083
|
+
* - **align** - `auto` (the default), `left`, `right`, or `center`. Where the new text sits when
|
|
2084
|
+
* its width differs from the old. `auto` keeps a placeholder in place when it is right-aligned
|
|
2085
|
+
* with other text on the page, or centered on the page, and otherwise keeps the left edge; a
|
|
2086
|
+
* label's value is always left-aligned after its label.
|
|
2087
|
+
*
|
|
2088
|
+
* - **unusedPlaceholders** - What to do with a placeholder found on the page that has no value in
|
|
2089
|
+
* `placeholders`: `error` (the default; a problem with the reason `unusedPlaceholder`), `blank`
|
|
2090
|
+
* (replaced by nothing), or `keep` (left as it is).
|
|
2091
|
+
*
|
|
2092
|
+
* - **unmatchedValues** - What to do with a value whose placeholder or label is not found on the
|
|
2093
|
+
* selected pages: `error` (the default; a problem with the reason `notFound`) or `ignore`.
|
|
2094
|
+
*
|
|
2095
|
+
* **Results (`jsonOut`)**
|
|
2096
|
+
*
|
|
2097
|
+
* - **applied** - Boolean: the replacements were made (`apply` only).
|
|
2098
|
+
*
|
|
2099
|
+
* - **ok** - Boolean (`check` only): no problems were found, so `apply` would succeed.
|
|
2100
|
+
*
|
|
2101
|
+
* - **replacements\[i\]** - One entry per placeholder or label that was (or would be) replaced:
|
|
2102
|
+
* **field** (the placeholder name) or **label**, **pages** (such as `1,3`) and **count**.
|
|
2103
|
+
*
|
|
2104
|
+
* - **problems\[i\]** - What prevents `apply`: **field** or **label**, **reason**, **page**, and
|
|
2105
|
+
* for font problems **font** and **chars** (the characters the font cannot draw). The reasons:
|
|
2106
|
+
*
|
|
2107
|
+
* - `notFound` - The placeholder or label was not found on the selected pages.
|
|
2108
|
+
*
|
|
2109
|
+
* - `unusedPlaceholder` - A placeholder on the page has no value (see `unusedPlaceholders`).
|
|
2110
|
+
*
|
|
2111
|
+
* - `missingGlyph` - The embedded font has no glyph for one or more characters of the value.
|
|
2112
|
+
*
|
|
2113
|
+
* - `notInEncoding` - The standard font's encoding has no code for one or more characters of the
|
|
2114
|
+
* value.
|
|
2115
|
+
*
|
|
2116
|
+
* - `nonStandardUnembeddedFont` - The text is drawn with a font that is neither standard-14 nor
|
|
2117
|
+
* embedded, so Chilkat has no way to know what it can draw.
|
|
2118
|
+
*
|
|
2119
|
+
* - `unsupportedFont` - The font cannot be used for new text (a Type 3 font, or a font program
|
|
2120
|
+
* that could not be read).
|
|
2121
|
+
*
|
|
2122
|
+
* - `placeholderSpansFonts` - The placeholder or value is drawn with more than one font or size,
|
|
2123
|
+
* so there is no single font to draw the replacement with.
|
|
2124
|
+
*
|
|
2125
|
+
* - **warnings\[i\]** - Replacements that were made but may not look right: the reason `overlap`
|
|
2126
|
+
* means the new text runs into neighbouring text or off the page.
|
|
2127
|
+
*
|
|
2128
|
+
* - **notReplaced\[i\]** - Placeholders found outside the page content, which this method does
|
|
2129
|
+
* not change: **field** and **where** (`metadata` for the document's Title, Author, Subject,
|
|
2130
|
+
* Keywords, Creator or Producer; `linkTarget` for a link's URL; `formField` for a form field
|
|
2131
|
+
* value).
|
|
2132
|
+
*
|
|
2133
|
+
* **Signed and encrypted PDFs**
|
|
2134
|
+
*
|
|
2135
|
+
* `apply` rewrites the page content, which invalidates signatures: on a signed PDF it is refused
|
|
2136
|
+
* while {@link Pdf.preserveSignatures} is \*true\* (the default). An encrypted PDF must have been
|
|
2137
|
+
* opened, and `apply` requires owner rights or the modify permission. `check` only reads.
|
|
2138
|
+
*
|
|
2139
|
+
* **Example: fill a template**
|
|
2140
|
+
*
|
|
2141
|
+
* ```
|
|
2142
|
+
* jsonIn: { "placeholders": { "customer": "Acme Corp", "date": "2026-10-18", "total": "$1,234.56" },
|
|
2143
|
+
* "labels": [ { "label": "Invoice #:", "value": "INV-2026-0412" } ] }
|
|
2144
|
+
* pdf.TextReplace("apply", jsonIn, jsonOut)
|
|
2145
|
+
* jsonOut: { "applied": true,
|
|
2146
|
+
* "replacements": [ { "field": "customer", "pages": "1", "count": 1 },
|
|
2147
|
+
* { "field": "date", "pages": "1", "count": 1 },
|
|
2148
|
+
* { "field": "total", "pages": "1", "count": 1 },
|
|
2149
|
+
* { "label": "Invoice #:", "pages": "1", "count": 1 } ],
|
|
2150
|
+
* "warnings": [], "problems": [], "notReplaced": [] }
|
|
2151
|
+
* ```
|
|
2152
|
+
*
|
|
2153
|
+
* **Example: a check that fails the font rule**
|
|
2154
|
+
*
|
|
2155
|
+
* ```
|
|
2156
|
+
* jsonIn: { "placeholders": { "customer": "Müller GmbH" } }
|
|
2157
|
+
* pdf.TextReplace("check", jsonIn, jsonOut)
|
|
2158
|
+
* jsonOut: { "applied": false, "ok": false,
|
|
2159
|
+
* "replacements": [],
|
|
2160
|
+
* "problems": [ { "field": "customer", "reason": "missingGlyph", "chars": "ü", "font": "ABCDEF+OpenSans-Regular", "page": 1 } ],
|
|
2161
|
+
* "warnings": [], "notReplaced": [] }
|
|
2162
|
+
* ```
|
|
2163
|
+
*
|
|
2164
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
2165
|
+
* {@link Pdf.lastErrorText}.
|
|
2166
|
+
*/
|
|
2167
|
+
textReplace(op: string, jsonIn: JsonObject, jsonOut: JsonObject): void
|
|
2168
|
+
|
|
2169
|
+
/**
|
|
2170
|
+
* The same as {@link Pdf.addEmbeddedFiles}, except that the updated PDF stays in memory instead
|
|
2171
|
+
* of being written to a file. Call {@link Pdf.writeFile} or {@link Pdf.writeBd} to write it, or
|
|
2172
|
+
* go on to other operations first: the embedded files are part of the loaded document as soon as
|
|
2173
|
+
* this method returns, so {@link Pdf.numEmbeddedFiles} and {@link Pdf.getEmbeddedFileInfo} see
|
|
2174
|
+
* them, and so do {@link Pdf.protection}, {@link Pdf.watermark}, {@link Pdf.optimize} and {@link
|
|
2175
|
+
* Pdf.signPdf}.
|
|
2176
|
+
*
|
|
2177
|
+
* Changes pending from other methods (a watermark added, a security change, an optimization,
|
|
2178
|
+
* replaced text) are committed first, so the files are added to the document's current state; the
|
|
2179
|
+
* embedded files themselves are added as an incremental update. See {@link Pdf.addEmbeddedFiles}
|
|
2180
|
+
* for the members of `json`.
|
|
2181
|
+
*
|
|
2182
|
+
* @throws Error if the call fails (the message names the reason); the full log is in
|
|
2183
|
+
* {@link Pdf.lastErrorText}.
|
|
2184
|
+
*/
|
|
2185
|
+
addEmbeddedFiles2(json: JsonObject): void
|
|
2186
|
+
|
|
716
2187
|
// ---- Events (ReactNativeGen_DESIGN.md §6) ----
|
|
717
2188
|
|
|
718
2189
|
/**
|