ts-d2 0.0.21 → 0.0.23

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/README.md CHANGED
@@ -40,13 +40,27 @@ import * as fs from "fs";
40
40
  import Deuterium from "ts-d2";
41
41
 
42
42
  new Deuterium.Content.Document("Hello World")
43
- .convertTo(Deuterium.OutputFormat.PDF)
43
+ .convertTo(Deuterium.Output.OutputFormat.PDF)
44
44
  .then(async (buffer) => {
45
45
  // save blob to file
46
46
  fs.writeFileSync("output.pdf", Buffer.from(await buffer.arrayBuffer()));
47
47
  });
48
48
  ```
49
49
 
50
+ ### Job Parameters
51
+
52
+ Both `convertTo` and `convertToPDF` accept an optional `jobParams` argument — a free-form object that is merged into the request metadata sent to the docPIPE server:
53
+
54
+ ```typescript
55
+ new Deuterium.Content.Document("Hello World")
56
+ .convertTo(Deuterium.Output.OutputFormat.PDF, undefined, { locale: "en-US" })
57
+ .then(async (buffer) => {
58
+ fs.writeFileSync("output.pdf", Buffer.from(await buffer.arrayBuffer()));
59
+ });
60
+ ```
61
+
62
+ These job parameters are available in docPIPE as job variables.
63
+
50
64
  ### Custom Connection
51
65
 
52
66
  By default, the library uses the connection credentials from your `.env` file. If you need to use different credentials for a specific conversion, you can create a custom `Connection` instance:
@@ -62,7 +76,7 @@ const customConnection = new Deuterium.Connection(
62
76
 
63
77
  // Use the custom connection for conversion
64
78
  const doc = new Deuterium.Content.Document("Hello World");
65
- customConnection.convertTo(Deuterium.OutputFormat.PDF, doc)
79
+ customConnection.convertTo(Deuterium.Output.OutputFormat.PDF, doc)
66
80
  .then(async (buffer) => {
67
81
  fs.writeFileSync("output.pdf", Buffer.from(await buffer.arrayBuffer()));
68
82
  });
@@ -80,23 +94,17 @@ All the supported DocumentElements are placed in the package `Deuterium.Content`
80
94
 
81
95
  ## Leaf elements
82
96
 
83
- The following leaf elements are currently supported:
84
- * Barcode
85
- * ColumnDefinition (only useful for page-based formats)
86
- * Directory
87
- * Footer
88
- * Formatted (may be used to directly insert docTYPE code and/or HTML code)
89
- * Header
90
- * Linebreak
91
- * Pagebreak
92
- * PageDefinition (only useful for page-based formats)
93
- * Paragraph
94
- * SpaceVertically
95
- * Span
96
- * Table
97
- * TableCell
98
- * TableRow
99
- * Text
97
+ Leaf elements have no children. The following leaf elements are supported:
98
+
99
+ * **Barcode** -- renders a barcode (QR, Code128, etc.) with configurable position, size and rotation
100
+ * **Linebreak** -- inserts a line break
101
+ * **Image** -- embeds an image with support for scaling, cropping, flipping, rotation and absolute positioning
102
+ * **Pagebreak** -- inserts a page break
103
+ * **Rule** -- draws a horizontal or vertical line with configurable style (solid, dashed, dotted, double, etc.), color and thickness
104
+ * **SpaceVertically** -- inserts vertical whitespace of a given height
105
+ * **Tag** -- inserts a named tag with optional parameters
106
+ * **Text** -- renders a plain text string
107
+ * **Variable** -- inserts a dynamic variable (data path, page number, date, etc.)
100
108
 
101
109
  Any leaf element may be added to multiple branch elements (there is no connection from a leaf element to its parent element).
102
110
 
@@ -118,6 +126,63 @@ new Deuterium.Content.Span("Hello World!", {
118
126
  });
119
127
  ```
120
128
 
