jspdf-dynamo 1.0.7 → 1.0.9

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.
Binary file
package/dist/index.cjs CHANGED
@@ -55,14 +55,14 @@ var __async = (__this, __arguments, generator) => {
55
55
  };
56
56
 
57
57
  // src/index.ts
58
- var src_exports = {};
59
- __export(src_exports, {
58
+ var index_exports = {};
59
+ __export(index_exports, {
60
60
  JsPdfDynamo: () => JsPdfDynamo
61
61
  });
62
- module.exports = __toCommonJS(src_exports);
62
+ module.exports = __toCommonJS(index_exports);
63
63
 
64
64
  // src/models/jsPdfProcessor.ts
65
- var import_jspdf = __toESM(require("jspdf"), 1);
65
+ var jspdfModule = __toESM(require("jspdf"), 1);
66
66
  var fs = __toESM(require("fs"), 1);
67
67
 
68
68
  // src/models/logger.ts
@@ -340,11 +340,18 @@ var JsPdfProcessor = class {
340
340
  };
341
341
  this._logger = logger;
342
342
  const optn = new JsPdfOptions(options);
343
- this._pdfDocument = new import_jspdf.default(optn);
343
+ const jsPDFCtor = jspdfModule && typeof jspdfModule.default === "function" ? jspdfModule.default : jspdfModule && typeof jspdfModule.jsPDF === "function" ? jspdfModule.jsPDF : typeof jspdfModule === "function" ? jspdfModule : void 0;
344
+ if (!jsPDFCtor) {
345
+ throw new Error(
346
+ 'jsPDF constructor not found. Ensure a compatible "jspdf" package is installed.'
347
+ );
348
+ }
349
+ this._pdfDocument = new jsPDFCtor(optn);
350
+ this._pdfDocument.setLineHeightFactor(1);
351
+ this._pdfDocument.setProperties({ creator: "jsPdf-Dynamo" });
344
352
  this.pageSize = optn.pageSize;
345
353
  this.pageOrientation = optn.orientation;
346
354
  this.currentUom = optn.unit;
347
- this._pdfDocument.setLineHeightFactor(1);
348
355
  const now = /* @__PURE__ */ new Date();
349
356
  this._variables.set(
350
357
  "_TIMEHM",
@@ -660,7 +667,8 @@ var JsPdfProcessor = class {
660
667
  this._pdfDocument.setTextColor(this._textColour);
661
668
  }
662
669
  get pageCount() {
663
- return this._pdfDocument ? this._pdfDocument.internal.getNumberOfPages() : -1;
670
+ const internal = this._pdfDocument && this._pdfDocument.internal ? this._pdfDocument.internal : null;
671
+ return internal && typeof internal.getNumberOfPages === "function" ? internal.getNumberOfPages() : -1;
664
672
  }
665
673
  addBookmark(input) {
666
674
  const subs = this.logAndParseCommand(".addBookmark", input);
@@ -1630,6 +1638,7 @@ var JsPdfProcessor = class {
1630
1638
  let subs = this.logAndParseCommand(".savePdf", input.trim());
1631
1639
  if (isBrowser()) {
1632
1640
  this.lastError = "SavePdf is not supported in the browser";
1641
+ this._logger.warn(this.lastError);
1633
1642
  this.lastResult = "0";
1634
1643
  return;
1635
1644
  }
@@ -1665,6 +1674,7 @@ var JsPdfProcessor = class {
1665
1674
  this.lastResult = pageNo.toString();
1666
1675
  this.posnX = 0;
1667
1676
  this.posnY = 0;
1677
+ this.lastResult = "1";
1668
1678
  }
1669
1679
  setCurrentFont(fontName, fontStyle) {
1670
1680
  this._pdfDocument.setFont(fontName, fontStyle);
@@ -1687,9 +1697,6 @@ var JsPdfProcessor = class {
1687
1697
  let { first, rest } = getNextString(subs);
1688
1698
  this.lastResult = "1";
1689
1699
  switch (first.toLocaleLowerCase()) {
1690
- case "application":
1691
- this._pdfDocument.setProperties({ application: rest });
1692
- break;
1693
1700
  case "author":
1694
1701
  this._pdfDocument.setProperties({ author: rest });
1695
1702
  break;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import jsPDF from 'jspdf';
1
+ import { jsPDF } from 'jspdf';
2
2
 
3
3
  interface ILogger {
4
4
  debug: (message: string, args?: any) => void;
@@ -370,7 +370,7 @@ declare class JsPdfDynamo {
370
370
  _processor: JsPdfProcessor;
371
371
  constructor(options?: Partial<IJsPdfOptions>, logger?: ILogger | null);
372
372
  toBlob(): Blob | null;
373
- toBlobUrl(): string | null;
373
+ toBlobUrl(): URL | null;
374
374
  getVariable(variableName: string): string | null;
375
375
  private prepareNewPdf;
376
376
  prepareWrappedString(input: string): string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import jsPDF from 'jspdf';
1
+ import { jsPDF } from 'jspdf';
2
2
 
3
3
  interface ILogger {
4
4
  debug: (message: string, args?: any) => void;
@@ -370,7 +370,7 @@ declare class JsPdfDynamo {
370
370
  _processor: JsPdfProcessor;
371
371
  constructor(options?: Partial<IJsPdfOptions>, logger?: ILogger | null);
372
372
  toBlob(): Blob | null;
373
- toBlobUrl(): string | null;
373
+ toBlobUrl(): URL | null;
374
374
  getVariable(variableName: string): string | null;
375
375
  private prepareNewPdf;
376
376
  prepareWrappedString(input: string): string;
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ var __async = (__this, __arguments, generator) => {
33
33
  };
34
34
 
35
35
  // src/models/jsPdfProcessor.ts
36
- import jsPDF from "jspdf";
36
+ import * as jspdfModule from "jspdf";
37
37
  import * as fs from "fs";
38
38
 
39
39
  // src/models/logger.ts
@@ -311,11 +311,18 @@ var JsPdfProcessor = class {
311
311
  };
312
312
  this._logger = logger;
313
313
  const optn = new JsPdfOptions(options);
314
- this._pdfDocument = new jsPDF(optn);
314
+ const jsPDFCtor = jspdfModule && typeof jspdfModule.default === "function" ? jspdfModule.default : jspdfModule && typeof jspdfModule.jsPDF === "function" ? jspdfModule.jsPDF : typeof jspdfModule === "function" ? jspdfModule : void 0;
315
+ if (!jsPDFCtor) {
316
+ throw new Error(
317
+ 'jsPDF constructor not found. Ensure a compatible "jspdf" package is installed.'
318
+ );
319
+ }
320
+ this._pdfDocument = new jsPDFCtor(optn);
321
+ this._pdfDocument.setLineHeightFactor(1);
322
+ this._pdfDocument.setProperties({ creator: "jsPdf-Dynamo" });
315
323
  this.pageSize = optn.pageSize;
316
324
  this.pageOrientation = optn.orientation;
317
325
  this.currentUom = optn.unit;
318
- this._pdfDocument.setLineHeightFactor(1);
319
326
  const now = /* @__PURE__ */ new Date();
320
327
  this._variables.set(
321
328
  "_TIMEHM",
@@ -631,7 +638,8 @@ var JsPdfProcessor = class {
631
638
  this._pdfDocument.setTextColor(this._textColour);
632
639
  }
633
640
  get pageCount() {
634
- return this._pdfDocument ? this._pdfDocument.internal.getNumberOfPages() : -1;
641
+ const internal = this._pdfDocument && this._pdfDocument.internal ? this._pdfDocument.internal : null;
642
+ return internal && typeof internal.getNumberOfPages === "function" ? internal.getNumberOfPages() : -1;
635
643
  }
636
644
  addBookmark(input) {
637
645
  const subs = this.logAndParseCommand(".addBookmark", input);
@@ -1601,6 +1609,7 @@ var JsPdfProcessor = class {
1601
1609
  let subs = this.logAndParseCommand(".savePdf", input.trim());
1602
1610
  if (isBrowser()) {
1603
1611
  this.lastError = "SavePdf is not supported in the browser";
1612
+ this._logger.warn(this.lastError);
1604
1613
  this.lastResult = "0";
1605
1614
  return;
1606
1615
  }
@@ -1636,6 +1645,7 @@ var JsPdfProcessor = class {
1636
1645
  this.lastResult = pageNo.toString();
1637
1646
  this.posnX = 0;
1638
1647
  this.posnY = 0;
1648
+ this.lastResult = "1";
1639
1649
  }
1640
1650
  setCurrentFont(fontName, fontStyle) {
1641
1651
  this._pdfDocument.setFont(fontName, fontStyle);
@@ -1658,9 +1668,6 @@ var JsPdfProcessor = class {
1658
1668
  let { first, rest } = getNextString(subs);
1659
1669
  this.lastResult = "1";
1660
1670
  switch (first.toLocaleLowerCase()) {
1661
- case "application":
1662
- this._pdfDocument.setProperties({ application: rest });
1663
- break;
1664
1671
  case "author":
1665
1672
  this._pdfDocument.setProperties({ author: rest });
1666
1673
  break;
@@ -1,7 +1,7 @@
1
1
  .SetVar CommandName toBlobUrl()
2
2
  .Do CommandHeading
3
3
  .SetVar text This is a browser only method that generates the current PDF as a Blob
4
- .SetVar text %text% and returns a string containing a URL to that Blob. This can be
4
+ .SetVar text %text% and returns the URL to that Blob. This can be
5
5
  .SetVar text %text% used to display the PDF in the current or another browser window.
6
6
  .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
7
7
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  .SetVar CommandSubHeading Returns
14
14
  .Do CommandSubHeading
15
- .SetVar CommandLine1 A string containing the URL reference to the PDF.
15
+ .SetVar CommandLine1 A URL object that references the PDF.
16
16
  .Do CommandLine2
17
17
 
18
18
  .SetVar CommandSubHeading Example
@@ -9,6 +9,12 @@
9
9
  .SetVar text Note that unless otherwise stated, all distances and positions are in the unit of measure specified
10
10
  .SetVar text %text% when creating the JsPdfDynamo object.
11
11
  .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
12
+ .SetVar text %text% variables can not be changed directly by using the SetVar command.
13
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
14
+ .incCurrentY %halfLineGap%
15
+ .SetVar text Note that unless otherwise stated, all distances and positions are in the unit of measure specified
16
+ .SetVar text %text% when creating the JsPdfDynamo object.
17
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
12
18
  .incCurrentY %halfLineGap%
13
19
  .SetMargin L 20
14
20
 
@@ -1,6 +1,39 @@
1
1
  .SetVar CommandName SavePdf
2
2
  .Do CommandHeading
3
- .SetVar CommandLine1 To be documented.
4
- .Do CommandLine
3
+ .SetVar text Only available when running within Node.js, this command saves the current PDF to the given location.
4
+ .SetVar text %text% A warning will be logged if used within a browser.
5
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
6
+
7
+ .SetVar CommandSubHeading Syntax
8
+ .Do CommandSubHeading
9
+ .SetVar CommandLine1 .SavePdf File-name
10
+ .Do CommandLine2
11
+
12
+ .SetVar CommandSubHeading Parameters
13
+ .Do CommandSubHeading
14
+ .SetVar CommandLine1 File-name
15
+ .SetVar CommandLine2 The path and name of the file to save. This can include
16
+ .Do CommandLine2
17
+ .SetVar CommandLine2 variables as well as constant text.
18
+ .Do CommandLine2
19
+
20
+ .SetVar CommandSubHeading Other
21
+ .Do CommandSubHeading
22
+ .SetVar text The variable _LastResult is set to '1' if the current PDF is saved, otherwise it is set to '0'
23
+ .SetVar text %text% and _LastError is set to a description of the problem.
24
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
25
+ .incCurrentY %halfLineGap%
26
+ .SetVar text Note that the path must exist or this command will fail.
27
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
28
+ .incCurrentY %halfLineGap%
29
+ .SetVar text If not given the default name of Document.pdf will be used.
30
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
31
+
32
+ .SetVar CommandSubHeading Examples
33
+ .Do CommandSubHeading
34
+ .SetVar CommandLine1 .SavePdf ../output/invoice.pdf
35
+ .Do CommandLine2
36
+ .SetVar CommandLine1 .SavePdf %%%%savepath%%%%/%%%%customer%%%%.pdf
37
+ .Do CommandLine2
5
38
 
6
39
  .incCurrentY %_FontHeight%
@@ -1,6 +1,31 @@
1
1
  .SetVar CommandName SelectPage
2
2
  .Do CommandHeading
3
- .SetVar CommandLine1 To be documented.
4
- .Do CommandLine
3
+ .SetVar text This makes the given page active and sets the current left and top positions to zero.
4
+ .SetVar text %text% Subsequent commands will be relative to this page.
5
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
6
+
7
+ .SetVar CommandSubHeading Syntax
8
+ .Do CommandSubHeading
9
+ .SetVar CommandLine1 .SelectPage Value
10
+ .Do CommandLine2
11
+
12
+ .SetVar CommandSubHeading Parameters
13
+ .Do CommandSubHeading
14
+ .SetVar CommandLine1 Value
15
+ .SetVar CommandLine2 The number of the page to make active. This is 1 based.
16
+ .Do CommandLine2
17
+
18
+ .SetVar CommandSubHeading Other
19
+ .Do CommandSubHeading
20
+ .SetVar text The variable _LastResult is set to '1' if the command is successful, otherwise it is set to '0'
21
+ .SetVar text %text% and _LastError is set to a description of the problem.
22
+ .DrawTextWrapped 0 %_CurrentY% %_PageWidth% CommandCheckPage %text%
23
+
24
+ .SetVar CommandSubHeading Examples
25
+ .Do CommandSubHeading
26
+ .SetVar CommandLine1 .SelectPage 7
27
+ .Do CommandLine2
28
+ .SetVar CommandLine1 .SelectPage %%%%_Pages%%%%
29
+ .Do CommandLine2
5
30
 
6
31
  .incCurrentY %_FontHeight%
@@ -10,14 +10,10 @@
10
10
  .SetVar CommandSubHeading Parameters
11
11
  .Do CommandSubHeading
12
12
  .SetVar CommandLine1 Property
13
- .SetVar CommandLine2 One of the following values: Application, Author, Creator, CreationDate, Keywords,
14
- .Do CommandLine2
15
- .SetVar CommandLine2 ModDate, Producer, Subject or Title.
13
+ .SetVar CommandLine2 One of the following values: Author, Creator, Keywords, Subject or Title.
16
14
  .Do CommandLine2
17
15
  .SetVar CommandLine1 Value
18
- .SetVar CommandLine2 The value to set the property to. For CreationDate and ModDate this must
19
- .Do CommandLine2
20
- .SetVar CommandLine2 either be in the format of yyyy-mm-dd or blank.
16
+ .SetVar CommandLine2 The value to set the property to.
21
17
  .Do CommandLine2
22
18
 
23
19
  .SetVar CommandSubHeading Other
@@ -5,6 +5,7 @@
5
5
  .SetVar CommandSubHeading Syntax
6
6
  .Do CommandSubHeading
7
7
  .SetVar CommandLine1 .SetFillColor Colour
8
+ .SetVar CommandLine1 .SetFillColor Colour
8
9
  .Do CommandLine2
9
10
 
10
11
  .SetVar CommandSubHeading Parameters
@@ -82,4 +82,6 @@
82
82
  .SetVar CommandLine1 DrawTextBox, DrawText, SetFontSize, SetFontStyle, SetTextColour
83
83
  .Do CommandLine
84
84
 
85
+ .incCurrentY %_FontHeight%
86
+
85
87
  .incCurrentY %_FontHeight%
@@ -45,4 +45,5 @@
45
45
  .SetVar CommandLine1 DrawTextBox, DrawText, SetFontName, SetFontStyle, SetTextColour
46
46
  .Do CommandLine
47
47
 
48
+ .incCurrentY %_FontHeight%
48
49
  .incCurrentY %_FontHeight%
@@ -5,6 +5,7 @@
5
5
  .SetVar CommandSubHeading Syntax
6
6
  .Do CommandSubHeading
7
7
  .SetVar CommandLine1 .SetLineColor Colour
8
+ .SetVar CommandLine1 .SetLineColor Colour
8
9
  .Do CommandLine2
9
10
 
10
11
  .SetVar CommandSubHeading Parameters
@@ -56,7 +56,6 @@
56
56
  .SetVar top %_PageHeight%
57
57
  .MultVar top 0.3
58
58
  .DrawTextBox 0 %top% %_PageWidth% %_FontHeight% centered top jsPdf-Dynamo
59
- .DrawTextBox 0 %_CurrentY% %_PageWidth% %_FontHeight% centered top (Draft)
60
59
  .incCurrentY 2
61
60
  .SetFontSize 24
62
61
  .SetTextColour %black%
@@ -81,11 +80,6 @@
81
80
  [End]
82
81
 
83
82
  [Footer]
84
- .setMargin t 7
85
- .setFontStyle Bold
86
- .setFontSize 18
87
- .SetTextColour red
88
- .ifGt %_PageNo% 1 .DrawTextBox 0 0 %_PageWidth% 8 centered centered *** Draft ***
89
83
  .Do SetDefaultText
90
84
  .SetVar top %_PageHeight%
91
85
  .incVar top -%_FontHeight%
@@ -276,5 +270,5 @@
276
270
  .ForEachPage Footer
277
271
 
278
272
  ;.DrawDebugGrid
279
- .SAVEpdF ./documentation/Documentation.pdf
273
+ .SAVEpdF ./Documentation.pdf
280
274
  .WriteLog info Documentation has been generated.
@@ -45,8 +45,9 @@ endobj
45
45
  endobj
46
46
  6 0 obj
47
47
  <<
48
- /Producer (jsPDF 2.5.2)
49
- /CreationDate (D:20241006151126+10'00')
48
+ /Producer (jsPDF 4.1.0)
49
+ /Creator (jsPdf-Dynamo)
50
+ /CreationDate (D:20260205101406+11'00')
50
51
  >>
51
52
  endobj
52
53
  7 0 obj
@@ -66,14 +67,14 @@ xref
66
67
  0000000152 00000 n
67
68
  0000000470 00000 n
68
69
  0000000704 00000 n
69
- 0000000789 00000 n
70
+ 0000000813 00000 n
70
71
  trailer
71
72
  <<
72
73
  /Size 8
73
74
  /Root 7 0 R
74
75
  /Info 6 0 R
75
- /ID [ <A4FE96B1D9C5D34C705DDBFDD4170A74> <A4FE96B1D9C5D34C705DDBFDD4170A74> ]
76
+ /ID [ <6F3B78A493C9BF1EDA9BB278B0829F9E> <6F3B78A493C9BF1EDA9BB278B0829F9E> ]
76
77
  >>
77
78
  startxref
78
- 892
79
+ 916
79
80
  %%EOF
@@ -1,8 +1,8 @@
1
1
  import { expect, it, describe } from "vitest";
2
- import { JsPdfDynamo } from "../src/jsPdfDynamo";
2
+ import { JsPdfDynamo } from "../../src/jsPdfDynamo";
3
3
 
4
- describe("app", () => {
5
- it("1. Simple", async () => {
4
+ describe("1. Simple example", () => {
5
+ it("Create", async () => {
6
6
  const pdfDynamo = new JsPdfDynamo({
7
7
  pageSize: "a4",
8
8
  orientation: "portrait",
Binary file
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "jspdf-dynamo",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Generate data driven PDFs from dynamic templates",
5
- "main": "dist/index.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
6
8
  "repository": {
7
9
  "type": "git",
8
- "url": "git+https://github.com/SteveCorbett/jsPdf-Dynamo"
10
+ "url": "git+https://github.com/SteveCorbett/jsPdf-Dynamo.git"
9
11
  },
10
12
  "bugs": {
11
13
  "url": "https://github.com/SteveCorbett/jsPdf-Dynamo/issues"
@@ -13,8 +15,8 @@
13
15
  "scripts": {
14
16
  "build": "tsup",
15
17
  "build-docs": "vitest --dir ./documentation run",
16
- "check-exports": "attw --pack . ",
17
- "ci": "npm run test && npm run lint && npm run build && npm run check-format && npm run check-exports ",
18
+ "check-exports": "npm pack && attw \"$(ls *.tgz | head -n 1)\" && rm -f *.tgz",
19
+ "ci": "npm run test && npm run lint && npm run build && npm run check-format && ( [ \"$npm_config_dry_run\" = \"true\" ] && echo \"Skipping check-exports in dry-run\" || npm run check-exports )",
18
20
  "examples": "vitest --dir ./examples run",
19
21
  "format": "prettier --write .",
20
22
  "lint": "tsc",
@@ -33,7 +35,7 @@
33
35
  "author": "Stephen Corbett <corbett@corbtech.com.au> (https://corbtech.com.au)",
34
36
  "license": "MIT",
35
37
  "dependencies": {
36
- "jspdf": "^2.5.2"
38
+ "jspdf": "^4.1.0"
37
39
  },
38
40
  "devDependencies": {
39
41
  "@arethetypeswrong/cli": "^0.15.4",
@@ -44,11 +46,12 @@
44
46
  "tslog": "^4.9.3",
45
47
  "tsup": "^8.2.4",
46
48
  "typescript": "^5.5.4",
47
- "vitest": "^2.1.1"
49
+ "vitest": "^4.0.18"
48
50
  },
49
51
  "files": [
50
52
  "dist",
51
53
  "documentation",
54
+ "Documentation.pdf",
52
55
  "examples",
53
56
  "README.md",
54
57
  "LICENSE"
@@ -58,7 +61,7 @@
58
61
  "./package.json": "./package.json",
59
62
  ".": {
60
63
  "import": "./dist/index.js",
61
- "default": "./dist/index.cjs"
64
+ "require": "./dist/index.cjs"
62
65
  }
63
66
  }
64
67
  }
Binary file
@@ -1,7 +0,0 @@
1
- ## How to build the documentation
2
-
3
- The documentation for jsPdfDynamo is built using jsPdfDynamo. Once the project dependencies have been restored, run the following command:
4
-
5
- ```
6
- npm run build-docs
7
- ```
@@ -1,22 +0,0 @@
1
- import { expect, it, describe } from "vitest";
2
- import { JsPdfDynamo } from "../src/jsPdfDynamo";
3
- import { Logger } from "tslog";
4
- import { ILogger } from "../src/models/logger";
5
-
6
- describe("Build the documentation", () => {
7
- it("should build", async () => {
8
- const logger: ILogger = new Logger({
9
- name: "jspdf-dynamo",
10
- minLevel: 0,
11
- type: "pretty",
12
- });
13
- const pdfDynamo = new JsPdfDynamo(
14
- { pageSize: "a4", orientation: "portrait" },
15
- logger,
16
- );
17
- await pdfDynamo.processCommands([
18
- ".include ./documentation/documentation.txt",
19
- ]);
20
- expect(true).toBe(true);
21
- });
22
- });