jspdf-dynamo 1.0.0

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 (66) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +93 -0
  3. package/dist/index.cjs +2175 -0
  4. package/dist/index.d.cts +370 -0
  5. package/dist/index.d.ts +370 -0
  6. package/dist/index.js +2145 -0
  7. package/documentation/1. Introduction/Introduction.txt +91 -0
  8. package/documentation/2. JsPdfDynamo/JsPdfDynamo.txt +6 -0
  9. package/documentation/2. JsPdfDynamo/constructor.txt +31 -0
  10. package/documentation/2. JsPdfDynamo/getVariable.txt +29 -0
  11. package/documentation/2. JsPdfDynamo/prepareWrappedString.txt +28 -0
  12. package/documentation/2. JsPdfDynamo/processCommands.txt +27 -0
  13. package/documentation/2. JsPdfDynamo/toBlob.txt +19 -0
  14. package/documentation/2. JsPdfDynamo/toBlobUrl.txt +36 -0
  15. package/documentation/3. Variables/Introduction.txt +36 -0
  16. package/documentation/3. Variables/SystemMaintained.txt +190 -0
  17. package/documentation/4. Commands/AddBookmark.txt +47 -0
  18. package/documentation/4. Commands/AddImageFromFile.txt +59 -0
  19. package/documentation/4. Commands/AddImageFromUrl.txt +63 -0
  20. package/documentation/4. Commands/AddPage.txt +40 -0
  21. package/documentation/4. Commands/CheckPage.txt +52 -0
  22. package/documentation/4. Commands/CopyVar.txt +52 -0
  23. package/documentation/4. Commands/Do.txt +40 -0
  24. package/documentation/4. Commands/DoRepeat.txt +51 -0
  25. package/documentation/4. Commands/DrawBox.txt +67 -0
  26. package/documentation/4. Commands/DrawDebugGrid.txt +41 -0
  27. package/documentation/4. Commands/DrawImage.txt +92 -0
  28. package/documentation/4. Commands/DrawLine.txt +62 -0
  29. package/documentation/4. Commands/DrawText.txt +61 -0
  30. package/documentation/4. Commands/DrawTextBox.txt +99 -0
  31. package/documentation/4. Commands/DrawTextWrapped.txt +65 -0
  32. package/documentation/4. Commands/ForEachPage.txt +44 -0
  33. package/documentation/4. Commands/GetEnvVar.txt +56 -0
  34. package/documentation/4. Commands/IfBlank.txt +63 -0
  35. package/documentation/4. Commands/IfGt.txt +58 -0
  36. package/documentation/4. Commands/IfNotBlank.txt +60 -0
  37. package/documentation/4. Commands/IncCurrentX.txt +52 -0
  38. package/documentation/4. Commands/IncCurrentY.txt +50 -0
  39. package/documentation/4. Commands/IncVar.txt +73 -0
  40. package/documentation/4. Commands/Include.txt +44 -0
  41. package/documentation/4. Commands/MultVar.txt +70 -0
  42. package/documentation/4. Commands/SetCurrentX.txt +37 -0
  43. package/documentation/4. Commands/SetCurrentY.txt +37 -0
  44. package/documentation/4. Commands/SetDocumentInfo.txt +35 -0
  45. package/documentation/4. Commands/SetFillColour.txt +58 -0
  46. package/documentation/4. Commands/SetFontName.txt +4 -0
  47. package/documentation/4. Commands/SetFontSize.txt +22 -0
  48. package/documentation/4. Commands/SetFontStyle.txt +55 -0
  49. package/documentation/4. Commands/SetLineColour.txt +58 -0
  50. package/documentation/4. Commands/SetLineWidth.txt +42 -0
  51. package/documentation/4. Commands/SetMargin.txt +69 -0
  52. package/documentation/4. Commands/SetPageOrientation.txt +42 -0
  53. package/documentation/4. Commands/SetVar.txt +69 -0
  54. package/documentation/5. Other Definitions/jsPdfOptions.txt +56 -0
  55. package/documentation/5. Other Definitions/logger.txt +35 -0
  56. package/documentation/5. Other Definitions/pageSizes.txt +41 -0
  57. package/documentation/6. Other/PossibleEnhancements.txt +63 -0
  58. package/documentation/6. Other/To Be Documented.txt +50 -0
  59. package/documentation/Documentation.pdf +9859 -0
  60. package/documentation/README.md +7 -0
  61. package/documentation/documentation.txt +266 -0
  62. package/documentation/gendoc.spec.ts +22 -0
  63. package/examples/1.Simple/simple.pdf +247 -0
  64. package/examples/1.Simple/template.txt +21 -0
  65. package/examples/examples.spec.ts +26 -0
  66. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT LICENSE
