docx 9.7.2 → 9.8.1

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.
@@ -0,0 +1,173 @@
1
+ import { IContext } from 'docx';
2
+ import { IXmlableObject } from 'docx';
3
+ import { XmlComponent } from 'docx';
4
+
5
+ /**
6
+ * Options for creating an image watermark.
7
+ *
8
+ * @see {@link ImageWatermark}
9
+ */
10
+ export declare type IImageWatermarkOptions = {
11
+ /** The image format. VML pictures do not support SVG. */
12
+ readonly type: "jpg" | "png" | "gif" | "bmp";
13
+ /** The image data. Accepts a Buffer, Uint8Array, ArrayBuffer, or a base64-encoded data URI string. */
14
+ readonly data: Buffer | string | Uint8Array | ArrayBuffer;
15
+ /** Size at which the image is drawn, in pixels, matching ImageRun. The image is centred on the page. */
16
+ readonly transformation: {
17
+ /** Display width in pixels. */
18
+ readonly width: number;
19
+ /** Display height in pixels. */
20
+ readonly height: number;
21
+ };
22
+ /** Whether the image is lightened so that text remains readable over it. Default is true, matching Word's "Washout" option. */
23
+ readonly washout?: boolean;
24
+ /** Title of the image, shown by Word as the picture's name. */
25
+ readonly title?: string;
26
+ };
27
+
28
+ /**
29
+ * Represents an image watermark in a WordprocessingML document.
30
+ *
31
+ * ImageWatermark is an inline element that belongs inside a paragraph, and the
32
+ * paragraph belongs in a header so that the watermark repeats on every page of
33
+ * the section. It renders as a picture shape centred on the page behind the
34
+ * document text, exactly as Word's Design > Watermark command does, so Word
35
+ * recognizes it and can remove or replace it through that command.
36
+ *
37
+ * The image is registered with the document's media collection during
38
+ * serialization and linked from the header through a relationship, in the same
39
+ * way as an ImageRun.
40
+ *
41
+ * @publicApi
42
+ *
43
+ * ## XSD Schema
44
+ * The watermark combines several elements:
45
+ * - w:r (run container)
46
+ * - w:pict (picture element containing VML)
47
+ * - v:shapetype (picture frame shape type definition)
48
+ * - v:shape (the positioned picture shape)
49
+ * - v:imagedata (the image reference and washout adjustments)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * new Document({
54
+ * sections: [
55
+ * {
56
+ * headers: {
57
+ * default: new Header({
58
+ * children: [
59
+ * new Paragraph({
60
+ * children: [
61
+ * new ImageWatermark({
62
+ * type: "png",
63
+ * data: fs.readFileSync("./logo.png"),
64
+ * transformation: { width: 400, height: 400 },
65
+ * }),
66
+ * ],
67
+ * }),
68
+ * ],
69
+ * }),
70
+ * },
71
+ * children: [new Paragraph("Body text")],
72
+ * },
73
+ * ],
74
+ * });
75
+ * ```
76
+ */
77
+ export declare class ImageWatermark extends XmlComponent {
78
+ private readonly mediaData;
79
+ constructor({ type, data, transformation, washout, title }: IImageWatermarkOptions);
80
+ prepForXml(context: IContext): IXmlableObject | undefined;
81
+ }
82
+
83
+ /**
84
+ * Options for creating a text watermark.
85
+ *
86
+ * @see {@link TextWatermark}
87
+ */
88
+ export declare type ITextWatermarkOptions = {
89
+ /** The text to display, e.g. "DRAFT". */
90
+ readonly text: string;
91
+ /** Font family. Default is Calibri. */
92
+ readonly font?: string;
93
+ /**
94
+ * Font size in points. When omitted the text is sized automatically to fill the
95
+ * watermark's width and height, which is what Word does by default.
96
+ */
97
+ readonly fontSize?: number;
98
+ /** Whether the text is bold. */
99
+ readonly bold?: boolean;
100
+ /** Whether the text is italic. */
101
+ readonly italics?: boolean;
102
+ /** Colour of the text: a named colour such as "silver" or a hex value such as "C0C0C0". Default is silver. */
103
+ readonly color?: string;
104
+ /** Opacity of the text from 0 (invisible) to 1 (solid). Default is 0.5, Word's "semitransparent" setting. */
105
+ readonly opacity?: number;
106
+ /** Whether the text runs diagonally across the page or horizontally. Default is diagonal. */
107
+ readonly layout?: WatermarkLayout;
108
+ /** Clockwise rotation in degrees. Overrides the rotation implied by the layout. */
109
+ readonly rotation?: number;
110
+ /** Width of the watermark in points. Default is 527.85, which spans a Letter or A4 page diagonally. */
111
+ readonly width?: number;
112
+ /** Height of the watermark in points. Defaults to a height that keeps the letters in proportion for the width. */
113
+ readonly height?: number;
114
+ };
115
+
116
+ /**
117
+ * Represents a text watermark in a WordprocessingML document.
118
+ *
119
+ * TextWatermark is an inline element that belongs inside a paragraph, and the
120
+ * paragraph belongs in a header so that the watermark repeats on every page of
121
+ * the section. It renders as a WordArt shape centred on the page behind the
122
+ * document text, exactly as Word's Design > Watermark command does, so Word
123
+ * recognizes it and can remove or replace it through that command.
124
+ *
125
+ * @publicApi
126
+ *
127
+ * ## XSD Schema
128
+ * The watermark combines several elements:
129
+ * - w:r (run container)
130
+ * - w:pict (picture element containing VML)
131
+ * - v:shapetype (WordArt shape type definition)
132
+ * - v:shape (the positioned WordArt shape)
133
+ * - v:fill (opacity)
134
+ * - v:textpath (the text and its font)
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * new Document({
139
+ * sections: [
140
+ * {
141
+ * headers: {
142
+ * default: new Header({
143
+ * children: [new Paragraph({ children: [new TextWatermark({ text: "DRAFT" })] })],
144
+ * }),
145
+ * },
146
+ * children: [new Paragraph("Body text")],
147
+ * },
148
+ * ],
149
+ * });
150
+ *
151
+ * // Customised watermark
152
+ * new TextWatermark({
153
+ * text: "CONFIDENTIAL",
154
+ * font: "Arial",
155
+ * color: "FF0000",
156
+ * opacity: 0.3,
157
+ * layout: "horizontal",
158
+ * });
159
+ * ```
160
+ */
161
+ export declare class TextWatermark extends XmlComponent {
162
+ constructor({ text, font, fontSize, bold, italics, color, opacity, layout, rotation, width, height, }: ITextWatermarkOptions);
163
+ }
164
+
165
+ /**
166
+ * Layout of a text watermark on the page.
167
+ *
168
+ * - `diagonal`: rotated from bottom-left to top-right (Word's default)
169
+ * - `horizontal`: not rotated
170
+ */
171
+ export declare type WatermarkLayout = "diagonal" | "horizontal";
172
+
173
+ export { }
@@ -0,0 +1,173 @@
1
+ import { IContext } from 'docx';
2
+ import { IXmlableObject } from 'docx';
3
+ import { XmlComponent } from 'docx';
4
+
5
+ /**
6
+ * Options for creating an image watermark.
7
+ *
8
+ * @see {@link ImageWatermark}
9
+ */
10
+ export declare type IImageWatermarkOptions = {
11
+ /** The image format. VML pictures do not support SVG. */
12
+ readonly type: "jpg" | "png" | "gif" | "bmp";
13
+ /** The image data. Accepts a Buffer, Uint8Array, ArrayBuffer, or a base64-encoded data URI string. */
14
+ readonly data: Buffer | string | Uint8Array | ArrayBuffer;
15
+ /** Size at which the image is drawn, in pixels, matching ImageRun. The image is centred on the page. */
16
+ readonly transformation: {
17
+ /** Display width in pixels. */
18
+ readonly width: number;
19
+ /** Display height in pixels. */
20
+ readonly height: number;
21
+ };
22
+ /** Whether the image is lightened so that text remains readable over it. Default is true, matching Word's "Washout" option. */
23
+ readonly washout?: boolean;
24
+ /** Title of the image, shown by Word as the picture's name. */
25
+ readonly title?: string;
26
+ };
27
+
28
+ /**
29
+ * Represents an image watermark in a WordprocessingML document.
30
+ *
31
+ * ImageWatermark is an inline element that belongs inside a paragraph, and the
32
+ * paragraph belongs in a header so that the watermark repeats on every page of
33
+ * the section. It renders as a picture shape centred on the page behind the
34
+ * document text, exactly as Word's Design > Watermark command does, so Word
35
+ * recognizes it and can remove or replace it through that command.
36
+ *
37
+ * The image is registered with the document's media collection during
38
+ * serialization and linked from the header through a relationship, in the same
39
+ * way as an ImageRun.
40
+ *
41
+ * @publicApi
42
+ *
43
+ * ## XSD Schema
44
+ * The watermark combines several elements:
45
+ * - w:r (run container)
46
+ * - w:pict (picture element containing VML)
47
+ * - v:shapetype (picture frame shape type definition)
48
+ * - v:shape (the positioned picture shape)
49
+ * - v:imagedata (the image reference and washout adjustments)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * new Document({
54
+ * sections: [
55
+ * {
56
+ * headers: {
57
+ * default: new Header({
58
+ * children: [
59
+ * new Paragraph({
60
+ * children: [
61
+ * new ImageWatermark({
62
+ * type: "png",
63
+ * data: fs.readFileSync("./logo.png"),
64
+ * transformation: { width: 400, height: 400 },
65
+ * }),
66
+ * ],
67
+ * }),
68
+ * ],
69
+ * }),
70
+ * },
71
+ * children: [new Paragraph("Body text")],
72
+ * },
73
+ * ],
74
+ * });
75
+ * ```
76
+ */
77
+ export declare class ImageWatermark extends XmlComponent {
78
+ private readonly mediaData;
79
+ constructor({ type, data, transformation, washout, title }: IImageWatermarkOptions);
80
+ prepForXml(context: IContext): IXmlableObject | undefined;
81
+ }
82
+
83
+ /**
84
+ * Options for creating a text watermark.
85
+ *
86
+ * @see {@link TextWatermark}
87
+ */
88
+ export declare type ITextWatermarkOptions = {
89
+ /** The text to display, e.g. "DRAFT". */
90
+ readonly text: string;
91
+ /** Font family. Default is Calibri. */
92
+ readonly font?: string;
93
+ /**
94
+ * Font size in points. When omitted the text is sized automatically to fill the
95
+ * watermark's width and height, which is what Word does by default.
96
+ */
97
+ readonly fontSize?: number;
98
+ /** Whether the text is bold. */
99
+ readonly bold?: boolean;
100
+ /** Whether the text is italic. */
101
+ readonly italics?: boolean;
102
+ /** Colour of the text: a named colour such as "silver" or a hex value such as "C0C0C0". Default is silver. */
103
+ readonly color?: string;
104
+ /** Opacity of the text from 0 (invisible) to 1 (solid). Default is 0.5, Word's "semitransparent" setting. */
105
+ readonly opacity?: number;
106
+ /** Whether the text runs diagonally across the page or horizontally. Default is diagonal. */
107
+ readonly layout?: WatermarkLayout;
108
+ /** Clockwise rotation in degrees. Overrides the rotation implied by the layout. */
109
+ readonly rotation?: number;
110
+ /** Width of the watermark in points. Default is 527.85, which spans a Letter or A4 page diagonally. */
111
+ readonly width?: number;
112
+ /** Height of the watermark in points. Defaults to a height that keeps the letters in proportion for the width. */
113
+ readonly height?: number;
114
+ };
115
+
116
+ /**
117
+ * Represents a text watermark in a WordprocessingML document.
118
+ *
119
+ * TextWatermark is an inline element that belongs inside a paragraph, and the
120
+ * paragraph belongs in a header so that the watermark repeats on every page of
121
+ * the section. It renders as a WordArt shape centred on the page behind the
122
+ * document text, exactly as Word's Design > Watermark command does, so Word
123
+ * recognizes it and can remove or replace it through that command.
124
+ *
125
+ * @publicApi
126
+ *
127
+ * ## XSD Schema
128
+ * The watermark combines several elements:
129
+ * - w:r (run container)
130
+ * - w:pict (picture element containing VML)
131
+ * - v:shapetype (WordArt shape type definition)
132
+ * - v:shape (the positioned WordArt shape)
133
+ * - v:fill (opacity)
134
+ * - v:textpath (the text and its font)
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * new Document({
139
+ * sections: [
140
+ * {
141
+ * headers: {
142
+ * default: new Header({
143
+ * children: [new Paragraph({ children: [new TextWatermark({ text: "DRAFT" })] })],
144
+ * }),
145
+ * },
146
+ * children: [new Paragraph("Body text")],
147
+ * },
148
+ * ],
149
+ * });
150
+ *
151
+ * // Customised watermark
152
+ * new TextWatermark({
153
+ * text: "CONFIDENTIAL",
154
+ * font: "Arial",
155
+ * color: "FF0000",
156
+ * opacity: 0.3,
157
+ * layout: "horizontal",
158
+ * });
159
+ * ```
160
+ */
161
+ export declare class TextWatermark extends XmlComponent {
162
+ constructor({ text, font, fontSize, bold, italics, color, opacity, layout, rotation, width, height, }: ITextWatermarkOptions);
163
+ }
164
+
165
+ /**
166
+ * Layout of a text watermark on the page.
167
+ *
168
+ * - `diagonal`: rotated from bottom-left to top-right (Word's default)
169
+ * - `horizontal`: not rotated
170
+ */
171
+ export declare type WatermarkLayout = "diagonal" | "horizontal";
172
+
173
+ export { }