jspdf-dynamo 1.0.5 → 1.0.7

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.
Files changed (36) hide show
  1. package/README.md +3 -3
  2. package/dist/index.cjs +199 -33
  3. package/dist/index.d.cts +14 -10
  4. package/dist/index.d.ts +14 -10
  5. package/dist/index.js +199 -33
  6. package/documentation/1. Introduction/Introduction.txt +1 -1
  7. package/documentation/3. Variables/Introduction.txt +13 -12
  8. package/documentation/3. Variables/SystemMaintained.txt +40 -0
  9. package/documentation/4. Commands/DrawBox.txt +6 -9
  10. package/documentation/4. Commands/DrawCircle.txt +71 -0
  11. package/documentation/4. Commands/DrawEllipse.txt +75 -0
  12. package/documentation/4. Commands/DrawTextWrapped.txt +1 -1
  13. package/documentation/4. Commands/IfBlank.txt +9 -14
  14. package/documentation/4. Commands/IfEq.txt +3 -2
  15. package/documentation/4. Commands/IfGt.txt +2 -1
  16. package/documentation/4. Commands/IfNe.txt +54 -0
  17. package/documentation/4. Commands/IfNotBlank.txt +9 -13
  18. package/documentation/4. Commands/LoadImageFromFile.txt +2 -2
  19. package/documentation/4. Commands/LoadImageFromUrl.txt +2 -2
  20. package/documentation/4. Commands/SetFillColour.txt +4 -2
  21. package/documentation/4. Commands/SetFontName.txt +80 -1
  22. package/documentation/4. Commands/SetFontSize.txt +43 -1
  23. package/documentation/4. Commands/SetFontStyle.txt +4 -5
  24. package/documentation/4. Commands/SetLineColour.txt +5 -2
  25. package/documentation/4. Commands/SetTextColour.txt +4 -2
  26. package/documentation/5. Other Definitions/pageSizes.txt +3 -3
  27. package/documentation/Documentation.pdf +0 -0
  28. package/documentation/documentation.txt +3 -0
  29. package/examples/1.Simple/simple.pdf +18 -186
  30. package/examples/2.Invoice/data.txt +21 -0
  31. package/examples/2.Invoice/gearz.png +0 -0
  32. package/examples/2.Invoice/invoice.pdf +0 -0
  33. package/examples/2.Invoice/invoice.spec.ts +62 -0
  34. package/examples/2.Invoice/parts.json +324 -0
  35. package/examples/2.Invoice/template.txt +136 -0
  36. package/package.json +1 -1
@@ -10,25 +10,11 @@
10
10
  endobj
11
11
  4 0 obj
12
12
  <<
13
- /Length 278
13
+ /Length 189
14
+ /Filter /FlateDecode
14
15
  >>
15
16
  stream
