@qrcommunication/gigapdf-lib 0.66.0 → 0.68.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/CHANGELOG.md +75 -0
- package/dist/index.cjs +94 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +208 -1
- package/dist/index.d.ts +208 -1
- package/dist/index.js +94 -1
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,30 @@ type Exports = {
|
|
|
18
18
|
gp_free(ptr: number, len: number): void;
|
|
19
19
|
[k: string]: any;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The eight PDF access permissions carried by an `/Encrypt` dictionary's `/P`
|
|
23
|
+
* entry (ISO 32000-1 §7.6.3.2, Table 22). Each flag is `true` when the action
|
|
24
|
+
* is **granted** to a user opening the document with the user password; the
|
|
25
|
+
* owner password always lifts every restriction.
|
|
26
|
+
*/
|
|
27
|
+
type PdfPermissions = {
|
|
28
|
+
/** Print the document (low resolution unless {@link printHighRes} is also set). */
|
|
29
|
+
print: boolean;
|
|
30
|
+
/** Modify the document contents (other than annotating, filling or assembling). */
|
|
31
|
+
modify: boolean;
|
|
32
|
+
/** Copy or otherwise extract text and graphics. */
|
|
33
|
+
copy: boolean;
|
|
34
|
+
/** Add or modify annotations and fill in interactive form fields. */
|
|
35
|
+
annotate: boolean;
|
|
36
|
+
/** Fill in existing interactive form fields (even if {@link annotate} is clear). */
|
|
37
|
+
fillForms: boolean;
|
|
38
|
+
/** Extract text and graphics for accessibility tools. */
|
|
39
|
+
accessibility: boolean;
|
|
40
|
+
/** Assemble the document: insert, rotate and delete pages. */
|
|
41
|
+
assemble: boolean;
|
|
42
|
+
/** Print to a high-resolution device (requires {@link print}). */
|
|
43
|
+
printHighRes: boolean;
|
|
44
|
+
};
|
|
21
45
|
/** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
|
|
22
46
|
declare class GigaPdfEngine {
|
|
23
47
|
private readonly ex;
|
|
@@ -84,6 +108,25 @@ declare class GigaPdfEngine {
|
|
|
84
108
|
version: number;
|
|
85
109
|
revision: number;
|
|
86
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Decode the eight access-permission flags from a `/P` permission bitmask
|
|
113
|
+
* (ISO 32000-1 Table 22) into named booleans (`true` = the action is
|
|
114
|
+
* granted). Reserved bits are ignored.
|
|
115
|
+
*/
|
|
116
|
+
decodePermissions(p: number): PdfPermissions;
|
|
117
|
+
/**
|
|
118
|
+
* Read a PDF's access permissions **without decrypting it** (no password
|
|
119
|
+
* needed). Returns the eight named flags decoded from the `/Encrypt`
|
|
120
|
+
* dictionary's `/P`; an unencrypted document grants everything.
|
|
121
|
+
*/
|
|
122
|
+
getPermissions(pdf: Uint8Array): PdfPermissions;
|
|
123
|
+
/**
|
|
124
|
+
* Pack eight access-permission flags into a signed 32-bit `/P` value
|
|
125
|
+
* (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
|
|
126
|
+
* object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
|
|
127
|
+
* via `opts.permissions`, or pass `opts.flags` directly.
|
|
128
|
+
*/
|
|
129
|
+
permissionsToP(flags?: Partial<PdfPermissions>): number;
|
|
87
130
|
/**
|
|
88
131
|
* Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
|
|
89
132
|
* place watermark/header text without embedding a font.
|
|
@@ -322,6 +365,12 @@ declare class GigaPdfEngine {
|
|
|
322
365
|
modelToHtml(model: GigaDocument): string;
|
|
323
366
|
/** Raise a model to RTF (decoded UTF-8 string). */
|
|
324
367
|
modelToRtf(model: GigaDocument): string;
|
|
368
|
+
/** Raise a model to Markdown (decoded UTF-8 string). */
|
|
369
|
+
modelToMarkdown(model: GigaDocument): string;
|
|
370
|
+
/** Raise a model to CSV (decoded UTF-8 string). */
|
|
371
|
+
modelToCsv(model: GigaDocument): string;
|
|
372
|
+
/** Raise a model to an EPUB e-book (`.epub`). */
|
|
373
|
+
modelToEpub(model: GigaDocument): Uint8Array;
|
|
325
374
|
}
|
|
326
375
|
/** A Google font the HTML engine needs (resolved from the catalogue). */
|
|
327
376
|
interface HtmlFontRequest {
|
|
@@ -838,6 +887,31 @@ interface GigaStylePatch {
|
|
|
838
887
|
strike?: boolean;
|
|
839
888
|
color?: [number, number, number] | null;
|
|
840
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* A paragraph-style patch for {@link ModelOp} `setParagraphStyle`: only the
|
|
892
|
+
* present fields are applied (mirror of `model::edit::ParaPatch`). Keys are the
|
|
893
|
+
* op's short names (`indent_left`, not `indent_left_pt`); values in PDF points.
|
|
894
|
+
* Omitting a field leaves the existing value unchanged.
|
|
895
|
+
*/
|
|
896
|
+
interface GigaParaPatch {
|
|
897
|
+
align?: 'left' | 'center' | 'right' | 'justify';
|
|
898
|
+
indent_left?: number;
|
|
899
|
+
indent_right?: number;
|
|
900
|
+
/** First-line indent (positive) or hanging indent (negative), in points. */
|
|
901
|
+
first_line?: number;
|
|
902
|
+
space_before?: number;
|
|
903
|
+
space_after?: number;
|
|
904
|
+
/** Leading policy: font-natural, a size multiple, or a fixed point value. */
|
|
905
|
+
line_height?: {
|
|
906
|
+
t: 'normal';
|
|
907
|
+
} | {
|
|
908
|
+
t: 'multiple';
|
|
909
|
+
v: number;
|
|
910
|
+
} | {
|
|
911
|
+
t: 'points';
|
|
912
|
+
v: number;
|
|
913
|
+
};
|
|
914
|
+
}
|
|
841
915
|
/** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
|
|
842
916
|
type GigaCellValue = {
|
|
843
917
|
t: 'empty';
|
|
@@ -909,6 +983,101 @@ type ModelOp = {
|
|
|
909
983
|
row: number;
|
|
910
984
|
col: number;
|
|
911
985
|
value: GigaCellValue;
|
|
986
|
+
} | {
|
|
987
|
+
op: 'insertTableRow';
|
|
988
|
+
addr: GigaBlockAddr;
|
|
989
|
+
at: number;
|
|
990
|
+
} | {
|
|
991
|
+
op: 'deleteTableRow';
|
|
992
|
+
addr: GigaBlockAddr;
|
|
993
|
+
at: number;
|
|
994
|
+
} | {
|
|
995
|
+
op: 'insertTableColumn';
|
|
996
|
+
addr: GigaBlockAddr;
|
|
997
|
+
at: number;
|
|
998
|
+
} | {
|
|
999
|
+
op: 'deleteTableColumn';
|
|
1000
|
+
addr: GigaBlockAddr;
|
|
1001
|
+
at: number;
|
|
1002
|
+
} | {
|
|
1003
|
+
op: 'setCellSpan';
|
|
1004
|
+
addr: GigaBlockAddr;
|
|
1005
|
+
/** Row index in `rows`. */
|
|
1006
|
+
row: number;
|
|
1007
|
+
/** Cell index in `rows[row].cells` (not a grid column). */
|
|
1008
|
+
col: number;
|
|
1009
|
+
/** Columns the cell spans (clamped to ≥ 1). */
|
|
1010
|
+
col_span: number;
|
|
1011
|
+
/** Rows the cell spans (clamped to ≥ 1). */
|
|
1012
|
+
row_span: number;
|
|
1013
|
+
} | {
|
|
1014
|
+
op: 'insertSheetRow';
|
|
1015
|
+
addr: GigaBlockAddr;
|
|
1016
|
+
sheet: number;
|
|
1017
|
+
at: number;
|
|
1018
|
+
} | {
|
|
1019
|
+
op: 'deleteSheetRow';
|
|
1020
|
+
addr: GigaBlockAddr;
|
|
1021
|
+
sheet: number;
|
|
1022
|
+
at: number;
|
|
1023
|
+
} | {
|
|
1024
|
+
op: 'insertSheetColumn';
|
|
1025
|
+
addr: GigaBlockAddr;
|
|
1026
|
+
sheet: number;
|
|
1027
|
+
at: number;
|
|
1028
|
+
} | {
|
|
1029
|
+
op: 'deleteSheetColumn';
|
|
1030
|
+
addr: GigaBlockAddr;
|
|
1031
|
+
sheet: number;
|
|
1032
|
+
at: number;
|
|
1033
|
+
} | {
|
|
1034
|
+
op: 'setParagraphStyle';
|
|
1035
|
+
addr: GigaBlockAddr;
|
|
1036
|
+
patch: GigaParaPatch;
|
|
1037
|
+
} | {
|
|
1038
|
+
op: 'setListLevel';
|
|
1039
|
+
addr: GigaBlockAddr;
|
|
1040
|
+
level: number;
|
|
1041
|
+
} | {
|
|
1042
|
+
op: 'setListMarker';
|
|
1043
|
+
addr: GigaBlockAddr;
|
|
1044
|
+
marker: GigaListMarker;
|
|
1045
|
+
} | {
|
|
1046
|
+
op: 'setListOrdered';
|
|
1047
|
+
addr: GigaBlockAddr;
|
|
1048
|
+
ordered: boolean;
|
|
1049
|
+
} | {
|
|
1050
|
+
op: 'setBlockFrame';
|
|
1051
|
+
addr: GigaBlockAddr;
|
|
1052
|
+
rect: GigaRect;
|
|
1053
|
+
}
|
|
1054
|
+
/** `deg` is CCW; 0/90/180/270 snap to exact rotations, else an arbitrary angle. */
|
|
1055
|
+
| {
|
|
1056
|
+
op: 'setBlockRotation';
|
|
1057
|
+
addr: GigaBlockAddr;
|
|
1058
|
+
deg: number;
|
|
1059
|
+
}
|
|
1060
|
+
/** `color: null` clears the cell's shading; a triple sets it. */
|
|
1061
|
+
| {
|
|
1062
|
+
op: 'setCellShading';
|
|
1063
|
+
addr: GigaBlockAddr;
|
|
1064
|
+
row: number;
|
|
1065
|
+
col: number;
|
|
1066
|
+
color: [number, number, number] | null;
|
|
1067
|
+
} | {
|
|
1068
|
+
op: 'setRowHeight';
|
|
1069
|
+
addr: GigaBlockAddr;
|
|
1070
|
+
row: number;
|
|
1071
|
+
height: number;
|
|
1072
|
+
} | {
|
|
1073
|
+
op: 'setColWidth';
|
|
1074
|
+
addr: GigaBlockAddr;
|
|
1075
|
+
col: number;
|
|
1076
|
+
width: number;
|
|
1077
|
+
} | {
|
|
1078
|
+
op: 'setTableBorder';
|
|
1079
|
+
addr: GigaBlockAddr;
|
|
1080
|
+
border: GigaBorderStyle;
|
|
912
1081
|
};
|
|
913
1082
|
/**
|
|
914
1083
|
* An image element from {@link GigaPdfDoc.imageElements}: its placement box
|
|
@@ -1318,6 +1487,35 @@ declare class GigaPdfDoc {
|
|
|
1318
1487
|
strokeAlpha?: number;
|
|
1319
1488
|
dash?: number[];
|
|
1320
1489
|
}): boolean;
|
|
1490
|
+
/**
|
|
1491
|
+
* Re-style **sub-ranges** of text run `index` on `page` in place — the
|
|
1492
|
+
* by-character-run companion of {@link setPathStyle}. Each span sets the style
|
|
1493
|
+
* of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
|
|
1494
|
+
* / underline / strike / colour / size); the run is split so the rest keeps its
|
|
1495
|
+
* original style and **positioning is preserved** (the original glyph codes,
|
|
1496
|
+
* including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
|
|
1497
|
+
* each styled slice is wrapped in `q … Q`). Spans may be given in any order and
|
|
1498
|
+
* are clamped to the run's length.
|
|
1499
|
+
*
|
|
1500
|
+
* Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
|
|
1501
|
+
* rescales the slice's font in the run's own text scale; `bold` is faux-bold
|
|
1502
|
+
* (fill+stroke render mode) when no bold variant font is wired; `italic` is a
|
|
1503
|
+
* no-op without an italic/oblique variant (a stream edit can't shear glyphs
|
|
1504
|
+
* without disturbing advances); `underline`/`strike` draw a thin rule in page
|
|
1505
|
+
* space. Returns `false` when `index` does not resolve to a top-level text run
|
|
1506
|
+
* (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
|
|
1507
|
+
* non-matching element.
|
|
1508
|
+
*/
|
|
1509
|
+
setTextRunStyle(page: number, index: number, spans: Array<{
|
|
1510
|
+
start: number;
|
|
1511
|
+
end: number;
|
|
1512
|
+
color?: [number, number, number];
|
|
1513
|
+
sizePt?: number;
|
|
1514
|
+
bold?: boolean;
|
|
1515
|
+
italic?: boolean;
|
|
1516
|
+
underline?: boolean;
|
|
1517
|
+
strike?: boolean;
|
|
1518
|
+
}>): boolean;
|
|
1321
1519
|
/**
|
|
1322
1520
|
* Set a constant opacity on element `index` on `page` — text, image **or**
|
|
1323
1521
|
* shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
|
|
@@ -1586,6 +1784,15 @@ declare class GigaPdfDoc {
|
|
|
1586
1784
|
saveEncrypted(password: string, fileId: string, opts?: {
|
|
1587
1785
|
ownerPassword?: string;
|
|
1588
1786
|
algorithm?: "rc4" | "aes128" | "aes256";
|
|
1787
|
+
/**
|
|
1788
|
+
* Named access permissions (ISO 32000-1 Table 22). Omitted flags default
|
|
1789
|
+
* to **granted**. Takes precedence over `permissions` when present.
|
|
1790
|
+
*/
|
|
1791
|
+
flags?: Partial<PdfPermissions>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Raw signed 32-bit `/P` bitmask. Use {@link flags} for a readable API.
|
|
1794
|
+
* Defaults to all permissions granted when neither is given.
|
|
1795
|
+
*/
|
|
1589
1796
|
permissions?: number;
|
|
1590
1797
|
keySeed?: Uint8Array;
|
|
1591
1798
|
}): Uint8Array;
|
|
@@ -1748,4 +1955,4 @@ declare class GigaPdfDoc {
|
|
|
1748
1955
|
}): boolean;
|
|
1749
1956
|
}
|
|
1750
1957
|
|
|
1751
|
-
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
|
1958
|
+
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,30 @@ type Exports = {
|
|
|
18
18
|
gp_free(ptr: number, len: number): void;
|
|
19
19
|
[k: string]: any;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The eight PDF access permissions carried by an `/Encrypt` dictionary's `/P`
|
|
23
|
+
* entry (ISO 32000-1 §7.6.3.2, Table 22). Each flag is `true` when the action
|
|
24
|
+
* is **granted** to a user opening the document with the user password; the
|
|
25
|
+
* owner password always lifts every restriction.
|
|
26
|
+
*/
|
|
27
|
+
type PdfPermissions = {
|
|
28
|
+
/** Print the document (low resolution unless {@link printHighRes} is also set). */
|
|
29
|
+
print: boolean;
|
|
30
|
+
/** Modify the document contents (other than annotating, filling or assembling). */
|
|
31
|
+
modify: boolean;
|
|
32
|
+
/** Copy or otherwise extract text and graphics. */
|
|
33
|
+
copy: boolean;
|
|
34
|
+
/** Add or modify annotations and fill in interactive form fields. */
|
|
35
|
+
annotate: boolean;
|
|
36
|
+
/** Fill in existing interactive form fields (even if {@link annotate} is clear). */
|
|
37
|
+
fillForms: boolean;
|
|
38
|
+
/** Extract text and graphics for accessibility tools. */
|
|
39
|
+
accessibility: boolean;
|
|
40
|
+
/** Assemble the document: insert, rotate and delete pages. */
|
|
41
|
+
assemble: boolean;
|
|
42
|
+
/** Print to a high-resolution device (requires {@link print}). */
|
|
43
|
+
printHighRes: boolean;
|
|
44
|
+
};
|
|
21
45
|
/** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
|
|
22
46
|
declare class GigaPdfEngine {
|
|
23
47
|
private readonly ex;
|
|
@@ -84,6 +108,25 @@ declare class GigaPdfEngine {
|
|
|
84
108
|
version: number;
|
|
85
109
|
revision: number;
|
|
86
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Decode the eight access-permission flags from a `/P` permission bitmask
|
|
113
|
+
* (ISO 32000-1 Table 22) into named booleans (`true` = the action is
|
|
114
|
+
* granted). Reserved bits are ignored.
|
|
115
|
+
*/
|
|
116
|
+
decodePermissions(p: number): PdfPermissions;
|
|
117
|
+
/**
|
|
118
|
+
* Read a PDF's access permissions **without decrypting it** (no password
|
|
119
|
+
* needed). Returns the eight named flags decoded from the `/Encrypt`
|
|
120
|
+
* dictionary's `/P`; an unencrypted document grants everything.
|
|
121
|
+
*/
|
|
122
|
+
getPermissions(pdf: Uint8Array): PdfPermissions;
|
|
123
|
+
/**
|
|
124
|
+
* Pack eight access-permission flags into a signed 32-bit `/P` value
|
|
125
|
+
* (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
|
|
126
|
+
* object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
|
|
127
|
+
* via `opts.permissions`, or pass `opts.flags` directly.
|
|
128
|
+
*/
|
|
129
|
+
permissionsToP(flags?: Partial<PdfPermissions>): number;
|
|
87
130
|
/**
|
|
88
131
|
* Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
|
|
89
132
|
* place watermark/header text without embedding a font.
|
|
@@ -322,6 +365,12 @@ declare class GigaPdfEngine {
|
|
|
322
365
|
modelToHtml(model: GigaDocument): string;
|
|
323
366
|
/** Raise a model to RTF (decoded UTF-8 string). */
|
|
324
367
|
modelToRtf(model: GigaDocument): string;
|
|
368
|
+
/** Raise a model to Markdown (decoded UTF-8 string). */
|
|
369
|
+
modelToMarkdown(model: GigaDocument): string;
|
|
370
|
+
/** Raise a model to CSV (decoded UTF-8 string). */
|
|
371
|
+
modelToCsv(model: GigaDocument): string;
|
|
372
|
+
/** Raise a model to an EPUB e-book (`.epub`). */
|
|
373
|
+
modelToEpub(model: GigaDocument): Uint8Array;
|
|
325
374
|
}
|
|
326
375
|
/** A Google font the HTML engine needs (resolved from the catalogue). */
|
|
327
376
|
interface HtmlFontRequest {
|
|
@@ -838,6 +887,31 @@ interface GigaStylePatch {
|
|
|
838
887
|
strike?: boolean;
|
|
839
888
|
color?: [number, number, number] | null;
|
|
840
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* A paragraph-style patch for {@link ModelOp} `setParagraphStyle`: only the
|
|
892
|
+
* present fields are applied (mirror of `model::edit::ParaPatch`). Keys are the
|
|
893
|
+
* op's short names (`indent_left`, not `indent_left_pt`); values in PDF points.
|
|
894
|
+
* Omitting a field leaves the existing value unchanged.
|
|
895
|
+
*/
|
|
896
|
+
interface GigaParaPatch {
|
|
897
|
+
align?: 'left' | 'center' | 'right' | 'justify';
|
|
898
|
+
indent_left?: number;
|
|
899
|
+
indent_right?: number;
|
|
900
|
+
/** First-line indent (positive) or hanging indent (negative), in points. */
|
|
901
|
+
first_line?: number;
|
|
902
|
+
space_before?: number;
|
|
903
|
+
space_after?: number;
|
|
904
|
+
/** Leading policy: font-natural, a size multiple, or a fixed point value. */
|
|
905
|
+
line_height?: {
|
|
906
|
+
t: 'normal';
|
|
907
|
+
} | {
|
|
908
|
+
t: 'multiple';
|
|
909
|
+
v: number;
|
|
910
|
+
} | {
|
|
911
|
+
t: 'points';
|
|
912
|
+
v: number;
|
|
913
|
+
};
|
|
914
|
+
}
|
|
841
915
|
/** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
|
|
842
916
|
type GigaCellValue = {
|
|
843
917
|
t: 'empty';
|
|
@@ -909,6 +983,101 @@ type ModelOp = {
|
|
|
909
983
|
row: number;
|
|
910
984
|
col: number;
|
|
911
985
|
value: GigaCellValue;
|
|
986
|
+
} | {
|
|
987
|
+
op: 'insertTableRow';
|
|
988
|
+
addr: GigaBlockAddr;
|
|
989
|
+
at: number;
|
|
990
|
+
} | {
|
|
991
|
+
op: 'deleteTableRow';
|
|
992
|
+
addr: GigaBlockAddr;
|
|
993
|
+
at: number;
|
|
994
|
+
} | {
|
|
995
|
+
op: 'insertTableColumn';
|
|
996
|
+
addr: GigaBlockAddr;
|
|
997
|
+
at: number;
|
|
998
|
+
} | {
|
|
999
|
+
op: 'deleteTableColumn';
|
|
1000
|
+
addr: GigaBlockAddr;
|
|
1001
|
+
at: number;
|
|
1002
|
+
} | {
|
|
1003
|
+
op: 'setCellSpan';
|
|
1004
|
+
addr: GigaBlockAddr;
|
|
1005
|
+
/** Row index in `rows`. */
|
|
1006
|
+
row: number;
|
|
1007
|
+
/** Cell index in `rows[row].cells` (not a grid column). */
|
|
1008
|
+
col: number;
|
|
1009
|
+
/** Columns the cell spans (clamped to ≥ 1). */
|
|
1010
|
+
col_span: number;
|
|
1011
|
+
/** Rows the cell spans (clamped to ≥ 1). */
|
|
1012
|
+
row_span: number;
|
|
1013
|
+
} | {
|
|
1014
|
+
op: 'insertSheetRow';
|
|
1015
|
+
addr: GigaBlockAddr;
|
|
1016
|
+
sheet: number;
|
|
1017
|
+
at: number;
|
|
1018
|
+
} | {
|
|
1019
|
+
op: 'deleteSheetRow';
|
|
1020
|
+
addr: GigaBlockAddr;
|
|
1021
|
+
sheet: number;
|
|
1022
|
+
at: number;
|
|
1023
|
+
} | {
|
|
1024
|
+
op: 'insertSheetColumn';
|
|
1025
|
+
addr: GigaBlockAddr;
|
|
1026
|
+
sheet: number;
|
|
1027
|
+
at: number;
|
|
1028
|
+
} | {
|
|
1029
|
+
op: 'deleteSheetColumn';
|
|
1030
|
+
addr: GigaBlockAddr;
|
|
1031
|
+
sheet: number;
|
|
1032
|
+
at: number;
|
|
1033
|
+
} | {
|
|
1034
|
+
op: 'setParagraphStyle';
|
|
1035
|
+
addr: GigaBlockAddr;
|
|
1036
|
+
patch: GigaParaPatch;
|
|
1037
|
+
} | {
|
|
1038
|
+
op: 'setListLevel';
|
|
1039
|
+
addr: GigaBlockAddr;
|
|
1040
|
+
level: number;
|
|
1041
|
+
} | {
|
|
1042
|
+
op: 'setListMarker';
|
|
1043
|
+
addr: GigaBlockAddr;
|
|
1044
|
+
marker: GigaListMarker;
|
|
1045
|
+
} | {
|
|
1046
|
+
op: 'setListOrdered';
|
|
1047
|
+
addr: GigaBlockAddr;
|
|
1048
|
+
ordered: boolean;
|
|
1049
|
+
} | {
|
|
1050
|
+
op: 'setBlockFrame';
|
|
1051
|
+
addr: GigaBlockAddr;
|
|
1052
|
+
rect: GigaRect;
|
|
1053
|
+
}
|
|
1054
|
+
/** `deg` is CCW; 0/90/180/270 snap to exact rotations, else an arbitrary angle. */
|
|
1055
|
+
| {
|
|
1056
|
+
op: 'setBlockRotation';
|
|
1057
|
+
addr: GigaBlockAddr;
|
|
1058
|
+
deg: number;
|
|
1059
|
+
}
|
|
1060
|
+
/** `color: null` clears the cell's shading; a triple sets it. */
|
|
1061
|
+
| {
|
|
1062
|
+
op: 'setCellShading';
|
|
1063
|
+
addr: GigaBlockAddr;
|
|
1064
|
+
row: number;
|
|
1065
|
+
col: number;
|
|
1066
|
+
color: [number, number, number] | null;
|
|
1067
|
+
} | {
|
|
1068
|
+
op: 'setRowHeight';
|
|
1069
|
+
addr: GigaBlockAddr;
|
|
1070
|
+
row: number;
|
|
1071
|
+
height: number;
|
|
1072
|
+
} | {
|
|
1073
|
+
op: 'setColWidth';
|
|
1074
|
+
addr: GigaBlockAddr;
|
|
1075
|
+
col: number;
|
|
1076
|
+
width: number;
|
|
1077
|
+
} | {
|
|
1078
|
+
op: 'setTableBorder';
|
|
1079
|
+
addr: GigaBlockAddr;
|
|
1080
|
+
border: GigaBorderStyle;
|
|
912
1081
|
};
|
|
913
1082
|
/**
|
|
914
1083
|
* An image element from {@link GigaPdfDoc.imageElements}: its placement box
|
|
@@ -1318,6 +1487,35 @@ declare class GigaPdfDoc {
|
|
|
1318
1487
|
strokeAlpha?: number;
|
|
1319
1488
|
dash?: number[];
|
|
1320
1489
|
}): boolean;
|
|
1490
|
+
/**
|
|
1491
|
+
* Re-style **sub-ranges** of text run `index` on `page` in place — the
|
|
1492
|
+
* by-character-run companion of {@link setPathStyle}. Each span sets the style
|
|
1493
|
+
* of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
|
|
1494
|
+
* / underline / strike / colour / size); the run is split so the rest keeps its
|
|
1495
|
+
* original style and **positioning is preserved** (the original glyph codes,
|
|
1496
|
+
* including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
|
|
1497
|
+
* each styled slice is wrapped in `q … Q`). Spans may be given in any order and
|
|
1498
|
+
* are clamped to the run's length.
|
|
1499
|
+
*
|
|
1500
|
+
* Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
|
|
1501
|
+
* rescales the slice's font in the run's own text scale; `bold` is faux-bold
|
|
1502
|
+
* (fill+stroke render mode) when no bold variant font is wired; `italic` is a
|
|
1503
|
+
* no-op without an italic/oblique variant (a stream edit can't shear glyphs
|
|
1504
|
+
* without disturbing advances); `underline`/`strike` draw a thin rule in page
|
|
1505
|
+
* space. Returns `false` when `index` does not resolve to a top-level text run
|
|
1506
|
+
* (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
|
|
1507
|
+
* non-matching element.
|
|
1508
|
+
*/
|
|
1509
|
+
setTextRunStyle(page: number, index: number, spans: Array<{
|
|
1510
|
+
start: number;
|
|
1511
|
+
end: number;
|
|
1512
|
+
color?: [number, number, number];
|
|
1513
|
+
sizePt?: number;
|
|
1514
|
+
bold?: boolean;
|
|
1515
|
+
italic?: boolean;
|
|
1516
|
+
underline?: boolean;
|
|
1517
|
+
strike?: boolean;
|
|
1518
|
+
}>): boolean;
|
|
1321
1519
|
/**
|
|
1322
1520
|
* Set a constant opacity on element `index` on `page` — text, image **or**
|
|
1323
1521
|
* shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
|
|
@@ -1586,6 +1784,15 @@ declare class GigaPdfDoc {
|
|
|
1586
1784
|
saveEncrypted(password: string, fileId: string, opts?: {
|
|
1587
1785
|
ownerPassword?: string;
|
|
1588
1786
|
algorithm?: "rc4" | "aes128" | "aes256";
|
|
1787
|
+
/**
|
|
1788
|
+
* Named access permissions (ISO 32000-1 Table 22). Omitted flags default
|
|
1789
|
+
* to **granted**. Takes precedence over `permissions` when present.
|
|
1790
|
+
*/
|
|
1791
|
+
flags?: Partial<PdfPermissions>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Raw signed 32-bit `/P` bitmask. Use {@link flags} for a readable API.
|
|
1794
|
+
* Defaults to all permissions granted when neither is given.
|
|
1795
|
+
*/
|
|
1589
1796
|
permissions?: number;
|
|
1590
1797
|
keySeed?: Uint8Array;
|
|
1591
1798
|
}): Uint8Array;
|
|
@@ -1748,4 +1955,4 @@ declare class GigaPdfDoc {
|
|
|
1748
1955
|
}): boolean;
|
|
1749
1956
|
}
|
|
1750
1957
|
|
|
1751
|
-
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
|
1958
|
+
export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParaPatch, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
import { loadDefaultWasmBytes } from "./node-fs.js";
|
|
3
3
|
var enc = new TextEncoder();
|
|
4
4
|
var dec = new TextDecoder();
|
|
5
|
+
var ALL_PERMISSIONS = {
|
|
6
|
+
print: true,
|
|
7
|
+
modify: true,
|
|
8
|
+
copy: true,
|
|
9
|
+
annotate: true,
|
|
10
|
+
fillForms: true,
|
|
11
|
+
accessibility: true,
|
|
12
|
+
assemble: true,
|
|
13
|
+
printHighRes: true
|
|
14
|
+
};
|
|
5
15
|
var GigaPdfEngine = class _GigaPdfEngine {
|
|
6
16
|
constructor(ex) {
|
|
7
17
|
this.ex = ex;
|
|
@@ -218,6 +228,43 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
218
228
|
);
|
|
219
229
|
return JSON.parse(dec.decode(json));
|
|
220
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Decode the eight access-permission flags from a `/P` permission bitmask
|
|
233
|
+
* (ISO 32000-1 Table 22) into named booleans (`true` = the action is
|
|
234
|
+
* granted). Reserved bits are ignored.
|
|
235
|
+
*/
|
|
236
|
+
decodePermissions(p) {
|
|
237
|
+
const json = dec.decode(this._buffer((o) => this.ex.gp_permissions_from_p(p, o)));
|
|
238
|
+
return JSON.parse(json);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Read a PDF's access permissions **without decrypting it** (no password
|
|
242
|
+
* needed). Returns the eight named flags decoded from the `/Encrypt`
|
|
243
|
+
* dictionary's `/P`; an unencrypted document grants everything.
|
|
244
|
+
*/
|
|
245
|
+
getPermissions(pdf) {
|
|
246
|
+
const { encrypted, permissions } = this.encryptionInfo(pdf);
|
|
247
|
+
return encrypted ? this.decodePermissions(permissions) : { ...ALL_PERMISSIONS };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Pack eight access-permission flags into a signed 32-bit `/P` value
|
|
251
|
+
* (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
|
|
252
|
+
* object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
|
|
253
|
+
* via `opts.permissions`, or pass `opts.flags` directly.
|
|
254
|
+
*/
|
|
255
|
+
permissionsToP(flags = {}) {
|
|
256
|
+
const f = { ...ALL_PERMISSIONS, ...flags };
|
|
257
|
+
return this.ex.gp_permissions_to_p(
|
|
258
|
+
f.print ? 1 : 0,
|
|
259
|
+
f.modify ? 1 : 0,
|
|
260
|
+
f.copy ? 1 : 0,
|
|
261
|
+
f.annotate ? 1 : 0,
|
|
262
|
+
f.fillForms ? 1 : 0,
|
|
263
|
+
f.accessibility ? 1 : 0,
|
|
264
|
+
f.assemble ? 1 : 0,
|
|
265
|
+
f.printHighRes ? 1 : 0
|
|
266
|
+
);
|
|
267
|
+
}
|
|
221
268
|
/**
|
|
222
269
|
* Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
|
|
223
270
|
* place watermark/header text without embedding a font.
|
|
@@ -759,6 +806,27 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
759
806
|
(p, l) => this._str((o) => this.ex.gp_model_to_rtf(p, l, o))
|
|
760
807
|
);
|
|
761
808
|
}
|
|
809
|
+
/** Raise a model to Markdown (decoded UTF-8 string). */
|
|
810
|
+
modelToMarkdown(model) {
|
|
811
|
+
return this._withStr(
|
|
812
|
+
JSON.stringify(model),
|
|
813
|
+
(p, l) => this._str((o) => this.ex.gp_model_to_md(p, l, o))
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
/** Raise a model to CSV (decoded UTF-8 string). */
|
|
817
|
+
modelToCsv(model) {
|
|
818
|
+
return this._withStr(
|
|
819
|
+
JSON.stringify(model),
|
|
820
|
+
(p, l) => this._str((o) => this.ex.gp_model_to_csv(p, l, o))
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
/** Raise a model to an EPUB e-book (`.epub`). */
|
|
824
|
+
modelToEpub(model) {
|
|
825
|
+
return this._withStr(
|
|
826
|
+
JSON.stringify(model),
|
|
827
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_epub(p, l, o))
|
|
828
|
+
);
|
|
829
|
+
}
|
|
762
830
|
};
|
|
763
831
|
function packHtmlResources(resources) {
|
|
764
832
|
let size = 4;
|
|
@@ -990,6 +1058,31 @@ var GigaPdfDoc = class {
|
|
|
990
1058
|
(p, l) => this.ex().gp_set_path_style_json(this.h, page, index, p, l)
|
|
991
1059
|
) === 0;
|
|
992
1060
|
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Re-style **sub-ranges** of text run `index` on `page` in place — the
|
|
1063
|
+
* by-character-run companion of {@link setPathStyle}. Each span sets the style
|
|
1064
|
+
* of the `[start, end)` UTF-16 slice of the run's *decoded* text (bold / italic
|
|
1065
|
+
* / underline / strike / colour / size); the run is split so the rest keeps its
|
|
1066
|
+
* original style and **positioning is preserved** (the original glyph codes,
|
|
1067
|
+
* including `TJ` kerning, are sliced and re-emitted — never re-encoded — and
|
|
1068
|
+
* each styled slice is wrapped in `q … Q`). Spans may be given in any order and
|
|
1069
|
+
* are clamped to the run's length.
|
|
1070
|
+
*
|
|
1071
|
+
* Notes on each field: `color` is `[r,g,b]` in `0..=1` (text fill); `sizePt`
|
|
1072
|
+
* rescales the slice's font in the run's own text scale; `bold` is faux-bold
|
|
1073
|
+
* (fill+stroke render mode) when no bold variant font is wired; `italic` is a
|
|
1074
|
+
* no-op without an italic/oblique variant (a stream edit can't shear glyphs
|
|
1075
|
+
* without disturbing advances); `underline`/`strike` draw a thin rule in page
|
|
1076
|
+
* space. Returns `false` when `index` does not resolve to a top-level text run
|
|
1077
|
+
* (e.g. it addresses form-XObject text), like {@link setPathStyle} for a
|
|
1078
|
+
* non-matching element.
|
|
1079
|
+
*/
|
|
1080
|
+
setTextRunStyle(page, index, spans) {
|
|
1081
|
+
return this.g._withStr(
|
|
1082
|
+
JSON.stringify(spans),
|
|
1083
|
+
(p, l) => this.ex().gp_set_text_run_style_json(this.h, page, index, p, l)
|
|
1084
|
+
) === 0;
|
|
1085
|
+
}
|
|
993
1086
|
/**
|
|
994
1087
|
* Set a constant opacity on element `index` on `page` — text, image **or**
|
|
995
1088
|
* shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
|
|
@@ -1500,7 +1593,7 @@ var GigaPdfDoc = class {
|
|
|
1500
1593
|
saveEncrypted(password, fileId, opts = {}) {
|
|
1501
1594
|
const algo = opts.algorithm ?? "aes256";
|
|
1502
1595
|
const algoCode = algo === "rc4" ? 0 : algo === "aes128" ? 1 : 2;
|
|
1503
|
-
const permissions = opts.permissions ??
|
|
1596
|
+
const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
|
|
1504
1597
|
let key = opts.keySeed ?? new Uint8Array(0);
|
|
1505
1598
|
if (algoCode === 2 && key.length < 32) {
|
|
1506
1599
|
const c = globalThis.crypto;
|