2
+ Copyright (c) 2024 Stephen Corbett
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # jsPdf-Dynamo
2
+
3
+ jsPdf-Dynamo is a wrapper around the open-source JavaScript PDF generation library, jsPDF. Using a
4
+ template driven approach, it enables the separation of layout and formatting logic from the placement of
5
+ data.
6
+
7
+ jsPdf-Dynamo can be used with browser or NodeJs JavaScript or TypeScript applications.
8
+
9
+ Advantages of using jsPdf-Dynamo include:
10
+
11
+ - The separation of layout and formatting logic from the placement of data. As a page is filled with data, jsPdf-Dynamo can insert new pages, with appropriate headings, footings, and bookmarks as required.
12
+ - The ability to store corporate and application wide format settings in templates that can be maintained independently from the application. This is similar to
13
+ the use of style sheets in web applications to enable visual consistency, reduce errors and minimise maintenance costs. These format settings can include colours, font styles and sizes, page headings, and more.
14
+
15
+ ## Install
16
+
17
+ Using npm:
18
+
19
+ ```sh
20
+ npm install jspdf --save
21
+ ```
22
+
23
+ Using yarn:
24
+
25
+ ```
26
+ yarn add jspdf
27
+ ```
28
+
29
+ ## Basic Concepts
30
+
31
+ There are a few basic concepts to be aware of when using jsPdf-Dynamo:
32
+
33
+ - The functionality of jsPdf-Dynamo is implemented through the JsPdfDynamo class.
34
+ - The initial page size, orientation and units 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 or NodeJs) or from local text files (NodeJs only).
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
+ - All measurements and positions are in the unit of measure specified when the instance
38
+ of JsPdfDynamo is created. This can be millimeters, inches, or points. The exception to this are fonts, which are always specified in points.
39
+ - A series of commands can be grouped and named. These groups of commands can then
40
+ be processed one or more times. This is a similar concept to methods or procedures
41
+ in more sophisticated computer languages.
42
+ - All commands, command group names and variable names are case insensitive.
43
+ - There are two kinds of variables, user variables and system maintained variables. User variables can be created and modified as required using script commands. As the name implies, system maintained variables are created and maintained and cannot be directly modified directly by script commands.
44
+
45
+ All commands are described in the documentation that can be found [here](./documentation/Documentation.pdf)
46
+
47
+ ## A Simple Example
48
+
49
+ In this example, there is a single template file, **`template.txt`**
50
+
51
+ ```
52
+ [Initialise]
53
+ .SetVar themeColour blue
54
+ .SetFontName helvetica
55
+ .SetSpaceVert = 0.3
56
+ .SetMargin a 10
57
+ .SetMargin b 15
58
+ [End]
59
+
60
+ [TitlePage]
61
+ .SetLineWidth 0.8
62
+ .SetLineColor %themeColour%
63
+ .DrawBox 0 0 %_PageWidth% %_PageHeight% 0
64
+ .SetFontSize 36
65
+ .SetTextColour %themeColour%
66
+ .SetFontStyle Bold
67
+ .DrawTextBox 0 0 %_PageWidth% %_PageHeight% center center %title%
68
+ [End]
69
+
70
+ [DrawPage]
71
+ .Do Initialise TitlePage
72
+ [End]
73
+ ```
74
+
75
+ The code to load this template, set the text of the title, process the commands, and save the document is:
76
+
77
+ ```TypeScript
78
+ import { JsPdfDynamo } from "jspdf-dynamo";
79
+
80
+ const commands = [
81
+ // Load the template
82
+ ".include path-to-template/template.txt",
83
+ // Set the title
84
+ ".SetVar title This is a title",
85
+ // Process the template
86
+ ".Do DrawPage",
87
+ // Save the pdf
88
+ ".SavePdf ./simple.pdf"
89
+ ];
90
+ await pdfDynamo.processCommands(commands);
91
+ ```
92
+
93
+ This, example can be found in the examples folder (additional examples to be added).