jspdf-dynamo 1.0.1 → 1.0.5
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/dist/index.cjs +90 -30
- package/dist/index.d.cts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.js +90 -30
- package/documentation/3. Variables/Introduction.txt +15 -12
- package/documentation/3. Variables/SystemMaintained.txt +47 -63
- package/documentation/4. Commands/AddBookmark.txt +4 -4
- package/documentation/4. Commands/AddPage.txt +6 -4
- package/documentation/4. Commands/CheckPage.txt +3 -3
- package/documentation/4. Commands/Commands.txt +7 -0
- package/documentation/4. Commands/CopyVar.txt +3 -3
- package/documentation/4. Commands/DivVar.txt +67 -0
- package/documentation/4. Commands/Do.txt +3 -3
- package/documentation/4. Commands/DoRepeat.txt +3 -3
- package/documentation/4. Commands/DrawBox.txt +3 -3
- package/documentation/4. Commands/DrawDebugGrid.txt +3 -3
- package/documentation/4. Commands/DrawImage.txt +4 -4
- package/documentation/4. Commands/DrawLine.txt +3 -3
- package/documentation/4. Commands/DrawTextBox.txt +1 -1
- package/documentation/4. Commands/DrawTextWrapped.txt +40 -17
- package/documentation/4. Commands/ForEachPage.txt +4 -4
- package/documentation/4. Commands/GetEnvVar.txt +2 -2
- package/documentation/4. Commands/IfEq.txt +53 -0
- package/documentation/4. Commands/IfGt.txt +1 -1
- package/documentation/4. Commands/IfNotBlank.txt +3 -3
- package/documentation/4. Commands/IncCurrentX.txt +1 -1
- package/documentation/4. Commands/IncCurrentY.txt +1 -1
- package/documentation/4. Commands/IncVar.txt +8 -8
- package/documentation/4. Commands/Include.txt +8 -8
- package/documentation/4. Commands/IncludeUrl.txt +43 -1
- package/documentation/4. Commands/{AddImageFromFile.txt → LoadImageFromFile.txt } +6 -6
- package/documentation/4. Commands/{AddImageFromUrl.txt → LoadImageFromUrl.txt } +6 -6
- package/documentation/4. Commands/MultVar.txt +11 -14
- package/documentation/4. Commands/SavePdf.txt +6 -0
- package/documentation/4. Commands/SelectPage.txt +6 -0
- package/documentation/4. Commands/SetCurrentX.txt +5 -5
- package/documentation/4. Commands/SetCurrentY.txt +3 -3
- package/documentation/4. Commands/SetDocumentInfo.txt +3 -3
- package/documentation/4. Commands/SetFillColour.txt +8 -25
- package/documentation/4. Commands/SetFontName.txt +3 -1
- package/documentation/4. Commands/SetFontSize.txt +2 -0
- package/documentation/4. Commands/SetLineColour.txt +8 -26
- package/documentation/4. Commands/SetLineWidth.txt +7 -7
- package/documentation/4. Commands/SetLogLevel.txt +6 -0
- package/documentation/4. Commands/SetMargin.txt +11 -14
- package/documentation/4. Commands/SetTextColour.txt +43 -0
- package/documentation/4. Commands/SetVar.txt +9 -10
- package/documentation/4. Commands/WriteLog.txt +56 -0
- package/documentation/Documentation.pdf +3430 -2703
- package/documentation/documentation.txt +13 -12
- package/package.json +2 -2
- package/documentation/4. Commands/SetPageOrientation.txt +0 -42
package/dist/index.cjs
CHANGED
|
@@ -118,9 +118,6 @@ var AppLogger = class {
|
|
|
118
118
|
this._logLevel = newLevel;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
if (this._logger.logLevel) {
|
|
122
|
-
this._logger.logLevel(this._logLevel);
|
|
123
|
-
}
|
|
124
121
|
}
|
|
125
122
|
canLog(level) {
|
|
126
123
|
return level >= this._logLevel;
|
|
@@ -355,10 +352,18 @@ var JsPdfProcessor = class {
|
|
|
355
352
|
})
|
|
356
353
|
);
|
|
357
354
|
this._variables.set("_DATEDMY", (/* @__PURE__ */ new Date()).toLocaleDateString("en-GB"));
|
|
355
|
+
this._variables.set("_IMAGEASPECT", "1");
|
|
356
|
+
this._variables.set("_IMAGEHEIGHT", "0");
|
|
357
|
+
this._variables.set("_IMAGEHEIGHTPX", "0");
|
|
358
|
+
this._variables.set("_IMAGEWIDTH", "0");
|
|
359
|
+
this._variables.set("_IMAGEWIDTHPX", "0");
|
|
358
360
|
this._variables.set("_PAGENO", "1");
|
|
359
361
|
this._variables.set("_PAGES", "1");
|
|
362
|
+
this.posnX = 0;
|
|
363
|
+
this.posnY = 0;
|
|
360
364
|
this.spaceHoz = 0;
|
|
361
365
|
this.spaceVert = 0;
|
|
366
|
+
this.currentPageNumber = 1;
|
|
362
367
|
this.lineWidth = this.pointsToUom(mmToPoints(0.2));
|
|
363
368
|
this.lineColour = "black";
|
|
364
369
|
this.fontPointSize = 12;
|
|
@@ -716,8 +721,8 @@ var JsPdfProcessor = class {
|
|
|
716
721
|
this.pageWidth = document.internal.pageSize.width - this._marginLeft - this._marginRight;
|
|
717
722
|
}
|
|
718
723
|
}
|
|
719
|
-
|
|
720
|
-
const subs = this.logAndParseCommand(".
|
|
724
|
+
LoadImageFromFile(input) {
|
|
725
|
+
const subs = this.logAndParseCommand(".LoadImageFromFile", input);
|
|
721
726
|
let fileName = subs;
|
|
722
727
|
if (!fileName) {
|
|
723
728
|
this.lastError = "A file name is required.";
|
|
@@ -738,9 +743,9 @@ var JsPdfProcessor = class {
|
|
|
738
743
|
this.lastResult = "0";
|
|
739
744
|
}
|
|
740
745
|
}
|
|
741
|
-
|
|
746
|
+
LoadImageFromUrl(input) {
|
|
742
747
|
return __async(this, null, function* () {
|
|
743
|
-
const subs = this.logAndParseCommand(".
|
|
748
|
+
const subs = this.logAndParseCommand(".LoadImageFromUrl", input);
|
|
744
749
|
let url = subs;
|
|
745
750
|
if (!url) {
|
|
746
751
|
this.lastError = "A URL is required.";
|
|
@@ -783,6 +788,10 @@ var JsPdfProcessor = class {
|
|
|
783
788
|
this.setFixedDec(this.pixelsToUom(info.height), 3)
|
|
784
789
|
);
|
|
785
790
|
this._variables.set("_IMAGEHEIGHTPX", info.height.toString());
|
|
791
|
+
this._variables.set(
|
|
792
|
+
"_IMAGEASPECT",
|
|
793
|
+
info.height > 0 ? this.setFixedDec(info.width / info.height, 3) : "1"
|
|
794
|
+
);
|
|
786
795
|
}
|
|
787
796
|
getContentType(fileName) {
|
|
788
797
|
const mediaType = fileName.split(".").pop();
|
|
@@ -1193,10 +1202,16 @@ var JsPdfProcessor = class {
|
|
|
1193
1202
|
return;
|
|
1194
1203
|
}
|
|
1195
1204
|
let lastObjectHeight = 0;
|
|
1196
|
-
text = text.replace(
|
|
1205
|
+
text = text.replace(/\\[nN]/g, " \n") + " ";
|
|
1206
|
+
const splitText = text.split("\n");
|
|
1207
|
+
const lines = [];
|
|
1208
|
+
for (let line of splitText) {
|
|
1209
|
+
lines.push(...this._pdfDocument.splitTextToSize(line, maxWidth));
|
|
1210
|
+
}
|
|
1211
|
+
if (lines.length > splitText.length) {
|
|
1212
|
+
this._logger.trace(`Text was wrapped into ${lines.length} lines`, lines);
|
|
1213
|
+
}
|
|
1197
1214
|
this.posnY = top;
|
|
1198
|
-
const lines = this._pdfDocument.splitTextToSize(text, maxWidth) || [];
|
|
1199
|
-
this._logger.trace(`Text was wrapped into ${lines.length} lines`, lines);
|
|
1200
1215
|
while (lines.length > 0) {
|
|
1201
1216
|
if (!cmdGroup.startsWith("*")) {
|
|
1202
1217
|
yield jsPdfDynamo.processGroups(this, cmdGroup, false);
|
|
@@ -1390,6 +1405,51 @@ var JsPdfProcessor = class {
|
|
|
1390
1405
|
"Variable " + varName + " incremented to " + this._variables.get(varName)
|
|
1391
1406
|
);
|
|
1392
1407
|
}
|
|
1408
|
+
divVar(input) {
|
|
1409
|
+
let subs = this.substitute(input.trim());
|
|
1410
|
+
this._logger.debug(".divVar " + subs);
|
|
1411
|
+
let { first: varName, rest } = getNextString(subs.toLocaleUpperCase());
|
|
1412
|
+
if (varName === "") {
|
|
1413
|
+
this.lastResult = "0";
|
|
1414
|
+
this.lastError = "DivVar must reference a variable";
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
if (varName.startsWith("_")) {
|
|
1418
|
+
this.lastResult = "0";
|
|
1419
|
+
this.lastError = "DivVar can not be used to update system maintained variables";
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
let varValue = this._variables.get(varName);
|
|
1423
|
+
if (!varValue) {
|
|
1424
|
+
this.lastResult = "0";
|
|
1425
|
+
this.lastError = "Variable '" + varName + "' is not defined";
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
if (isNaN(Number(varValue))) {
|
|
1429
|
+
this._variables.set(varName, "0");
|
|
1430
|
+
}
|
|
1431
|
+
while (rest.length > 0) {
|
|
1432
|
+
const { first: nextOp, rest: remainder } = getNextNumber(rest, 4);
|
|
1433
|
+
rest = remainder;
|
|
1434
|
+
let varValue2 = this._variables.get(varName);
|
|
1435
|
+
if (!isNaN(Number(nextOp)) && Number(nextOp) === 0) {
|
|
1436
|
+
this.lastResult = "0";
|
|
1437
|
+
this.lastError = "Divide by zero error";
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
if (!isNaN(Number(varValue2)) && !isNaN(Number(nextOp))) {
|
|
1441
|
+
this._variables.set(
|
|
1442
|
+
varName,
|
|
1443
|
+
removeTrailingZeros((Number(varValue2) / Number(nextOp)).toFixed(4))
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
varValue2 = this._variables.get(varName);
|
|
1447
|
+
}
|
|
1448
|
+
this.lastResult = "1";
|
|
1449
|
+
this._logger.trace(
|
|
1450
|
+
"Variable " + varName + " incremented to " + this._variables.get(varName)
|
|
1451
|
+
);
|
|
1452
|
+
}
|
|
1393
1453
|
multVar(input) {
|
|
1394
1454
|
let subs = this.substitute(input.trim());
|
|
1395
1455
|
this._logger.debug(".multVar " + subs);
|
|
@@ -1840,10 +1900,7 @@ var JsPdfDynamo = class {
|
|
|
1840
1900
|
}
|
|
1841
1901
|
toBlobUrl() {
|
|
1842
1902
|
try {
|
|
1843
|
-
const result = this._processor.PdfDocument.output(
|
|
1844
|
-
"bloburi",
|
|
1845
|
-
"application/pdf"
|
|
1846
|
-
);
|
|
1903
|
+
const result = this._processor.PdfDocument.output("bloburi");
|
|
1847
1904
|
return result;
|
|
1848
1905
|
} catch (e) {
|
|
1849
1906
|
__privateGet(this, _appLogger).warn(
|
|
@@ -1852,7 +1909,7 @@ var JsPdfDynamo = class {
|
|
|
1852
1909
|
return null;
|
|
1853
1910
|
}
|
|
1854
1911
|
}
|
|
1855
|
-
|
|
1912
|
+
getVariable(variableName) {
|
|
1856
1913
|
var _a;
|
|
1857
1914
|
return this._processor ? (_a = this._processor.getVar(variableName)) != null ? _a : null : null;
|
|
1858
1915
|
}
|
|
@@ -1874,7 +1931,7 @@ var JsPdfDynamo = class {
|
|
|
1874
1931
|
}
|
|
1875
1932
|
processTemplate(processor, input) {
|
|
1876
1933
|
return __async(this, null, function* () {
|
|
1877
|
-
let
|
|
1934
|
+
let inGroupLoading = false;
|
|
1878
1935
|
let grpName = "";
|
|
1879
1936
|
let currGroup = [];
|
|
1880
1937
|
for (let ix = 0; ix < input.length; ix++) {
|
|
@@ -1883,8 +1940,8 @@ var JsPdfDynamo = class {
|
|
|
1883
1940
|
continue;
|
|
1884
1941
|
}
|
|
1885
1942
|
if (currLine.startsWith("[")) {
|
|
1886
|
-
if (
|
|
1887
|
-
|
|
1943
|
+
if (inGroupLoading) {
|
|
1944
|
+
inGroupLoading = false;
|
|
1888
1945
|
__privateGet(this, _appLogger).debug(
|
|
1889
1946
|
`Finished loading group ${grpName} (${currLine})
|
|
1890
1947
|
`
|
|
@@ -1897,7 +1954,7 @@ var JsPdfDynamo = class {
|
|
|
1897
1954
|
grpName = grpName.substring(0, iy);
|
|
1898
1955
|
}
|
|
1899
1956
|
grpName = grpName.trim().toLocaleUpperCase();
|
|
1900
|
-
|
|
1957
|
+
inGroupLoading = true;
|
|
1901
1958
|
__privateGet(this, _appLogger).debug(`Loading group ${grpName} (${currLine})
|
|
1902
1959
|
`);
|
|
1903
1960
|
currGroup = [];
|
|
@@ -1905,7 +1962,7 @@ var JsPdfDynamo = class {
|
|
|
1905
1962
|
}
|
|
1906
1963
|
continue;
|
|
1907
1964
|
}
|
|
1908
|
-
if (
|
|
1965
|
+
if (inGroupLoading) {
|
|
1909
1966
|
currGroup.push(currLine);
|
|
1910
1967
|
__privateGet(this, _appLogger).trace(` ${currLine}`);
|
|
1911
1968
|
continue;
|
|
@@ -1929,12 +1986,6 @@ var JsPdfDynamo = class {
|
|
|
1929
1986
|
case "AddBookmark".toLowerCase():
|
|
1930
1987
|
processor.addBookmark(parameters);
|
|
1931
1988
|
return;
|
|
1932
|
-
case "AddImageFromFile".toLowerCase():
|
|
1933
|
-
processor.addImageFromFile(parameters);
|
|
1934
|
-
return;
|
|
1935
|
-
case "AddImageFromUrl".toLowerCase():
|
|
1936
|
-
yield processor.addImageFromUrl(parameters);
|
|
1937
|
-
return;
|
|
1938
1989
|
case "AddPage".toLowerCase():
|
|
1939
1990
|
processor.addPage(parameters);
|
|
1940
1991
|
return;
|
|
@@ -1944,6 +1995,9 @@ var JsPdfDynamo = class {
|
|
|
1944
1995
|
case "CopyVar".toLowerCase():
|
|
1945
1996
|
processor.copyVar(parameters);
|
|
1946
1997
|
return;
|
|
1998
|
+
case "DivVar".toLowerCase():
|
|
1999
|
+
processor.divVar(parameters);
|
|
2000
|
+
return;
|
|
1947
2001
|
case "Do".toLowerCase():
|
|
1948
2002
|
yield this.processGroups(processor, parameters);
|
|
1949
2003
|
return;
|
|
@@ -1998,12 +2052,18 @@ var JsPdfDynamo = class {
|
|
|
1998
2052
|
case "Include".toLowerCase():
|
|
1999
2053
|
yield this.includeFile(processor, parameters);
|
|
2000
2054
|
return;
|
|
2001
|
-
case "
|
|
2002
|
-
yield this.
|
|
2055
|
+
case "IncludeUrl".toLowerCase():
|
|
2056
|
+
yield this.includeUrl(processor, parameters);
|
|
2003
2057
|
return;
|
|
2004
2058
|
case "IncVar".toLowerCase():
|
|
2005
2059
|
processor.incVar(parameters);
|
|
2006
2060
|
return;
|
|
2061
|
+
case "LoadImageFromFile".toLowerCase():
|
|
2062
|
+
processor.LoadImageFromFile(parameters);
|
|
2063
|
+
return;
|
|
2064
|
+
case "LoadImageFromUrl".toLowerCase():
|
|
2065
|
+
yield processor.LoadImageFromUrl(parameters);
|
|
2066
|
+
return;
|
|
2007
2067
|
case "MultVar".toLowerCase():
|
|
2008
2068
|
processor.multVar(parameters);
|
|
2009
2069
|
return;
|
|
@@ -2137,10 +2197,10 @@ var JsPdfDynamo = class {
|
|
|
2137
2197
|
}
|
|
2138
2198
|
});
|
|
2139
2199
|
}
|
|
2140
|
-
|
|
2200
|
+
includeUrl(processor, input) {
|
|
2141
2201
|
return __async(this, null, function* () {
|
|
2142
2202
|
const subs = processor.substitute(input);
|
|
2143
|
-
__privateGet(this, _appLogger).debug(`.
|
|
2203
|
+
__privateGet(this, _appLogger).debug(`.includeUrl ${subs}`);
|
|
2144
2204
|
try {
|
|
2145
2205
|
const response = yield fetch(subs, {
|
|
2146
2206
|
headers: { Accept: "text/plain;q=0.9, text/*;q=0.8, */*;q=0.7" }
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,18 @@ interface ILogger {
|
|
|
6
6
|
info: (message: string, ...args: any | null) => void;
|
|
7
7
|
trace: (message: string, ...args: any | null) => void;
|
|
8
8
|
warn: (message: string, ...args: any | null) => void;
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
declare class AppLogger implements ILogger {
|
|
11
|
+
private _logLevel;
|
|
12
|
+
private _logger;
|
|
13
|
+
constructor(logger?: ILogger | null);
|
|
14
|
+
trace(message: string, ...args: any | null): void;
|
|
15
|
+
debug(message: string, ...args: any | null): void;
|
|
16
|
+
info(message: string, ...args: any | null): void;
|
|
17
|
+
warn(message: string, ...args: any | null): void;
|
|
18
|
+
error(message: string, ...args: any | null): void;
|
|
19
|
+
logLevel(newLevel: string | number): void;
|
|
20
|
+
private canLog;
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
type fontStyleType = "bold" | "italic" | "normal" | "bolditalic";
|
|
@@ -291,13 +302,13 @@ declare class JsPdfProcessor {
|
|
|
291
302
|
get textColour(): string;
|
|
292
303
|
private set textColour(value);
|
|
293
304
|
private get pageCount();
|
|
294
|
-
constructor(options: Partial<IJsPdfOptions>, logger:
|
|
305
|
+
constructor(options: Partial<IJsPdfOptions>, logger: AppLogger);
|
|
295
306
|
private logAndParseCommand;
|
|
296
307
|
addBookmark(input: string): void;
|
|
297
308
|
addPage(input?: string): void;
|
|
298
309
|
private calcPageDimensions;
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
LoadImageFromFile(input: string): void;
|
|
311
|
+
LoadImageFromUrl(input: string): Promise<void>;
|
|
301
312
|
private saveImage;
|
|
302
313
|
private getContentType;
|
|
303
314
|
checkPage(jsPdfDynamo: JsPdfDynamo, input: string): Promise<void>;
|
|
@@ -318,6 +329,7 @@ declare class JsPdfProcessor {
|
|
|
318
329
|
incCurrentX(input: string): void;
|
|
319
330
|
incCurrentY(input: string): void;
|
|
320
331
|
incVar(input: string): void;
|
|
332
|
+
divVar(input: string): void;
|
|
321
333
|
multVar(input: string): void;
|
|
322
334
|
savePdf(input: string): void;
|
|
323
335
|
selectPage(input: string): void;
|
|
@@ -355,7 +367,7 @@ declare class JsPdfDynamo {
|
|
|
355
367
|
constructor(options?: Partial<IJsPdfOptions>, logger?: ILogger | null);
|
|
356
368
|
toBlob(): Blob | null;
|
|
357
369
|
toBlobUrl(): string | null;
|
|
358
|
-
|
|
370
|
+
getVariable(variableName: string): string | null;
|
|
359
371
|
private prepareNewPdf;
|
|
360
372
|
prepareWrappedString(input: string): string;
|
|
361
373
|
processCommands(commands: string[]): Promise<void>;
|
|
@@ -364,7 +376,7 @@ declare class JsPdfDynamo {
|
|
|
364
376
|
processGroups(processor: JsPdfProcessor, input: string, log?: boolean): Promise<void>;
|
|
365
377
|
private processGroupsRepeat;
|
|
366
378
|
private includeFile;
|
|
367
|
-
private
|
|
379
|
+
private includeUrl;
|
|
368
380
|
}
|
|
369
381
|
|
|
370
382
|
export { JsPdfDynamo };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,18 @@ interface ILogger {
|
|
|
6
6
|
info: (message: string, ...args: any | null) => void;
|
|
7
7
|
trace: (message: string, ...args: any | null) => void;
|
|
8
8
|
warn: (message: string, ...args: any | null) => void;
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
declare class AppLogger implements ILogger {
|
|
11
|
+
private _logLevel;
|
|
12
|
+
private _logger;
|
|
13
|
+
constructor(logger?: ILogger | null);
|
|
14
|
+
trace(message: string, ...args: any | null): void;
|
|
15
|
+
debug(message: string, ...args: any | null): void;
|
|
16
|
+
info(message: string, ...args: any | null): void;
|
|
17
|
+
warn(message: string, ...args: any | null): void;
|
|
18
|
+
error(message: string, ...args: any | null): void;
|
|
19
|
+
logLevel(newLevel: string | number): void;
|
|
20
|
+
private canLog;
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
type fontStyleType = "bold" | "italic" | "normal" | "bolditalic";
|
|
@@ -291,13 +302,13 @@ declare class JsPdfProcessor {
|
|
|
291
302
|
get textColour(): string;
|
|
292
303
|
private set textColour(value);
|
|
293
304
|
private get pageCount();
|
|
294
|
-
constructor(options: Partial<IJsPdfOptions>, logger:
|
|
305
|
+
constructor(options: Partial<IJsPdfOptions>, logger: AppLogger);
|
|
295
306
|
private logAndParseCommand;
|
|
296
307
|
addBookmark(input: string): void;
|
|
297
308
|
addPage(input?: string): void;
|
|
298
309
|
private calcPageDimensions;
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
LoadImageFromFile(input: string): void;
|
|
311
|
+
LoadImageFromUrl(input: string): Promise<void>;
|
|
301
312
|
private saveImage;
|
|
302
313
|
private getContentType;
|
|
303
314
|
checkPage(jsPdfDynamo: JsPdfDynamo, input: string): Promise<void>;
|
|
@@ -318,6 +329,7 @@ declare class JsPdfProcessor {
|
|
|
318
329
|
incCurrentX(input: string): void;
|
|
319
330
|
incCurrentY(input: string): void;
|
|
320
331
|
incVar(input: string): void;
|
|
332
|
+
divVar(input: string): void;
|
|
321
333
|
multVar(input: string): void;
|
|
322
334
|
savePdf(input: string): void;
|
|
323
335
|
selectPage(input: string): void;
|
|
@@ -355,7 +367,7 @@ declare class JsPdfDynamo {
|
|
|
355
367
|
constructor(options?: Partial<IJsPdfOptions>, logger?: ILogger | null);
|
|
356
368
|
toBlob(): Blob | null;
|
|
357
369
|
toBlobUrl(): string | null;
|
|
358
|
-
|
|
370
|
+
getVariable(variableName: string): string | null;
|
|
359
371
|
private prepareNewPdf;
|
|
360
372
|
prepareWrappedString(input: string): string;
|
|
361
373
|
processCommands(commands: string[]): Promise<void>;
|
|
@@ -364,7 +376,7 @@ declare class JsPdfDynamo {
|
|
|
364
376
|
processGroups(processor: JsPdfProcessor, input: string, log?: boolean): Promise<void>;
|
|
365
377
|
private processGroupsRepeat;
|
|
366
378
|
private includeFile;
|
|
367
|
-
private
|
|
379
|
+
private includeUrl;
|
|
368
380
|
}
|
|
369
381
|
|
|
370
382
|
export { JsPdfDynamo };
|
package/dist/index.js
CHANGED
|
@@ -89,9 +89,6 @@ var AppLogger = class {
|
|
|
89
89
|
this._logLevel = newLevel;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
if (this._logger.logLevel) {
|
|
93
|
-
this._logger.logLevel(this._logLevel);
|
|
94
|
-
}
|
|
95
92
|
}
|
|
96
93
|
canLog(level) {
|
|
97
94
|
return level >= this._logLevel;
|
|
@@ -326,10 +323,18 @@ var JsPdfProcessor = class {
|
|
|
326
323
|
})
|
|
327
324
|
);
|
|
328
325
|
this._variables.set("_DATEDMY", (/* @__PURE__ */ new Date()).toLocaleDateString("en-GB"));
|
|
326
|
+
this._variables.set("_IMAGEASPECT", "1");
|
|
327
|
+
this._variables.set("_IMAGEHEIGHT", "0");
|
|
328
|
+
this._variables.set("_IMAGEHEIGHTPX", "0");
|
|
329
|
+
this._variables.set("_IMAGEWIDTH", "0");
|
|
330
|
+
this._variables.set("_IMAGEWIDTHPX", "0");
|
|
329
331
|
this._variables.set("_PAGENO", "1");
|
|
330
332
|
this._variables.set("_PAGES", "1");
|
|
333
|
+
this.posnX = 0;
|
|
334
|
+
this.posnY = 0;
|
|
331
335
|
this.spaceHoz = 0;
|
|
332
336
|
this.spaceVert = 0;
|
|
337
|
+
this.currentPageNumber = 1;
|
|
333
338
|
this.lineWidth = this.pointsToUom(mmToPoints(0.2));
|
|
334
339
|
this.lineColour = "black";
|
|
335
340
|
this.fontPointSize = 12;
|
|
@@ -687,8 +692,8 @@ var JsPdfProcessor = class {
|
|
|
687
692
|
this.pageWidth = document.internal.pageSize.width - this._marginLeft - this._marginRight;
|
|
688
693
|
}
|
|
689
694
|
}
|
|
690
|
-
|
|
691
|
-
const subs = this.logAndParseCommand(".
|
|
695
|
+
LoadImageFromFile(input) {
|
|
696
|
+
const subs = this.logAndParseCommand(".LoadImageFromFile", input);
|
|
692
697
|
let fileName = subs;
|
|
693
698
|
if (!fileName) {
|
|
694
699
|
this.lastError = "A file name is required.";
|
|
@@ -709,9 +714,9 @@ var JsPdfProcessor = class {
|
|
|
709
714
|
this.lastResult = "0";
|
|
710
715
|
}
|
|
711
716
|
}
|
|
712
|
-
|
|
717
|
+
LoadImageFromUrl(input) {
|
|
713
718
|
return __async(this, null, function* () {
|
|
714
|
-
const subs = this.logAndParseCommand(".
|
|
719
|
+
const subs = this.logAndParseCommand(".LoadImageFromUrl", input);
|
|
715
720
|
let url = subs;
|
|
716
721
|
if (!url) {
|
|
717
722
|
this.lastError = "A URL is required.";
|
|
@@ -754,6 +759,10 @@ var JsPdfProcessor = class {
|
|
|
754
759
|
this.setFixedDec(this.pixelsToUom(info.height), 3)
|
|
755
760
|
);
|
|
756
761
|
this._variables.set("_IMAGEHEIGHTPX", info.height.toString());
|
|
762
|
+
this._variables.set(
|
|
763
|
+
"_IMAGEASPECT",
|
|
764
|
+
info.height > 0 ? this.setFixedDec(info.width / info.height, 3) : "1"
|
|
765
|
+
);
|
|
757
766
|
}
|
|
758
767
|
getContentType(fileName) {
|
|
759
768
|
const mediaType = fileName.split(".").pop();
|
|
@@ -1164,10 +1173,16 @@ var JsPdfProcessor = class {
|
|
|
1164
1173
|
return;
|
|
1165
1174
|
}
|
|
1166
1175
|
let lastObjectHeight = 0;
|
|
1167
|
-
text = text.replace(
|
|
1176
|
+
text = text.replace(/\\[nN]/g, " \n") + " ";
|
|
1177
|
+
const splitText = text.split("\n");
|
|
1178
|
+
const lines = [];
|
|
1179
|
+
for (let line of splitText) {
|
|
1180
|
+
lines.push(...this._pdfDocument.splitTextToSize(line, maxWidth));
|
|
1181
|
+
}
|
|
1182
|
+
if (lines.length > splitText.length) {
|
|
1183
|
+
this._logger.trace(`Text was wrapped into ${lines.length} lines`, lines);
|
|
1184
|
+
}
|
|
1168
1185
|
this.posnY = top;
|
|
1169
|
-
const lines = this._pdfDocument.splitTextToSize(text, maxWidth) || [];
|
|
1170
|
-
this._logger.trace(`Text was wrapped into ${lines.length} lines`, lines);
|
|
1171
1186
|
while (lines.length > 0) {
|
|
1172
1187
|
if (!cmdGroup.startsWith("*")) {
|
|
1173
1188
|
yield jsPdfDynamo.processGroups(this, cmdGroup, false);
|
|
@@ -1361,6 +1376,51 @@ var JsPdfProcessor = class {
|
|
|
1361
1376
|
"Variable " + varName + " incremented to " + this._variables.get(varName)
|
|
1362
1377
|
);
|
|
1363
1378
|
}
|
|
1379
|
+
divVar(input) {
|
|
1380
|
+
let subs = this.substitute(input.trim());
|
|
1381
|
+
this._logger.debug(".divVar " + subs);
|
|
1382
|
+
let { first: varName, rest } = getNextString(subs.toLocaleUpperCase());
|
|
1383
|
+
if (varName === "") {
|
|
1384
|
+
this.lastResult = "0";
|
|
1385
|
+
this.lastError = "DivVar must reference a variable";
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (varName.startsWith("_")) {
|
|
1389
|
+
this.lastResult = "0";
|
|
1390
|
+
this.lastError = "DivVar can not be used to update system maintained variables";
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
let varValue = this._variables.get(varName);
|
|
1394
|
+
if (!varValue) {
|
|
1395
|
+
this.lastResult = "0";
|
|
1396
|
+
this.lastError = "Variable '" + varName + "' is not defined";
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (isNaN(Number(varValue))) {
|
|
1400
|
+
this._variables.set(varName, "0");
|
|
1401
|
+
}
|
|
1402
|
+
while (rest.length > 0) {
|
|
1403
|
+
const { first: nextOp, rest: remainder } = getNextNumber(rest, 4);
|
|
1404
|
+
rest = remainder;
|
|
1405
|
+
let varValue2 = this._variables.get(varName);
|
|
1406
|
+
if (!isNaN(Number(nextOp)) && Number(nextOp) === 0) {
|
|
1407
|
+
this.lastResult = "0";
|
|
1408
|
+
this.lastError = "Divide by zero error";
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (!isNaN(Number(varValue2)) && !isNaN(Number(nextOp))) {
|
|
1412
|
+
this._variables.set(
|
|
1413
|
+
varName,
|
|
1414
|
+
removeTrailingZeros((Number(varValue2) / Number(nextOp)).toFixed(4))
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
varValue2 = this._variables.get(varName);
|
|
1418
|
+
}
|
|
1419
|
+
this.lastResult = "1";
|
|
1420
|
+
this._logger.trace(
|
|
1421
|
+
"Variable " + varName + " incremented to " + this._variables.get(varName)
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1364
1424
|
multVar(input) {
|
|
1365
1425
|
let subs = this.substitute(input.trim());
|
|
1366
1426
|
this._logger.debug(".multVar " + subs);
|
|
@@ -1811,10 +1871,7 @@ var JsPdfDynamo = class {
|
|
|
1811
1871
|
}
|
|
1812
1872
|
toBlobUrl() {
|
|
1813
1873
|
try {
|
|
1814
|
-
const result = this._processor.PdfDocument.output(
|
|
1815
|
-
"bloburi",
|
|
1816
|
-
"application/pdf"
|
|
1817
|
-
);
|
|
1874
|
+
const result = this._processor.PdfDocument.output("bloburi");
|
|
1818
1875
|
return result;
|
|
1819
1876
|
} catch (e) {
|
|
1820
1877
|
__privateGet(this, _appLogger).warn(
|
|
@@ -1823,7 +1880,7 @@ var JsPdfDynamo = class {
|
|
|
1823
1880
|
return null;
|
|
1824
1881
|
}
|
|
1825
1882
|
}
|
|
1826
|
-
|
|
1883
|
+
getVariable(variableName) {
|
|
1827
1884
|
var _a;
|
|
1828
1885
|
return this._processor ? (_a = this._processor.getVar(variableName)) != null ? _a : null : null;
|
|
1829
1886
|
}
|
|
@@ -1845,7 +1902,7 @@ var JsPdfDynamo = class {
|
|
|
1845
1902
|
}
|
|
1846
1903
|
processTemplate(processor, input) {
|
|
1847
1904
|
return __async(this, null, function* () {
|
|
1848
|
-
let
|
|
1905
|
+
let inGroupLoading = false;
|
|
1849
1906
|
let grpName = "";
|
|
1850
1907
|
let currGroup = [];
|
|
1851
1908
|
for (let ix = 0; ix < input.length; ix++) {
|
|
@@ -1854,8 +1911,8 @@ var JsPdfDynamo = class {
|
|
|
1854
1911
|
continue;
|
|
1855
1912
|
}
|
|
1856
1913
|
if (currLine.startsWith("[")) {
|
|
1857
|
-
if (
|
|
1858
|
-
|
|
1914
|
+
if (inGroupLoading) {
|
|
1915
|
+
inGroupLoading = false;
|
|
1859
1916
|
__privateGet(this, _appLogger).debug(
|
|
1860
1917
|
`Finished loading group ${grpName} (${currLine})
|
|
1861
1918
|
`
|
|
@@ -1868,7 +1925,7 @@ var JsPdfDynamo = class {
|
|
|
1868
1925
|
grpName = grpName.substring(0, iy);
|
|
1869
1926
|
}
|
|
1870
1927
|
grpName = grpName.trim().toLocaleUpperCase();
|
|
1871
|
-
|
|
1928
|
+
inGroupLoading = true;
|
|
1872
1929
|
__privateGet(this, _appLogger).debug(`Loading group ${grpName} (${currLine})
|
|
1873
1930
|
`);
|
|
1874
1931
|
currGroup = [];
|
|
@@ -1876,7 +1933,7 @@ var JsPdfDynamo = class {
|
|
|
1876
1933
|
}
|
|
1877
1934
|
continue;
|
|
1878
1935
|
}
|
|
1879
|
-
if (
|
|
1936
|
+
if (inGroupLoading) {
|
|
1880
1937
|
currGroup.push(currLine);
|
|
1881
1938
|
__privateGet(this, _appLogger).trace(` ${currLine}`);
|
|
1882
1939
|
continue;
|
|
@@ -1900,12 +1957,6 @@ var JsPdfDynamo = class {
|
|
|
1900
1957
|
case "AddBookmark".toLowerCase():
|
|
1901
1958
|
processor.addBookmark(parameters);
|
|
1902
1959
|
return;
|
|
1903
|
-
case "AddImageFromFile".toLowerCase():
|
|
1904
|
-
processor.addImageFromFile(parameters);
|
|
1905
|
-
return;
|
|
1906
|
-
case "AddImageFromUrl".toLowerCase():
|
|
1907
|
-
yield processor.addImageFromUrl(parameters);
|
|
1908
|
-
return;
|
|
1909
1960
|
case "AddPage".toLowerCase():
|
|
1910
1961
|
processor.addPage(parameters);
|
|
1911
1962
|
return;
|
|
@@ -1915,6 +1966,9 @@ var JsPdfDynamo = class {
|
|
|
1915
1966
|
case "CopyVar".toLowerCase():
|
|
1916
1967
|
processor.copyVar(parameters);
|
|
1917
1968
|
return;
|
|
1969
|
+
case "DivVar".toLowerCase():
|
|
1970
|
+
processor.divVar(parameters);
|
|
1971
|
+
return;
|
|
1918
1972
|
case "Do".toLowerCase():
|
|
1919
1973
|
yield this.processGroups(processor, parameters);
|
|
1920
1974
|
return;
|
|
@@ -1969,12 +2023,18 @@ var JsPdfDynamo = class {
|
|
|
1969
2023
|
case "Include".toLowerCase():
|
|
1970
2024
|
yield this.includeFile(processor, parameters);
|
|
1971
2025
|
return;
|
|
1972
|
-
case "
|
|
1973
|
-
yield this.
|
|
2026
|
+
case "IncludeUrl".toLowerCase():
|
|
2027
|
+
yield this.includeUrl(processor, parameters);
|
|
1974
2028
|
return;
|
|
1975
2029
|
case "IncVar".toLowerCase():
|
|
1976
2030
|
processor.incVar(parameters);
|
|
1977
2031
|
return;
|
|
2032
|
+
case "LoadImageFromFile".toLowerCase():
|
|
2033
|
+
processor.LoadImageFromFile(parameters);
|
|
2034
|
+
return;
|
|
2035
|
+
case "LoadImageFromUrl".toLowerCase():
|
|
2036
|
+
yield processor.LoadImageFromUrl(parameters);
|
|
2037
|
+
return;
|
|
1978
2038
|
case "MultVar".toLowerCase():
|
|
1979
2039
|
processor.multVar(parameters);
|
|
1980
2040
|
return;
|
|
@@ -2108,10 +2168,10 @@ var JsPdfDynamo = class {
|
|
|
2108
2168
|
}
|
|
2109
2169
|
});
|
|
2110
2170
|
}
|
|
2111
|
-
|
|
2171
|
+
includeUrl(processor, input) {
|
|
2112
2172
|
return __async(this, null, function* () {
|
|
2113
2173
|
const subs = processor.substitute(input);
|
|
2114
|
-
__privateGet(this, _appLogger).debug(`.
|
|
2174
|
+
__privateGet(this, _appLogger).debug(`.includeUrl ${subs}`);
|
|
2115
2175
|
try {
|
|
2116
2176
|
const response = yield fetch(subs, {
|
|
2117
2177
|
headers: { Accept: "text/plain;q=0.9, text/*;q=0.8, */*;q=0.7" }
|
|
@@ -11,26 +11,29 @@
|
|
|
11
11
|
.DrawText 0 %_CurrentY% Commands are described in a following chapter.
|
|
12
12
|
|
|
13
13
|
.incCurrentY %_FontHeight%
|
|
14
|
-
.
|
|
15
|
-
.
|
|
14
|
+
.SetVar CommandLine1 Variables are referenced by enclosing them in percentage symbols. For example, to write some
|
|
15
|
+
.SetVar CommandLine1 %CommandLine1% text at the current position on the page the following DrawText command can be used:
|
|
16
|
+
.Do CommandLine1
|
|
16
17
|
.incCurrentY %_FontHeight%
|
|
17
18
|
.SetVar CommandLine1 .DrawText %%%%_CurrentX%%%% %%%%_CurrentY%%%% Hello World!
|
|
18
|
-
.Do CommandLine2
|
|
19
|
+
.Do CommandLine2
|
|
19
20
|
.incCurrentY %_FontHeight%
|
|
20
|
-
.
|
|
21
|
-
.
|
|
21
|
+
.SetVar CommandLine1 Variables (and commands) are not case sensitive and the above command could also be given as:
|
|
22
|
+
.Do CommandLine1
|
|
22
23
|
.incCurrentY %_FontHeight%
|
|
23
24
|
.SetVar CommandLine1 .drawTEXT %%%%_currentX%%%% %%%%_CURRENTy%%%% Hello World!
|
|
24
25
|
.Do CommandLine2
|
|
25
26
|
.incCurrentY %_FontHeight%
|
|
26
|
-
|
|
27
|
-
.
|
|
28
|
-
.
|
|
27
|
+
|
|
28
|
+
.SetVar CommandLine1 Variables are stored as strings though there is a limited capability to perform arithmetic on
|
|
29
|
+
.SetVar CommandLine1 %CommandLine1% variables. For example, the .IncVar command can be used to add or subtract a number from
|
|
30
|
+
.SetVar CommandLine1 %CommandLine1% a variable.
|
|
31
|
+
.Do CommandLine1
|
|
29
32
|
.incCurrentY %_FontHeight%
|
|
33
|
+
|
|
30
34
|
.DrawText 0 %_CurrentY% Variables do not have to be assigned a value before being used.
|
|
31
35
|
.DrawText 0 %_CurrentY% The value of a variable referenced before being assigned a value is an empty string.
|
|
32
36
|
.incCurrentY %_FontHeight%
|
|
33
|
-
.
|
|
34
|
-
.
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
+
.SetVar CommandLine1 All variables are global, there is no scoping of variables within a group. A variable
|
|
38
|
+
.SetVar CommandLine1 %CommandLine1% defined within a group is available to commands run after that group.
|
|
39
|
+
.Do CommandLine1
|