16
- 0.5670000000000001 w
17
- 0 G
18
- 0.5669291338582678 w
19
- 0. G
20
- 1. g
21
- 2.2677165354330713 w
22
- 0. 0. 1. RG
23
- 27.2125984251968518 814.6774015748030706 543.1181102362205593 -775.5590551181103365 re
24
- S
25
- BT
26
- /F2 36 Tf
27
- 36. TL
28
- 0. 0. 1. rg
29
- 188.9177952755905778 410.0317322834645211 Td
30
- (This is a title) Tj
31
- ET
17
+ x�M�;N@ D{��%֟m�
32
18
  endstream
33
19
  endobj
34
20
  1 0 obj
@@ -40,16 +26,6 @@ endobj
40
26
  5 0 obj
41
27
  <<
42
28
  /Type /Font
43
- /BaseFont /Helvetica
44
- /Subtype /Type1
45
- /Encoding /WinAnsiEncoding
46
- /FirstChar 32
47
- /LastChar 255
48
- >>
49
- endobj
50
- 6 0 obj
51
- <<
52
- /Type /Font
53
29
  /BaseFont /Helvetica-Bold
54
30
  /Subtype /Type1
55
31
  /Encoding /WinAnsiEncoding
@@ -57,154 +33,23 @@ endobj
57
33
  /LastChar 255
58
34
  >>
59
35
  endobj
60
- 7 0 obj
61
- <<
62
- /Type /Font
63
- /BaseFont /Helvetica-Oblique
64
- /Subtype /Type1
65
- /Encoding /WinAnsiEncoding
66
- /FirstChar 32
67
- /LastChar 255
68
- >>
69
- endobj
70
- 8 0 obj
71
- <<
72
- /Type /Font
73
- /BaseFont /Helvetica-BoldOblique
74
- /Subtype /Type1
75
- /Encoding /WinAnsiEncoding
76
- /FirstChar 32
77
- /LastChar 255
78
- >>
79
- endobj
80
- 9 0 obj
81
- <<
82
- /Type /Font
83
- /BaseFont /Courier
84
- /Subtype /Type1
85
- /Encoding /WinAnsiEncoding
86
- /FirstChar 32
87
- /LastChar 255
88
- >>
89
- endobj
90
- 10 0 obj
91
- <<
92
- /Type /Font
93
- /BaseFont /Courier-Bold
94
- /Subtype /Type1
95
- /Encoding /WinAnsiEncoding
96
- /FirstChar 32
97
- /LastChar 255
98
- >>
99
- endobj
100
- 11 0 obj
101
- <<
102
- /Type /Font
103
- /BaseFont /Courier-Oblique
104
- /Subtype /Type1
105
- /Encoding /WinAnsiEncoding
106
- /FirstChar 32
107
- /LastChar 255
108
- >>
109
- endobj
110
- 12 0 obj
111
- <<
112
- /Type /Font
113
- /BaseFont /Courier-BoldOblique
114
- /Subtype /Type1
115
- /Encoding /WinAnsiEncoding
116
- /FirstChar 32
117
- /LastChar 255
118
- >>
119
- endobj
120
- 13 0 obj
121
- <<
122
- /Type /Font
123
- /BaseFont /Times-Roman
124
- /Subtype /Type1
125
- /Encoding /WinAnsiEncoding
126
- /FirstChar 32
127
- /LastChar 255
128
- >>
129
- endobj
130
- 14 0 obj
131
- <<
132
- /Type /Font
133
- /BaseFont /Times-Bold
134
- /Subtype /Type1
135
- /Encoding /WinAnsiEncoding
136
- /FirstChar 32
137
- /LastChar 255
138
- >>
139
- endobj
140
- 15 0 obj
141
- <<
142
- /Type /Font
143
- /BaseFont /Times-Italic
144
- /Subtype /Type1
145
- /Encoding /WinAnsiEncoding
146
- /FirstChar 32
147
- /LastChar 255
148
- >>
149
- endobj
150
- 16 0 obj
151
- <<
152
- /Type /Font
153
- /BaseFont /Times-BoldItalic
154
- /Subtype /Type1
155
- /Encoding /WinAnsiEncoding
156
- /FirstChar 32
157
- /LastChar 255
158
- >>
159
- endobj
160
- 17 0 obj
161
- <<
162
- /Type /Font
163
- /BaseFont /ZapfDingbats
164
- /Subtype /Type1
165
- /FirstChar 32
166
- /LastChar 255
167
- >>
168
- endobj
169
- 18 0 obj
170
- <<
171
- /Type /Font
172
- /BaseFont /Symbol
173
- /Subtype /Type1
174
- /FirstChar 32
175
- /LastChar 255
176
- >>
177
- endobj
178
36
  2 0 obj
179
37
  <<
180
38
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
181
39
  /Font <<
182
- /F1 5 0 R
183
- /F2 6 0 R
184
- /F3 7 0 R
185
- /F4 8 0 R
186
- /F5 9 0 R
187
- /F6 10 0 R
188
- /F7 11 0 R
189
- /F8 12 0 R
190
- /F9 13 0 R
191
- /F10 14 0 R
192
- /F11 15 0 R
193
- /F12 16 0 R
194
- /F13 17 0 R
195
- /F14 18 0 R
40
+ /F2 5 0 R
196
41
  >>
197
42
  /XObject <<
198
43
  >>
199
44
  >>
200
45
  endobj
201
- 19 0 obj
46
+ 6 0 obj
202
47
  <<
203
48
  /Producer (jsPDF 2.5.2)
204
- /CreationDate (D:20240924091503+10'00')
49
+ /CreationDate (D:20241006151126+10'00')
205
50
  >>
206
51
  endobj
207
- 20 0 obj
52
+ 7 0 obj
208
53
  <<
209
54
  /Type /Catalog
210
55
  /Pages 1 0 R
@@ -213,35 +58,22 @@ endobj
213
58
  >>
214
59
  endobj
215
60
  xref
216
- 0 21
61
+ 0 8
217
62
  0000000000 65535 f
218
- 0000000481 00000 n
219
- 0000002298 00000 n
63
+ 0000000413 00000 n
64
+ 0000000600 00000 n
220
65
  0000000015 00000 n
221
66
  0000000152 00000 n
222
- 0000000538 00000 n
223
- 0000000663 00000 n
224
- 0000000793 00000 n
225
- 0000000926 00000 n
226
- 0000001063 00000 n
227
- 0000001186 00000 n
228
- 0000001315 00000 n
229
- 0000001447 00000 n
230
- 0000001583 00000 n
231
- 0000001711 00000 n
232
- 0000001838 00000 n
233
- 0000001967 00000 n
234
- 0000002100 00000 n
235
- 0000002202 00000 n
236
- 0000002546 00000 n
237
- 0000002632 00000 n
67
+ 0000000470 00000 n
68
+ 0000000704 00000 n
69
+ 0000000789 00000 n
238
70
  trailer
239
71
  <<
240
- /Size 21
241
- /Root 20 0 R
242
- /Info 19 0 R
243
- /ID [ <BFEC21AB9E25DABE2D2409F6AA5BDFBD> <BFEC21AB9E25DABE2D2409F6AA5BDFBD> ]
72
+ /Size 8
73
+ /Root 7 0 R
74
+ /Info 6 0 R
75
+ /ID [ <A4FE96B1D9C5D34C705DDBFDD4170A74> <A4FE96B1D9C5D34C705DDBFDD4170A74> ]
244
76
  >>
245
77
  startxref
246
- 2736
78
+ 892
247
79
  %%EOF
@@ -0,0 +1,21 @@
1
+ ; Sample data. This would normally be generated by an application
2
+ .SetVar DocumentCaption INVOICE
3
+ .SetVar DocumentType Invoice
4
+ .SetVar DocumentNo A12345
5
+ .SetVar CustNo BZ1235
6
+ .SetVar CustRef 104581
7
+
8
+ .SetVar To1 Ship To
9
+ .SetVar Name1 Phoenix Auto Bits & Pieces
10
+ .SetVar Addr1Line1 777 W Chandler Blvd
11
+ .SetVar City1 Phoenix
12
+ .SetVar State1 AZ
13
+ .SetVar Zip1 85021
14
+
15
+ .SetVar To2 Charge To
16
+ .SetVar Name2 Barry's Spare Parts Group
17
+ .SetVar Addr2Line1 Level 43
18
+ .SetVar Addr2Line2 2072 41st Ave #6300
19
+ .SetVar City2 Santa Cruz
20
+ .SetVar State2 CA
21
+ .SetVar Zip2 95062
Binary file
Binary file
@@ -0,0 +1,62 @@
1
+ import { expect, it, describe } from "vitest";
2
+ import { JsPdfDynamo } from "../../src/jsPdfDynamo";
3
+ import * as allParts from "./parts.json";
4
+
5
+ describe("2.Invoice example", () => {
6
+ it("Create invoice", async () => {
7
+ const pdfDynamo = new JsPdfDynamo({
8
+ pageSize: "a4",
9
+ orientation: "portrait",
10
+ unit: "mm",
11
+ });
12
+
13
+ const formatter = new Intl.NumberFormat(undefined, {
14
+ minimumFractionDigits: 2,
15
+ });
16
+
17
+ const commands = [
18
+ // Load the template
19
+ ".include ./examples/2.Invoice/template.txt",
20
+ // Load some sample data. This would normally be generated by an application
21
+ ".include ./examples/2.Invoice/data.txt",
22
+ `.setVar docDate ${new Date().toLocaleDateString()}`,
23
+ // Create the top section of the first page
24
+ ".Do Initialise FirstPageHeader Headings",
25
+ ];
26
+
27
+ const total = addParts(commands, allParts.parts, 380, formatter);
28
+ commands.push(
29
+ `.setVar total ${formatter.format(total)}`,
30
+ ".Do Totals",
31
+ ".ForEachPage NumberPages",
32
+ );
33
+
34
+ commands.push(".SavePdf ./examples/2.Invoice/invoice.pdf");
35
+
36
+ await pdfDynamo.processCommands(commands);
37
+ expect(true).toBe(true);
38
+ });
39
+ });
40
+
41
+ function addParts(
42
+ commands: string[],
43
+ parts: any,
44
+ maxParts: number,
45
+ formatter: Intl.NumberFormat,
46
+ ): number {
47
+ let result = 0;
48
+ for (let ix = 0; ix < parts.length && ix < maxParts; ix++) {
49
+ const part = parts[ix];
50
+ commands.push(`.setVar partNo ${part.partNumber}`);
51
+ commands.push(`.setVar description ${part.description}`);
52
+ const qty = Math.floor(Math.random() * 8);
53
+ commands.push(`.setVar qty ${qty === 0 ? "On Order" : qty}`);
54
+ commands.push(`.setVar price ${formatter.format(part.price)}`);
55
+ const total = qty * part.price;
56
+ commands.push(`.setVar total ${qty === 0 ? "-" : formatter.format(total)}`);
57
+ commands.push(`.SetVar ix ${ix + 1}`);
58
+ commands.push(`.Do AddPart`);
59
+ result += total;
60
+ }
61
+ return result;
62
+ }
@@ -0,0 +1,324 @@
1
+ {
2
+ "parts": [
3
+ {
4
+ "partNumber": "AB12345A",
5
+ "description": "Air Filter - Standard",
6
+ "price": 10.99
7
+ },
8
+ {
9
+ "partNumber": "CDA87654F",
10
+ "description": "Brake Pads for Honda Ridgeline",
11
+ "price": 30.0
12
+ },
13
+ {
14
+ "partNumber": "BHG54321G",
15
+ "description": "Radiator for Nissan Titan",
16
+ "price": 100.0
17
+ },
18
+ {
19
+ "partNumber": "CC56789B",
20
+ "description": "Catalytic Converter - California",
21
+ "price": 829.1
22
+ },
23
+ {
24
+ "partNumber": "UVWXYZ123456D",
25
+ "description": "Chevrolet Silverado 3500HD Crew Cab Console Lining",
26
+ "price": 120.99
27
+ },
28
+ {
29
+ "partNumber": "ABC12345A",
30
+ "description": "Fuel Pump for Ford F-150",
31
+ "price": 120.99
32
+ },
33
+ {
34
+ "partNumber": "KMA67890B",
35
+ "description": "Air Filter for Chevrolet Silverado",
36
+ "price": 25.5
37
+ },
38
+ {
39
+ "partNumber": "XYZ90123C",
40
+ "description": "Muffler for Ram 1500",
41
+ "price": 150.0
42
+ },
43
+ {
44
+ "partNumber": "LTA34567D",
45
+ "description": "Timing Belt for Toyota Tundra",
46
+ "price": 80.99
47
+ },
48
+ {
49
+ "partNumber": "MNP98765E",
50
+ "description": "Transmission Filter for GMC Sierra",
51
+ "price": 40.5
52
+ },
53
+ {
54
+ "partNumber": "VWXYZA123456E",
55
+ "description": "Ram 2500 Laramie Trim 20-Inch Wheels",
56
+ "price": 180.99
57
+ },
58
+ {
59
+ "partNumber": "DA23456C",
60
+ "description": "Differential Assembly",
61
+ "price": 399.99
62
+ },
63
+ {
64
+ "partNumber": "EF34567D",
65
+ "description": "Engine Filter - High Performance",
66
+ "price": 14.99
67
+ },
68
+ {
69
+ "partNumber": "PQR12345H",
70
+ "description": "Wheel Bearing for Dodge Ram",
71
+ "price": 50.0
72
+ },
73
+ {
74
+ "partNumber": "VBU67890J",
75
+ "description": "Camshaft Sensor for Chevrolet Colorado",
76
+ "price": 70.5
77
+ },
78
+ {
79
+ "partNumber": "FG67890E",
80
+ "description": "Fan and Shroud",
81
+ "price": 139
82
+ },
83
+ {
84
+ "partNumber": "GH34567F",
85
+ "description": "Gearbox Gasket - Ford 9\"",
86
+ "price": 9.99
87
+ },
88
+ {
89
+ "partNumber": "HI23456G",
90
+ "description": "Headlight Assembly - Toyota Prius 2010",
91
+ "price": 144.2
92
+ },
93
+ {
94
+ "partNumber": "WXYZBC123456F",
95
+ "description": "Toyota Tundra 1794 Edition Center Console Lining",
96
+ "price": 120.99
97
+ },
98
+ {
99
+ "partNumber": "JK67890H",
100
+ "description": "Suspension Kit",
101
+ "price": 89.99
102
+ },
103
+ {
104
+ "partNumber": "KL34567I",
105
+ "description": "Cooling Fan",
106
+ "price": 24.99
107
+ },
108
+ {
109
+ "partNumber": "LMOPQR123456T",
110
+ "description": "Toyota Tacoma TRD Off-Road Wheels",
111
+ "price": 190.99
112
+ },
113
+ {
114
+ "partNumber": "WXY90123I",
115
+ "description": "Ignition Coils for Ford F-250",
116
+ "price": 60.99
117
+ },
118
+ {
119
+ "partNumber": "PQRSTU123456W",
120
+ "description": "Ram 2500 Laramie Interior Trim Kit",
121
+ "price": 120.99
122
+ },
123
+ {
124
+ "partNumber": "LM23456J",
125
+ "description": "Lever and Linkage",
126
+ "price": 29.99
127
+ },
128
+ {
129
+ "partNumber": "MN67890K",
130
+ "description": "Volvo Master Cylinder - Brake",
131
+ "price": 49.99
132
+ },
133
+ {
134
+ "partNumber": "BBCCC123456D",
135
+ "description": "Chevrolet Silverado Right Rear Brake Pads",
136
+ "price": 85.99
137
+ },
138
+ {
139
+ "partNumber": "NO34567L",
140
+ "description": "Neutral Safety Switch",
141
+ "price": 12.99
142
+ },
143
+ {
144
+ "partNumber": "TUVWXY123456C",
145
+ "description": "Ford F-250 Crew Cab 4- Way Flasher",
146
+ "price": 25.99
147
+ },
148
+ {
149
+ "partNumber": "OX23456M",
150
+ "description": "Oil Filter",
151
+ "price": 7.99
152
+ },
153
+ {
154
+ "partNumber": "PQ67890N",
155
+ "description": "Power Steering Pump",
156
+ "price": 169.3
157
+ },
158
+ {
159
+ "partNumber": "AABBCC123456",
160
+ "description": "Ford F-150 Left Front Tire",
161
+ "price": 120.99
162
+ },
163
+ {
164
+ "partNumber": "CCDDD123456A",
165
+ "description": "Ram 1500 Power Steering Pump",
166
+ "price": 156.99
167
+ },
168
+ {
169
+ "partNumber": "DDFFE123456G",
170
+ "description": "Toyota Tacoma 4- Wheel Drive Actuator",
171
+ "price": 120.99
172
+ },
173
+ {
174
+ "partNumber": "QR34567O",
175
+ "description": "Rear View Mirror",
176
+ "price": 19.99
177
+ },
178
+ {
179
+ "partNumber": "ST67890Q",
180
+ "description": "Sway Bar Link",
181
+ "price": 25.99
182
+ },
183
+ {
184
+ "partNumber": "RSWTUV123456A",
185
+ "description": "Ram 1500 Tradesman Trim Fuel Tank Skid Plate",
186
+ "price": 80.99
187
+ },
188
+ {
189
+ "partNumber": "TU34567R",
190
+ "description": "Taillight Assembly",
191
+ "price": 59.99
192
+ },
193
+ {
194
+ "partNumber": "QRSTUV123456Z",
195
+ "description": "Chevrolet Silverado 2500HD Bed Liner",
196
+ "price": 100.99
197
+ },
198
+ {
199
+ "partNumber": "STUVWX123456B",
200
+ "description": "Toyota Tacoma TRD Sport Trim Dash Trim Kit",
201
+ "price": 60.99
202
+ },
203
+ {
204
+ "partNumber": "UV67890S",
205
+ "description": "Upper Control Arm",
206
+ "price": 39.99
207
+ },
208
+ {
209
+ "partNumber": "QRSTUV123456X",
210
+ "description": "Toyota Tundra 1794 Edition Running Boards",
211
+ "price": 150.99
212
+ },
213
+ {
214
+ "partNumber": "QRSTWX123456Y",
215
+ "description": "Ford F-350 Super Duty Fender Flares",
216
+ "price": 80.99
217
+ },
218
+ {
219
+ "partNumber": "VW34567T",
220
+ "description": "Vacuum Pump",
221
+ "price": 15.99
222
+ },
223
+ {
224
+ "partNumber": "WX23456U",
225
+ "description": "Water Pump",
226
+ "price": 49.99
227
+ },
228
+ {
229
+ "partNumber": "EEFFG123456H",
230
+ "description": "Ford F-250 Crew Cab Interior Mirror",
231
+ "price": 35.99
232
+ },
233
+ {
234
+ "partNumber": "RS23456P",
235
+ "description": "Radiator Fan Shroud",
236
+ "price": 34.99
237
+ },
238
+ {
239
+ "partNumber": "FFGGH123456J",
240
+ "description": "Chevrolet Silverado 3500HD Suspension Spring",
241
+ "price": 110.99
242
+ },
243
+ {
244
+ "partNumber": "GGHIK123456L",
245
+ "description": "Ram 2500 Laramie Leveling Kit",
246
+ "price": 220.99
247
+ },
248
+ {
249
+ "partNumber": "HIJKL123456M",
250
+ "description": "Toyota Tundra 1794 Edition Tow Hitch",
251
+ "price": 150.99
252
+ },
253
+ {
254
+ "partNumber": "XY67890V",
255
+ "description": "X-Pipe Muffler",
256
+ "price": 99.99
257
+ },
258
+ {
259
+ "partNumber": "YZ34567W",
260
+ "description": "Y-Axis Gasket",
261
+ "price": 22.99
262
+ },
263
+ {
264
+ "partNumber": "JKLMN123456O",
265
+ "description": "Ford F-350 Super Duty Axle Shaft",
266
+ "price": 300.99
267
+ },
268
+ {
269
+ "partNumber": "ZA23456X",
270
+ "description": "Z-Bar Linkage",
271
+ "price": 35.99
272
+ },
273
+ {
274
+ "partNumber": "ZB67890Y",
275
+ "description": "Zip Tie",
276
+ "price": 1.99
277
+ },
278
+ {
279
+ "partNumber": "ZC34567Z",
280
+ "description": "Zerostart Battery",
281
+ "price": 129.99
282
+ },
283
+ {
284
+ "partNumber": "JKLMOP123456P",
285
+ "description": "Chevrolet Silverado 2500HD Bumper Cover",
286
+ "price": 60.99
287
+ },
288
+ {
289
+ "partNumber": "KLMOPQ123456R",
290
+ "description": "Ram 1500 Sport Trim Headlight Assembly",
291
+ "price": 80.99
292
+ },
293
+ {
294
+ "partNumber": "AA12345A",
295
+ "description": "Air Filter Assembly",
296
+ "price": 49.99
297
+ },
298
+ {
299
+ "partNumber": "BB56789B",
300
+ "description": "Battery Box",
301
+ "price": 29.99
302
+ },
303
+ {
304
+ "partNumber": "MOPQRT123456U",
305
+ "description": "Ford F-250 XL Crew Cab Seats",
306
+ "price": 120.99
307
+ },
308
+ {
309
+ "partNumber": "OPQRST123456V",
310
+ "description": "Chevrolet Silverado 2500HD Transfer Case",
311
+ "price": 280.99
312
+ },
313
+ {
314
+ "partNumber": "CC23456C",
315
+ "description": "Cooling Fan Shroud",
316
+ "price": 19.99
317
+ },
318
+ {
319
+ "partNumber": "DD34567D",
320
+ "description": "Dash Panel",
321
+ "price": 39.99
322
+ }
323
+ ]
324
+ }