129
+ ### Image
130
+
131
+ ```typescript
132
+ new Deuterium.Content.Image({
133
+ /* Currently only images located on the docPIPE server are supported. */
134
+ src: "logo.png",
135
+ alt: "Company Logo",
136
+ width: new Deuterium.Measure.AbsoluteMeasure(200, "pt"),
137
+ height: new Deuterium.Measure.AbsoluteMeasure(100, "pt"),
138
+ scaleType: "absolute",
139
+ });
140
+ ```
141
+
142
+ ### Variable
143
+
144
+ Variables can display dynamic data or special values like page numbers:
145
+
146
+ ```typescript
147
+ // Data variable
148
+ new Deuterium.Content.Variable({ path: "customer.name" });
149
+
150
+ // Page number
151
+ new Deuterium.Content.Variable({ specialType: "cur-page" });
152
+
153
+ // Total page count
154
+ new Deuterium.Content.Variable({ specialType: "page-count" });
155
+ ```
156
+
157
+ ### Rule
158
+
159
+ ```typescript
160
+ new Deuterium.Content.Rule({
161
+ width: new Deuterium.Measure.AbsoluteMeasure(400, "pt"),
162
+ thickness: new Deuterium.Measure.AbsoluteMeasure(1, "pt"),
163
+ color: Deuterium.Color.Colors.black,
164
+ style: "solid",
165
+ });
166
+ ```
167
+
168
+ ### Barcode
169
+
170
+ ```typescript
171
+ import Proto from "docframe-types";
172
+
173
+ new Deuterium.Content.Barcode({
174
+ type: Proto.ProtoBarcodeType.QRCODE,
175
+ data: "https://example.com",
176
+ x: new Deuterium.Measure.AbsoluteMeasure(0, "pt"),
177
+ y: new Deuterium.Measure.AbsoluteMeasure(0, "pt"),
178
+ width: new Deuterium.Measure.AbsoluteMeasure(100, "pt"),
179
+ height: new Deuterium.Measure.AbsoluteMeasure(100, "pt"),
180
+ referencePoint: "top-left",
181
+ rotation: 0,
182
+ positionAbsolute: false,
183
+ });
184
+ ```
185
+
121
186
  ## Branch elements
122
187
 
123
188
  Branch elements have two functionalities:
@@ -125,15 +190,31 @@ Branch elements have two functionalities:
125
190
  * Apply formatting/properties to their child elements.
126
191
 
127
192
  The following branch elements are supported:
128
- * Directory
129
- * Document
130
- * Footer
131
- * Header
132
- * Paragraph
133
- * Span
134
- * Table
135
- * TableCell
136
- * TableRow
193
+
194
+ * **AdjustHorizontally** -- adjusts font size within min/max bounds to fit content horizontally
195
+ * **AdvancedIllustrationArea** -- a positioned area for illustrations with text flow control
196
+ * **CarryOver** -- defines content carried over when a table breaks across pages
197
+ * **Condition** -- conditionally includes content based on a code expression
198
+ * **Directory** -- groups elements with optional name, editability and semantic type
199
+ * **Document** -- the root element; holds page/column definitions, paragraph formats and all content
200
+ * **Footer** -- defines page footer content with configurable mode (append, extend, replace)
201
+ * **Header** -- defines page header content with configurable mode (append, extend, replace)
202
+ * **Indentation** -- applies left/right indentation to its children
203
+ * **Link** -- wraps content in a hyperlink
204
+ * **Loop** -- iterates over a data path, rendering children for each entry
205
+ * **LoopEntry** -- represents a single entry inside a Loop
206
+ * **PageCondition** -- conditionally includes content evaluated per page
207
+ * **Paragraph** -- groups inline content under a named paragraph format with optional overrides
208
+ * **Section** -- defines a document section, optionally with its own column definition
209
+ * **Selection** -- groups selectable entries (single or multi-select)
210
+ * **SelectionEntry** -- a single option inside a Selection
211
+ * **Span** -- applies inline formatting (bold, italic, underline, strikethrough, color, sub/superscript)
212
+ * **SubTotal** -- defines a sub-total area for tables (e.g. running totals)
213
+ * **Table** -- a table element with configurable width, offset and repeating headers
214
+ * **TableCell** -- a table cell with alignment, background color, borders, padding, margin and rotation
215
+ * **TableContentGroup** -- groups table rows (e.g. header group, body group, footer group)
216
+ * **TableRow** -- a table row with optional minimum height
217
+ * **WsArea** -- wraps content to control widow/orphan and page-split behavior
137
218
 
138
219
  ### Content parameter
139
220
 
@@ -151,6 +232,108 @@ Especially the first variant of the content parameter can result in small code:
151
232
  new Deuterium.Content.Footer("...");
