jspdf-dynamo 1.0.5 → 1.0.6
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 +3 -3
- package/dist/index.cjs +80 -33
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +80 -33
- package/documentation/1. Introduction/Introduction.txt +1 -1
- package/documentation/3. Variables/Introduction.txt +13 -12
- package/documentation/3. Variables/SystemMaintained.txt +40 -0
- package/documentation/4. Commands/DrawTextWrapped.txt +1 -1
- package/documentation/4. Commands/IfBlank.txt +1 -1
- package/documentation/4. Commands/IfNotBlank.txt +1 -1
- package/documentation/4. Commands/LoadImageFromFile.txt +2 -2
- package/documentation/4. Commands/LoadImageFromUrl.txt +2 -2
- package/documentation/4. Commands/SetFillColour.txt +4 -2
- package/documentation/4. Commands/SetFontName.txt +80 -1
- package/documentation/4. Commands/SetFontSize.txt +43 -1
- package/documentation/4. Commands/SetFontStyle.txt +4 -5
- package/documentation/4. Commands/SetLineColour.txt +5 -2
- package/documentation/4. Commands/SetTextColour.txt +4 -2
- package/documentation/5. Other Definitions/pageSizes.txt +3 -3
- package/documentation/Documentation.pdf +0 -0
- package/examples/1.Simple/simple.pdf +18 -186
- package/examples/2.Invoice/data.txt +21 -0
- package/examples/2.Invoice/gearz.png +0 -0
- package/examples/2.Invoice/invoice.pdf +0 -0
- package/examples/2.Invoice/invoice.spec.ts +62 -0
- package/examples/2.Invoice/parts.json +324 -0
- package/examples/2.Invoice/template.txt +136 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ jsPdf-Dynamo is a wrapper around the open-source JavaScript PDF generation libra
|
|
|
4
4
|
template driven approach, it enables the separation of layout and formatting logic from the placement of
|
|
5
5
|
data.
|
|
6
6
|
|
|
7
|
-
jsPdf-Dynamo can be used with browser or NodeJs JavaScript or TypeScript
|
|
7
|
+
jsPdf-Dynamo can be used with browser or NodeJs applications written in JavaScript or TypeScript.
|
|
8
8
|
|
|
9
9
|
Advantages of using jsPdf-Dynamo include:
|
|
10
10
|
|
|
@@ -31,8 +31,8 @@ yarn add jspdf
|
|
|
31
31
|
There are a few basic concepts to be aware of when using jsPdf-Dynamo:
|
|
32
32
|
|
|
33
33
|
- The functionality of jsPdf-Dynamo is implemented through the JsPdfDynamo class.
|
|
34
|
-
- The initial page size, orientation and
|
|
35
|
-
- Output is driven by a series of plain text 'commands'. These commands can be provided as a list of strings from multiple sources, including the JavaScript or TypeScript application, or loaded from 'templates' retrieved from a URL (browser
|
|
34
|
+
- The initial page size, orientation and unit of measure are set when the JsPdfDynamo instance is instantiated.
|
|
35
|
+
- Output is driven by a series of plain text 'commands'. These commands can be provided as a list of strings from multiple sources, including the JavaScript or TypeScript application, or loaded from 'templates' retrieved from a URL (browser only) or from local text files (NodeJs only).
|
|
36
36
|
- Positions are specified relative to the left and top margin. The exception to this are margins which are measured from the appropriate edge of the page.
|
|
37
37
|
- All measurements and positions are in the unit of measure specified when the instance
|
|
38
38
|
of JsPdfDynamo is created. This can be millimeters, inches, or points. The exception to this are fonts, which are always specified in points.
|
package/dist/index.cjs
CHANGED
|
@@ -75,19 +75,19 @@ var AppLogger = class {
|
|
|
75
75
|
this._logger = console;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
trace(message,
|
|
78
|
+
trace(message, args) {
|
|
79
79
|
this.canLog(0) ? this._logger.trace(message, args) : null;
|
|
80
80
|
}
|
|
81
|
-
debug(message,
|
|
81
|
+
debug(message, args) {
|
|
82
82
|
this.canLog(1) ? this._logger.debug(message, args) : null;
|
|
83
83
|
}
|
|
84
|
-
info(message,
|
|
84
|
+
info(message, args) {
|
|
85
85
|
this.canLog(2) ? this._logger.info(message, args) : null;
|
|
86
86
|
}
|
|
87
|
-
warn(message,
|
|
87
|
+
warn(message, args) {
|
|
88
88
|
this.canLog(3) ? this._logger.warn(message, args) : null;
|
|
89
89
|
}
|
|
90
|
-
error(message,
|
|
90
|
+
error(message, args) {
|
|
91
91
|
this.canLog(4) ? this._logger.error(message, args) : null;
|
|
92
92
|
}
|
|
93
93
|
logLevel(newLevel) {
|
|
@@ -264,6 +264,8 @@ function isValidFontStyle(fontStyle) {
|
|
|
264
264
|
// src/models/jsPdfOptions.ts
|
|
265
265
|
var JsPdfOptions = class {
|
|
266
266
|
constructor(options = {}) {
|
|
267
|
+
this.compress = true;
|
|
268
|
+
this.putOnlyUsedFonts = true;
|
|
267
269
|
var _a, _b, _c;
|
|
268
270
|
this.pageSize = ((_a = options.pageSize) == null ? void 0 : _a.toLocaleLowerCase()) || "a4";
|
|
269
271
|
this.orientation = ((_b = options.orientation) == null ? void 0 : _b.toLocaleLowerCase()) || "portrait";
|
|
@@ -343,15 +345,32 @@ var JsPdfProcessor = class {
|
|
|
343
345
|
this.pageOrientation = optn.orientation;
|
|
344
346
|
this.currentUom = optn.unit;
|
|
345
347
|
this._pdfDocument.setLineHeightFactor(1);
|
|
348
|
+
const now = /* @__PURE__ */ new Date();
|
|
346
349
|
this._variables.set(
|
|
347
350
|
"_TIMEHM",
|
|
348
|
-
|
|
351
|
+
now.toLocaleTimeString(void 0, {
|
|
349
352
|
hour12: false,
|
|
350
353
|
hour: "2-digit",
|
|
351
354
|
minute: "2-digit"
|
|
352
355
|
})
|
|
353
356
|
);
|
|
354
|
-
this._variables.set(
|
|
357
|
+
this._variables.set(
|
|
358
|
+
"_DATEDDMMYYYY",
|
|
359
|
+
now.toLocaleDateString("en-GB", {
|
|
360
|
+
day: "2-digit",
|
|
361
|
+
month: "2-digit",
|
|
362
|
+
year: "numeric"
|
|
363
|
+
})
|
|
364
|
+
);
|
|
365
|
+
this._variables.set(
|
|
366
|
+
"_DATEMMDDYYYY",
|
|
367
|
+
now.toLocaleDateString("en-US", {
|
|
368
|
+
day: "2-digit",
|
|
369
|
+
month: "2-digit",
|
|
370
|
+
year: "numeric"
|
|
371
|
+
})
|
|
372
|
+
);
|
|
373
|
+
this._variables.set("_DATEISO", now.toISOString().substring(0, 10));
|
|
355
374
|
this._variables.set("_IMAGEASPECT", "1");
|
|
356
375
|
this._variables.set("_IMAGEHEIGHT", "0");
|
|
357
376
|
this._variables.set("_IMAGEHEIGHTPX", "0");
|
|
@@ -855,6 +874,8 @@ var JsPdfProcessor = class {
|
|
|
855
874
|
const subs = this.logAndParseCommand(".drawDebugGrid", input);
|
|
856
875
|
const savedLineColour = this.lineColour;
|
|
857
876
|
const savedLineWidth = this.lineWidth;
|
|
877
|
+
const savedX = this.posnX;
|
|
878
|
+
const savedY = this.posnY;
|
|
858
879
|
const mm = 0.1;
|
|
859
880
|
const pts = mmToPoints(mm);
|
|
860
881
|
const lineWidth = this.pointsToUom(pts);
|
|
@@ -911,6 +932,8 @@ var JsPdfProcessor = class {
|
|
|
911
932
|
}
|
|
912
933
|
this.lineColour = savedLineColour;
|
|
913
934
|
this.lineWidth = savedLineWidth;
|
|
935
|
+
this.posnX = savedX;
|
|
936
|
+
this.posnY = savedY;
|
|
914
937
|
}
|
|
915
938
|
drawLine(input) {
|
|
916
939
|
const subs = this.logAndParseCommand(".drawLine", input);
|
|
@@ -950,7 +973,7 @@ var JsPdfProcessor = class {
|
|
|
950
973
|
return;
|
|
951
974
|
}
|
|
952
975
|
if (isNaN(imageNo) || imageNo < 0 || imageNo > this._images.length - 1) {
|
|
953
|
-
this.lastError = this._images.length ?
|
|
976
|
+
this.lastError = this._images.length > 1 ? `The image number ${imageNo} must be in the range of 0 to ${(this._images.length - 1).toString()}` : "Only one image has been loaded, the image number can only be 0";
|
|
954
977
|
this.lastResult = "0";
|
|
955
978
|
return;
|
|
956
979
|
}
|
|
@@ -1001,7 +1024,6 @@ var JsPdfProcessor = class {
|
|
|
1001
1024
|
this.lastResult = "1";
|
|
1002
1025
|
}
|
|
1003
1026
|
drawText(input) {
|
|
1004
|
-
var _a;
|
|
1005
1027
|
const subs = this.logAndParseCommand(".drawText", input);
|
|
1006
1028
|
const { first: left, rest: rest1 } = getNextNumber(subs);
|
|
1007
1029
|
const { first: top, rest: rest2 } = getNextNumber(rest1);
|
|
@@ -1013,7 +1035,7 @@ var JsPdfProcessor = class {
|
|
|
1013
1035
|
this.lastObjectWidth = 0;
|
|
1014
1036
|
this.lastResult = "1";
|
|
1015
1037
|
if (lines.length > 1) {
|
|
1016
|
-
this.lastError = `Text was truncated to fit within the available width (${
|
|
1038
|
+
this.lastError = `Text was truncated to fit within the available width (${rest2.substring(0, 20)}...) on page ${this._currentPageNumber}.`;
|
|
1017
1039
|
this.lastResult = "0";
|
|
1018
1040
|
if (lines[0]) {
|
|
1019
1041
|
if (this._pdfDocument.getTextWidth(lines[0]) < maxWidth) {
|
|
@@ -1319,10 +1341,11 @@ var JsPdfProcessor = class {
|
|
|
1319
1341
|
}
|
|
1320
1342
|
ifNotBlank(jsPdfDynamo, input) {
|
|
1321
1343
|
return __async(this, null, function* () {
|
|
1322
|
-
let { first:
|
|
1344
|
+
let { first: value1, rest } = getNextString(input);
|
|
1323
1345
|
const subs = this.substitute(rest.trim());
|
|
1324
|
-
this._logger.debug(".ifNotBlank " +
|
|
1325
|
-
|
|
1346
|
+
this._logger.debug(".ifNotBlank " + value1 + " " + subs);
|
|
1347
|
+
const variable1 = this.substitute(value1);
|
|
1348
|
+
let value = this._variables.get(variable1.toLocaleUpperCase()) || "";
|
|
1326
1349
|
this.lastResult = "-1";
|
|
1327
1350
|
if (value.trim() !== "") {
|
|
1328
1351
|
yield jsPdfDynamo.processDot(this, rest);
|
|
@@ -1576,9 +1599,14 @@ var JsPdfProcessor = class {
|
|
|
1576
1599
|
}
|
|
1577
1600
|
}
|
|
1578
1601
|
setFillColour(input) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1602
|
+
const subs = this.logAndParseCommand(".setFillColour", input);
|
|
1603
|
+
const { first: fillColour } = getNextString(subs);
|
|
1604
|
+
if (fillColour === "") {
|
|
1605
|
+
this.lastResult = "0";
|
|
1606
|
+
this.lastError = "A fill colour must be specified";
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
this.fillColour = fillColour;
|
|
1582
1610
|
this.lastResult = "1";
|
|
1583
1611
|
}
|
|
1584
1612
|
setFontName(input) {
|
|
@@ -1594,14 +1622,25 @@ var JsPdfProcessor = class {
|
|
|
1594
1622
|
}
|
|
1595
1623
|
setFontSize(input) {
|
|
1596
1624
|
const subs = this.logAndParseCommand(".setFontSize", input);
|
|
1597
|
-
|
|
1598
|
-
if (size > 0) {
|
|
1599
|
-
this.fontPointSize = size;
|
|
1600
|
-
this.lastResult = "1";
|
|
1601
|
-
} else {
|
|
1625
|
+
if (subs === "") {
|
|
1602
1626
|
this.lastResult = "0";
|
|
1603
|
-
this.lastError = "
|
|
1627
|
+
this.lastError = "A font size must be specified";
|
|
1628
|
+
return;
|
|
1604
1629
|
}
|
|
1630
|
+
let { first: sizeAlpha } = getNextNumber(subs);
|
|
1631
|
+
const size = Number(sizeAlpha);
|
|
1632
|
+
if (Number.isNaN(size)) {
|
|
1633
|
+
this.lastResult = "0";
|
|
1634
|
+
this.lastError = `A font size must be a number. '${sizeAlpha}' is not a number.`;
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
if (size <= 0) {
|
|
1638
|
+
this.lastResult = "0";
|
|
1639
|
+
this.lastError = "A font size must be greater than 0";
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
this.fontPointSize = size;
|
|
1643
|
+
this.lastResult = "1";
|
|
1605
1644
|
}
|
|
1606
1645
|
setFontStyle(input) {
|
|
1607
1646
|
const subs = this.logAndParseCommand(".setFontStyle", input);
|
|
@@ -1620,9 +1659,14 @@ var JsPdfProcessor = class {
|
|
|
1620
1659
|
this.lastResult = "1";
|
|
1621
1660
|
}
|
|
1622
1661
|
setLineColour(input) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1662
|
+
const subs = this.logAndParseCommand(".setFontStyle", input);
|
|
1663
|
+
const { first: lineColour } = getNextString(subs);
|
|
1664
|
+
if (lineColour === "") {
|
|
1665
|
+
this.lastResult = "0";
|
|
1666
|
+
this.lastError = "A line colour must be specified";
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
this.lineColour = lineColour;
|
|
1626
1670
|
this.lastResult = "1";
|
|
1627
1671
|
}
|
|
1628
1672
|
setLineWidth(input) {
|
|
@@ -1728,7 +1772,13 @@ var JsPdfProcessor = class {
|
|
|
1728
1772
|
}
|
|
1729
1773
|
setTextColour(input) {
|
|
1730
1774
|
const subs = this.logAndParseCommand(".setTextColour", input);
|
|
1731
|
-
|
|
1775
|
+
const { first: textColour } = getNextString(subs);
|
|
1776
|
+
if (textColour === "") {
|
|
1777
|
+
this.lastResult = "0";
|
|
1778
|
+
this.lastError = "A text colour must be specified";
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
this.textColour = textColour;
|
|
1732
1782
|
this.lastResult = "1";
|
|
1733
1783
|
}
|
|
1734
1784
|
copyVar(input) {
|
|
@@ -1942,10 +1992,6 @@ var JsPdfDynamo = class {
|
|
|
1942
1992
|
if (currLine.startsWith("[")) {
|
|
1943
1993
|
if (inGroupLoading) {
|
|
1944
1994
|
inGroupLoading = false;
|
|
1945
|
-
__privateGet(this, _appLogger).debug(
|
|
1946
|
-
`Finished loading group ${grpName} (${currLine})
|
|
1947
|
-
`
|
|
1948
|
-
);
|
|
1949
1995
|
} else {
|
|
1950
1996
|
if (currLine.length === 1) continue;
|
|
1951
1997
|
grpName = currLine.substring(1);
|
|
@@ -1955,8 +2001,7 @@ var JsPdfDynamo = class {
|
|
|
1955
2001
|
}
|
|
1956
2002
|
grpName = grpName.trim().toLocaleUpperCase();
|
|
1957
2003
|
inGroupLoading = true;
|
|
1958
|
-
__privateGet(this, _appLogger).debug(`Loading group ${grpName}
|
|
1959
|
-
`);
|
|
2004
|
+
__privateGet(this, _appLogger).debug(`Loading group ${grpName}`);
|
|
1960
2005
|
currGroup = [];
|
|
1961
2006
|
__privateGet(this, _groups)[grpName] = currGroup;
|
|
1962
2007
|
}
|
|
@@ -2140,9 +2185,11 @@ var JsPdfDynamo = class {
|
|
|
2140
2185
|
let { first: group, rest } = getNextString(subs);
|
|
2141
2186
|
subs = rest;
|
|
2142
2187
|
__privateGet(this, _appLogger).debug(`
|
|
2143
|
-
[${group}]`);
|
|
2188
|
+
[${group} - Enter]`);
|
|
2144
2189
|
if (__privateGet(this, _groups)[group]) {
|
|
2145
2190
|
yield this.processTemplate(processor, __privateGet(this, _groups)[group]);
|
|
2191
|
+
__privateGet(this, _appLogger).debug(`[${group} - Exit]
|
|
2192
|
+
`);
|
|
2146
2193
|
} else {
|
|
2147
2194
|
__privateGet(this, _appLogger).warn(`Group ${group} was not found.`);
|
|
2148
2195
|
processor.lastResult = "0";
|
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import jsPDF from 'jspdf';
|
|
2
2
|
|
|
3
3
|
interface ILogger {
|
|
4
|
-
debug: (message: string,
|
|
5
|
-
error: (message: string,
|
|
6
|
-
info: (message: string,
|
|
7
|
-
trace: (message: string,
|
|
8
|
-
warn: (message: string,
|
|
4
|
+
debug: (message: string, args?: any) => void;
|
|
5
|
+
error: (message: string, args?: any) => void;
|
|
6
|
+
info: (message: string, args?: any) => void;
|
|
7
|
+
trace: (message: string, args?: any) => void;
|
|
8
|
+
warn: (message: string, args?: any) => void;
|
|
9
9
|
}
|
|
10
10
|
declare class AppLogger implements ILogger {
|
|
11
11
|
private _logLevel;
|
|
12
12
|
private _logger;
|
|
13
13
|
constructor(logger?: ILogger | null);
|
|
14
|
-
trace(message: string,
|
|
15
|
-
debug(message: string,
|
|
16
|
-
info(message: string,
|
|
17
|
-
warn(message: string,
|
|
18
|
-
error(message: string,
|
|
14
|
+
trace(message: string, args?: any): void;
|
|
15
|
+
debug(message: string, args?: any): void;
|
|
16
|
+
info(message: string, args?: any): void;
|
|
17
|
+
warn(message: string, args?: any): void;
|
|
18
|
+
error(message: string, args?: any): void;
|
|
19
19
|
logLevel(newLevel: string | number): void;
|
|
20
20
|
private canLog;
|
|
21
21
|
}
|
|
@@ -193,6 +193,7 @@ declare const pageSizes: {
|
|
|
193
193
|
type pageSizeType = keyof typeof pageSizes;
|
|
194
194
|
|
|
195
195
|
interface IJsPdfOptions {
|
|
196
|
+
compress: boolean;
|
|
196
197
|
margins: {
|
|
197
198
|
top: number;
|
|
198
199
|
bottom: number;
|
|
@@ -200,6 +201,7 @@ interface IJsPdfOptions {
|
|
|
200
201
|
right: number;
|
|
201
202
|
};
|
|
202
203
|
pageSize: pageSizeType;
|
|
204
|
+
putOnlyUsedFonts: boolean;
|
|
203
205
|
orientation: "portrait" | "landscape" | "p" | "l";
|
|
204
206
|
unit: "mm" | "in" | "pt";
|
|
205
207
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import jsPDF from 'jspdf';
|
|
2
2
|
|
|
3
3
|
interface ILogger {
|
|
4
|
-
debug: (message: string,
|
|
5
|
-
error: (message: string,
|
|
6
|
-
info: (message: string,
|
|
7
|
-
trace: (message: string,
|
|
8
|
-
warn: (message: string,
|
|
4
|
+
debug: (message: string, args?: any) => void;
|
|
5
|
+
error: (message: string, args?: any) => void;
|
|
6
|
+
info: (message: string, args?: any) => void;
|
|
7
|
+
trace: (message: string, args?: any) => void;
|
|
8
|
+
warn: (message: string, args?: any) => void;
|
|
9
9
|
}
|
|
10
10
|
declare class AppLogger implements ILogger {
|
|
11
11
|
private _logLevel;
|
|
12
12
|
private _logger;
|
|
13
13
|
constructor(logger?: ILogger | null);
|
|
14
|
-
trace(message: string,
|
|
15
|
-
debug(message: string,
|
|
16
|
-
info(message: string,
|
|
17
|
-
warn(message: string,
|
|
18
|
-
error(message: string,
|
|
14
|
+
trace(message: string, args?: any): void;
|
|
15
|
+
debug(message: string, args?: any): void;
|
|
16
|
+
info(message: string, args?: any): void;
|
|
17
|
+
warn(message: string, args?: any): void;
|
|
18
|
+
error(message: string, args?: any): void;
|
|
19
19
|
logLevel(newLevel: string | number): void;
|
|
20
20
|
private canLog;
|
|
21
21
|
}
|
|
@@ -193,6 +193,7 @@ declare const pageSizes: {
|
|
|
193
193
|
type pageSizeType = keyof typeof pageSizes;
|
|
194
194
|
|
|
195
195
|
interface IJsPdfOptions {
|
|
196
|
+
compress: boolean;
|
|
196
197
|
margins: {
|
|
197
198
|
top: number;
|
|
198
199
|
bottom: number;
|
|
@@ -200,6 +201,7 @@ interface IJsPdfOptions {
|
|
|
200
201
|
right: number;
|
|
201
202
|
};
|
|
202
203
|
pageSize: pageSizeType;
|
|
204
|
+
putOnlyUsedFonts: boolean;
|
|
203
205
|
orientation: "portrait" | "landscape" | "p" | "l";
|
|
204
206
|
unit: "mm" | "in" | "pt";
|
|
205
207
|
}
|
package/dist/index.js
CHANGED
|
@@ -46,19 +46,19 @@ var AppLogger = class {
|
|
|
46
46
|
this._logger = console;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
trace(message,
|
|
49
|
+
trace(message, args) {
|
|
50
50
|
this.canLog(0) ? this._logger.trace(message, args) : null;
|
|
51
51
|
}
|
|
52
|
-
debug(message,
|
|
52
|
+
debug(message, args) {
|
|
53
53
|
this.canLog(1) ? this._logger.debug(message, args) : null;
|
|
54
54
|
}
|
|
55
|
-
info(message,
|
|
55
|
+
info(message, args) {
|
|
56
56
|
this.canLog(2) ? this._logger.info(message, args) : null;
|
|
57
57
|
}
|
|
58
|
-
warn(message,
|
|
58
|
+
warn(message, args) {
|
|
59
59
|
this.canLog(3) ? this._logger.warn(message, args) : null;
|
|
60
60
|
}
|
|
61
|
-
error(message,
|
|
61
|
+
error(message, args) {
|
|
62
62
|
this.canLog(4) ? this._logger.error(message, args) : null;
|
|
63
63
|
}
|
|
64
64
|
logLevel(newLevel) {
|
|
@@ -235,6 +235,8 @@ function isValidFontStyle(fontStyle) {
|
|
|
235
235
|
// src/models/jsPdfOptions.ts
|
|
236
236
|
var JsPdfOptions = class {
|
|
237
237
|
constructor(options = {}) {
|
|
238
|
+
this.compress = true;
|
|
239
|
+
this.putOnlyUsedFonts = true;
|
|
238
240
|
var _a, _b, _c;
|
|
239
241
|
this.pageSize = ((_a = options.pageSize) == null ? void 0 : _a.toLocaleLowerCase()) || "a4";
|
|
240
242
|
this.orientation = ((_b = options.orientation) == null ? void 0 : _b.toLocaleLowerCase()) || "portrait";
|
|
@@ -314,15 +316,32 @@ var JsPdfProcessor = class {
|
|
|
314
316
|
this.pageOrientation = optn.orientation;
|
|
315
317
|
this.currentUom = optn.unit;
|
|
316
318
|
this._pdfDocument.setLineHeightFactor(1);
|
|
319
|
+
const now = /* @__PURE__ */ new Date();
|
|
317
320
|
this._variables.set(
|
|
318
321
|
"_TIMEHM",
|
|
319
|
-
|
|
322
|
+
now.toLocaleTimeString(void 0, {
|
|
320
323
|
hour12: false,
|
|
321
324
|
hour: "2-digit",
|
|
322
325
|
minute: "2-digit"
|
|
323
326
|
})
|
|
324
327
|
);
|
|
325
|
-
this._variables.set(
|
|
328
|
+
this._variables.set(
|
|
329
|
+
"_DATEDDMMYYYY",
|
|
330
|
+
now.toLocaleDateString("en-GB", {
|
|
331
|
+
day: "2-digit",
|
|
332
|
+
month: "2-digit",
|
|
333
|
+
year: "numeric"
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
this._variables.set(
|
|
337
|
+
"_DATEMMDDYYYY",
|
|
338
|
+
now.toLocaleDateString("en-US", {
|
|
339
|
+
day: "2-digit",
|
|
340
|
+
month: "2-digit",
|
|
341
|
+
year: "numeric"
|
|
342
|
+
})
|
|
343
|
+
);
|
|
344
|
+
this._variables.set("_DATEISO", now.toISOString().substring(0, 10));
|
|
326
345
|
this._variables.set("_IMAGEASPECT", "1");
|
|
327
346
|
this._variables.set("_IMAGEHEIGHT", "0");
|
|
328
347
|
this._variables.set("_IMAGEHEIGHTPX", "0");
|
|
@@ -826,6 +845,8 @@ var JsPdfProcessor = class {
|
|
|
826
845
|
const subs = this.logAndParseCommand(".drawDebugGrid", input);
|
|
827
846
|
const savedLineColour = this.lineColour;
|
|
828
847
|
const savedLineWidth = this.lineWidth;
|
|
848
|
+
const savedX = this.posnX;
|
|
849
|
+
const savedY = this.posnY;
|
|
829
850
|
const mm = 0.1;
|
|
830
851
|
const pts = mmToPoints(mm);
|
|
831
852
|
const lineWidth = this.pointsToUom(pts);
|
|
@@ -882,6 +903,8 @@ var JsPdfProcessor = class {
|
|
|
882
903
|
}
|
|
883
904
|
this.lineColour = savedLineColour;
|
|
884
905
|
this.lineWidth = savedLineWidth;
|
|
906
|
+
this.posnX = savedX;
|
|
907
|
+
this.posnY = savedY;
|
|
885
908
|
}
|
|
886
909
|
drawLine(input) {
|
|
887
910
|
const subs = this.logAndParseCommand(".drawLine", input);
|
|
@@ -921,7 +944,7 @@ var JsPdfProcessor = class {
|
|
|
921
944
|
return;
|
|
922
945
|
}
|
|
923
946
|
if (isNaN(imageNo) || imageNo < 0 || imageNo > this._images.length - 1) {
|
|
924
|
-
this.lastError = this._images.length ?
|
|
947
|
+
this.lastError = this._images.length > 1 ? `The image number ${imageNo} must be in the range of 0 to ${(this._images.length - 1).toString()}` : "Only one image has been loaded, the image number can only be 0";
|
|
925
948
|
this.lastResult = "0";
|
|
926
949
|
return;
|
|
927
950
|
}
|
|
@@ -972,7 +995,6 @@ var JsPdfProcessor = class {
|
|
|
972
995
|
this.lastResult = "1";
|
|
973
996
|
}
|
|
974
997
|
drawText(input) {
|
|
975
|
-
var _a;
|
|
976
998
|
const subs = this.logAndParseCommand(".drawText", input);
|
|
977
999
|
const { first: left, rest: rest1 } = getNextNumber(subs);
|
|
978
1000
|
const { first: top, rest: rest2 } = getNextNumber(rest1);
|
|
@@ -984,7 +1006,7 @@ var JsPdfProcessor = class {
|
|
|
984
1006
|
this.lastObjectWidth = 0;
|
|
985
1007
|
this.lastResult = "1";
|
|
986
1008
|
if (lines.length > 1) {
|
|
987
|
-
this.lastError = `Text was truncated to fit within the available width (${
|
|
1009
|
+
this.lastError = `Text was truncated to fit within the available width (${rest2.substring(0, 20)}...) on page ${this._currentPageNumber}.`;
|
|
988
1010
|
this.lastResult = "0";
|
|
989
1011
|
if (lines[0]) {
|
|
990
1012
|
if (this._pdfDocument.getTextWidth(lines[0]) < maxWidth) {
|
|
@@ -1290,10 +1312,11 @@ var JsPdfProcessor = class {
|
|
|
1290
1312
|
}
|
|
1291
1313
|
ifNotBlank(jsPdfDynamo, input) {
|
|
1292
1314
|
return __async(this, null, function* () {
|
|
1293
|
-
let { first:
|
|
1315
|
+
let { first: value1, rest } = getNextString(input);
|
|
1294
1316
|
const subs = this.substitute(rest.trim());
|
|
1295
|
-
this._logger.debug(".ifNotBlank " +
|
|
1296
|
-
|
|
1317
|
+
this._logger.debug(".ifNotBlank " + value1 + " " + subs);
|
|
1318
|
+
const variable1 = this.substitute(value1);
|
|
1319
|
+
let value = this._variables.get(variable1.toLocaleUpperCase()) || "";
|
|
1297
1320
|
this.lastResult = "-1";
|
|
1298
1321
|
if (value.trim() !== "") {
|
|
1299
1322
|
yield jsPdfDynamo.processDot(this, rest);
|
|
@@ -1547,9 +1570,14 @@ var JsPdfProcessor = class {
|
|
|
1547
1570
|
}
|
|
1548
1571
|
}
|
|
1549
1572
|
setFillColour(input) {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1573
|
+
const subs = this.logAndParseCommand(".setFillColour", input);
|
|
1574
|
+
const { first: fillColour } = getNextString(subs);
|
|
1575
|
+
if (fillColour === "") {
|
|
1576
|
+
this.lastResult = "0";
|
|
1577
|
+
this.lastError = "A fill colour must be specified";
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
this.fillColour = fillColour;
|
|
1553
1581
|
this.lastResult = "1";
|
|
1554
1582
|
}
|
|
1555
1583
|
setFontName(input) {
|
|
@@ -1565,14 +1593,25 @@ var JsPdfProcessor = class {
|
|
|
1565
1593
|
}
|
|
1566
1594
|
setFontSize(input) {
|
|
1567
1595
|
const subs = this.logAndParseCommand(".setFontSize", input);
|
|
1568
|
-
|
|
1569
|
-
if (size > 0) {
|
|
1570
|
-
this.fontPointSize = size;
|
|
1571
|
-
this.lastResult = "1";
|
|
1572
|
-
} else {
|
|
1596
|
+
if (subs === "") {
|
|
1573
1597
|
this.lastResult = "0";
|
|
1574
|
-
this.lastError = "
|
|
1598
|
+
this.lastError = "A font size must be specified";
|
|
1599
|
+
return;
|
|
1575
1600
|
}
|
|
1601
|
+
let { first: sizeAlpha } = getNextNumber(subs);
|
|
1602
|
+
const size = Number(sizeAlpha);
|
|
1603
|
+
if (Number.isNaN(size)) {
|
|
1604
|
+
this.lastResult = "0";
|
|
1605
|
+
this.lastError = `A font size must be a number. '${sizeAlpha}' is not a number.`;
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
if (size <= 0) {
|
|
1609
|
+
this.lastResult = "0";
|
|
1610
|
+
this.lastError = "A font size must be greater than 0";
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
this.fontPointSize = size;
|
|
1614
|
+
this.lastResult = "1";
|
|
1576
1615
|
}
|
|
1577
1616
|
setFontStyle(input) {
|
|
1578
1617
|
const subs = this.logAndParseCommand(".setFontStyle", input);
|
|
@@ -1591,9 +1630,14 @@ var JsPdfProcessor = class {
|
|
|
1591
1630
|
this.lastResult = "1";
|
|
1592
1631
|
}
|
|
1593
1632
|
setLineColour(input) {
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1633
|
+
const subs = this.logAndParseCommand(".setFontStyle", input);
|
|
1634
|
+
const { first: lineColour } = getNextString(subs);
|
|
1635
|
+
if (lineColour === "") {
|
|
1636
|
+
this.lastResult = "0";
|
|
1637
|
+
this.lastError = "A line colour must be specified";
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
this.lineColour = lineColour;
|
|
1597
1641
|
this.lastResult = "1";
|
|
1598
1642
|
}
|
|
1599
1643
|
setLineWidth(input) {
|
|
@@ -1699,7 +1743,13 @@ var JsPdfProcessor = class {
|
|
|
1699
1743
|
}
|
|
1700
1744
|
setTextColour(input) {
|
|
1701
1745
|
const subs = this.logAndParseCommand(".setTextColour", input);
|
|
1702
|
-
|
|
1746
|
+
const { first: textColour } = getNextString(subs);
|
|
1747
|
+
if (textColour === "") {
|
|
1748
|
+
this.lastResult = "0";
|
|
1749
|
+
this.lastError = "A text colour must be specified";
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
this.textColour = textColour;
|
|
1703
1753
|
this.lastResult = "1";
|
|
1704
1754
|
}
|
|
1705
1755
|
copyVar(input) {
|
|
@@ -1913,10 +1963,6 @@ var JsPdfDynamo = class {
|
|
|
1913
1963
|
if (currLine.startsWith("[")) {
|
|
1914
1964
|
if (inGroupLoading) {
|
|
1915
1965
|
inGroupLoading = false;
|
|
1916
|
-
__privateGet(this, _appLogger).debug(
|
|
1917
|
-
`Finished loading group ${grpName} (${currLine})
|
|
1918
|
-
`
|
|
1919
|
-
);
|
|
1920
1966
|
} else {
|
|
1921
1967
|
if (currLine.length === 1) continue;
|
|
1922
1968
|
grpName = currLine.substring(1);
|
|
@@ -1926,8 +1972,7 @@ var JsPdfDynamo = class {
|
|
|
1926
1972
|
}
|
|
1927
1973
|
grpName = grpName.trim().toLocaleUpperCase();
|
|
1928
1974
|
inGroupLoading = true;
|
|
1929
|
-
__privateGet(this, _appLogger).debug(`Loading group ${grpName}
|
|
1930
|
-
`);
|
|
1975
|
+
__privateGet(this, _appLogger).debug(`Loading group ${grpName}`);
|
|
1931
1976
|
currGroup = [];
|
|
1932
1977
|
__privateGet(this, _groups)[grpName] = currGroup;
|
|
1933
1978
|
}
|
|
@@ -2111,9 +2156,11 @@ var JsPdfDynamo = class {
|
|
|
2111
2156
|
let { first: group, rest } = getNextString(subs);
|
|
2112
2157
|
subs = rest;
|
|
2113
2158
|
__privateGet(this, _appLogger).debug(`
|
|
2114
|
-
[${group}]`);
|
|
2159
|
+
[${group} - Enter]`);
|
|
2115
2160
|
if (__privateGet(this, _groups)[group]) {
|
|
2116
2161
|
yield this.processTemplate(processor, __privateGet(this, _groups)[group]);
|
|
2162
|
+
__privateGet(this, _appLogger).debug(`[${group} - Exit]
|
|
2163
|
+
`);
|
|
2117
2164
|
} else {
|
|
2118
2165
|
__privateGet(this, _appLogger).warn(`Group ${group} was not found.`);
|
|
2119
2166
|
processor.lastResult = "0";
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
|
|
43
43
|
.SetVar top %_CurrentY%
|
|
44
44
|
.DrawText 5 %top% -
|
|
45
|
-
.SetVar text The initial page size, orientation and
|
|
45
|
+
.SetVar text The initial page size, orientation and unit of measure are set when the
|
|
46
46
|
.SetVar text %text% JsPdfDynamo instance is instantiated.
|
|
47
47
|
.DrawTextWrapped 10 %top% %width% *None %text%
|
|
48
48
|
|
|
@@ -10,30 +10,31 @@
|
|
|
10
10
|
.incCurrentY %halfLineGap%
|
|
11
11
|
.DrawText 0 %_CurrentY% Commands are described in a following chapter.
|
|
12
12
|
|
|
13
|
-
.incCurrentY %
|
|
13
|
+
.incCurrentY %halfLineGap%
|
|
14
14
|
.SetVar CommandLine1 Variables are referenced by enclosing them in percentage symbols. For example, to write some
|
|
15
15
|
.SetVar CommandLine1 %CommandLine1% text at the current position on the page the following DrawText command can be used:
|
|
16
|
-
.Do
|
|
17
|
-
.incCurrentY %
|
|
16
|
+
.Do CommandLine
|
|
17
|
+
.incCurrentY %halfLineGap%
|
|
18
18
|
.SetVar CommandLine1 .DrawText %%%%_CurrentX%%%% %%%%_CurrentY%%%% Hello World!
|
|
19
19
|
.Do CommandLine2
|
|
20
|
-
.incCurrentY %
|
|
20
|
+
.incCurrentY %halfLineGap%
|
|
21
21
|
.SetVar CommandLine1 Variables (and commands) are not case sensitive and the above command could also be given as:
|
|
22
|
-
.Do
|
|
23
|
-
.incCurrentY %
|
|
22
|
+
.Do CommandLine
|
|
23
|
+
.incCurrentY %halfLineGap%
|
|
24
24
|
.SetVar CommandLine1 .drawTEXT %%%%_currentX%%%% %%%%_CURRENTy%%%% Hello World!
|
|
25
25
|
.Do CommandLine2
|
|
26
|
-
.incCurrentY %
|
|
26
|
+
.incCurrentY %halfLineGap%
|
|
27
27
|
|
|
28
28
|
.SetVar CommandLine1 Variables are stored as strings though there is a limited capability to perform arithmetic on
|
|
29
29
|
.SetVar CommandLine1 %CommandLine1% variables. For example, the .IncVar command can be used to add or subtract a number from
|
|
30
30
|
.SetVar CommandLine1 %CommandLine1% a variable.
|
|
31
|
-
.Do
|
|
32
|
-
.incCurrentY %
|
|
31
|
+
.Do CommandLine
|
|
32
|
+
.incCurrentY %halfLineGap%
|
|
33
33
|
|
|
34
|
-
.DrawText 0 %_CurrentY% Variables do not have to be assigned a value before being used.
|
|
34
|
+
.DrawText 0 %_CurrentY% Variables do not have to be assigned a value before being used.
|
|
35
|
+
.incCurrentY %halfLineGap%
|
|
35
36
|
.DrawText 0 %_CurrentY% The value of a variable referenced before being assigned a value is an empty string.
|
|
36
|
-
.incCurrentY %
|
|
37
|
+
.incCurrentY %halfLineGap%
|
|
37
38
|
.SetVar CommandLine1 All variables are global, there is no scoping of variables within a group. A variable
|
|
38
39
|
.SetVar CommandLine1 %CommandLine1% defined within a group is available to commands run after that group.
|
|
39
|
-
.Do
|
|
40
|
+
.Do CommandLine
|