152
233
  ```
153
234
 
235
+ ### Span
236
+
237
+ ```typescript
238
+ new Deuterium.Content.Span("Important!", {
239
+ bold: true,
240
+ italic: true,
241
+ color: Deuterium.Color.Color.rgb(255, 0, 0),
242
+ underline: true,
243
+ });
244
+ ```
245
+
246
+ ### Link
247
+
248
+ ```typescript
249
+ new Deuterium.Content.Link("Click here", "https://example.com");
250
+ ```
251
+
252
+ ### Table
253
+
254
+ ```typescript
255
+ new Deuterium.Content.Table(
256
+ new Deuterium.Content.TableRow([
257
+ new Deuterium.Content.TableCell("Column 1", {
258
+ border: new Deuterium.Border.SideBorders({
259
+ bottom: new Deuterium.Border.Border(
260
+ new Deuterium.Measure.AbsoluteMeasure(1, "pt"),
261
+ Deuterium.Color.Colors.black,
262
+ ),
263
+ }),
264
+ }),
265
+ new Deuterium.Content.TableCell("Column 2"),
266
+ ]),
267
+ { repeatHeader: 1 },
268
+ );
269
+ ```
270
+
271
+ ### Header and Footer
272
+
273
+ ```typescript
274
+ new Deuterium.Content.Header("Page header content", { mode: "replace" });
275
+ new Deuterium.Content.Footer("Page footer content", { mode: "append" });
276
+ ```
277
+
278
+ ### Condition
279
+
280
+ ```typescript
281
+ new Deuterium.Content.Condition(
282
+ "This is only shown when the condition is true",
283
+ { code: "data.showSection === true", result: true },
284
+ );
285
+ ```
286
+
287
+ ### Loop
288
+
289
+ ```typescript
290
+ new Deuterium.Content.Loop(
291
+ new Deuterium.Content.Variable({ path: "item.name" }),
292
+ { path: "items" },
293
+ );
294
+ ```
295
+
296
+ ### Indentation
297
+
298
+ ```typescript
299
+ new Deuterium.Content.Indentation(
300
+ "This text is indented",
301
+ { left: new Deuterium.Measure.AbsoluteMeasure(30, "pt") },
302
+ );
303
+ ```
304
+
305
+ ## Support classes
306
+
307
+ In addition to the document elements, the library provides several support classes:
308
+
309
+ * **Deuterium.Alignment** -- predefined horizontal (Left, Center, Right, Justify, FullJustify) and vertical (Top, Middle, Bottom) alignment values
310
+ * **Deuterium.Border** -- `Border` (weight + color) and `SideBorders` (top/right/bottom/left)
311
+ * **Deuterium.Color** -- `Color.rgb()`, `Color.cmyk()`, `Color.fromHex()` factory methods and preset `Colors` (black, white)
312
+ * **Deuterium.Font** -- `Font` class and `StandardFonts` (Helvetica)
313
+ * **Deuterium.Measure** -- `AbsoluteMeasure` (pt, cm, mm, in, px), `Measure` (also supports %), `SideMeasures` and `Sides`
314
+ * **Deuterium.ParagraphFormat** -- defines named paragraph formats with font, size, line feed, spacing, alignment, bold/italic and indentation
315
+
316
+ ## Page layout
317
+
318
+ For page-based output formats (PDF, PostScript), you can configure page size and column layout:
319
+
320
+ ```typescript
321
+ const doc = new Deuterium.Content.Document("Content", {
322
+ pageDefinition: new Deuterium.Content.PageDefinition(
323
+ new Deuterium.Measure.AbsoluteMeasure(595, "pt"),
324
+ new Deuterium.Measure.AbsoluteMeasure(842, "pt"),
325
+ ),
326
+ columnDefinition: new Deuterium.Content.ColumnDefinition({
327
+ position: Deuterium.Content.ColumnPosition.Center,
328
+ interColumnSpace: new Deuterium.Measure.AbsoluteMeasure(0, "pt"),
329
+ positionOffset: new Deuterium.Measure.AbsoluteMeasure(70, "pt"),
330
+ width: new Deuterium.Measure.AbsoluteMeasure(490, "pt"),
331
+ }),
332
+ });
333
+ ```
334
+
335
+ Predefined page sizes are available via `PageDefinitions` (A3, A4, A5) and column presets via `ColumnDefinitions`.
336
+
154
337
  # Contributing
155
338
 
156
339
  Contributions to this project are very welcome. If you want to contribute, please create a pull request with your changes and a description of what you have done.
@@ -170,4 +353,4 @@ To run the tests, you can use the following command:
170
353
 
171
354
  ```bash
172
355
  npm run test
173
- ```
356
+ ```