pdfxml 0.1.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 (172) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/CONTRIBUTING.md +152 -0
  3. package/LICENSE +201 -0
  4. package/README.md +140 -0
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +23 -0
  8. package/dist/lib/common/applyBoxStyle.d.ts +3 -0
  9. package/dist/lib/common/applyBoxStyle.d.ts.map +1 -0
  10. package/dist/lib/common/applyBoxStyle.js +38 -0
  11. package/dist/lib/common/applyTextStyle.d.ts +3 -0
  12. package/dist/lib/common/applyTextStyle.d.ts.map +1 -0
  13. package/dist/lib/common/applyTextStyle.js +46 -0
  14. package/dist/lib/common/calculateTableColumnWidths.d.ts +3 -0
  15. package/dist/lib/common/calculateTableColumnWidths.d.ts.map +1 -0
  16. package/dist/lib/common/calculateTableColumnWidths.js +57 -0
  17. package/dist/lib/common/cmToPt.d.ts +2 -0
  18. package/dist/lib/common/cmToPt.d.ts.map +1 -0
  19. package/dist/lib/common/cmToPt.js +35 -0
  20. package/dist/lib/common/extractTableRows.d.ts +3 -0
  21. package/dist/lib/common/extractTableRows.d.ts.map +1 -0
  22. package/dist/lib/common/extractTableRows.js +43 -0
  23. package/dist/lib/common/getFontName.d.ts +2 -0
  24. package/dist/lib/common/getFontName.d.ts.map +1 -0
  25. package/dist/lib/common/getFontName.js +33 -0
  26. package/dist/lib/common/getMargin.d.ts +8 -0
  27. package/dist/lib/common/getMargin.d.ts.map +1 -0
  28. package/dist/lib/common/getMargin.js +30 -0
  29. package/dist/lib/common/getPadding.d.ts +8 -0
  30. package/dist/lib/common/getPadding.d.ts.map +1 -0
  31. package/dist/lib/common/getPadding.js +31 -0
  32. package/dist/lib/common/getSvgSize.d.ts +5 -0
  33. package/dist/lib/common/getSvgSize.d.ts.map +1 -0
  34. package/dist/lib/common/getSvgSize.js +40 -0
  35. package/dist/lib/common/mergeProps.d.ts +3 -0
  36. package/dist/lib/common/mergeProps.d.ts.map +1 -0
  37. package/dist/lib/common/mergeProps.js +27 -0
  38. package/dist/lib/common/normalize.d.ts +3 -0
  39. package/dist/lib/common/normalize.d.ts.map +1 -0
  40. package/dist/lib/common/normalize.js +67 -0
  41. package/dist/lib/common/parseInlineMarkdown.d.ts +3 -0
  42. package/dist/lib/common/parseInlineMarkdown.d.ts.map +1 -0
  43. package/dist/lib/common/parseInlineMarkdown.js +65 -0
  44. package/dist/lib/common/prepareText.d.ts +3 -0
  45. package/dist/lib/common/prepareText.d.ts.map +1 -0
  46. package/dist/lib/common/prepareText.js +38 -0
  47. package/dist/lib/common/resolveSize.d.ts +2 -0
  48. package/dist/lib/common/resolveSize.d.ts.map +1 -0
  49. package/dist/lib/common/resolveSize.js +42 -0
  50. package/dist/lib/common/truncateWithEllipsis.d.ts +2 -0
  51. package/dist/lib/common/truncateWithEllipsis.d.ts.map +1 -0
  52. package/dist/lib/common/truncateWithEllipsis.js +42 -0
  53. package/dist/lib/constants.d.ts +2 -0
  54. package/dist/lib/constants.d.ts.map +1 -0
  55. package/dist/lib/constants.js +22 -0
  56. package/dist/lib/measure/measureFlex.d.ts +3 -0
  57. package/dist/lib/measure/measureFlex.d.ts.map +1 -0
  58. package/dist/lib/measure/measureFlex.js +91 -0
  59. package/dist/lib/measure/measureImage.d.ts +3 -0
  60. package/dist/lib/measure/measureImage.d.ts.map +1 -0
  61. package/dist/lib/measure/measureImage.js +37 -0
  62. package/dist/lib/measure/measureNode.d.ts +3 -0
  63. package/dist/lib/measure/measureNode.d.ts.map +1 -0
  64. package/dist/lib/measure/measureNode.js +54 -0
  65. package/dist/lib/measure/measureTable.d.ts +3 -0
  66. package/dist/lib/measure/measureTable.d.ts.map +1 -0
  67. package/dist/lib/measure/measureTable.js +46 -0
  68. package/dist/lib/measure/measureTableCell.d.ts +3 -0
  69. package/dist/lib/measure/measureTableCell.d.ts.map +1 -0
  70. package/dist/lib/measure/measureTableCell.js +57 -0
  71. package/dist/lib/measure/measureText.d.ts +3 -0
  72. package/dist/lib/measure/measureText.d.ts.map +1 -0
  73. package/dist/lib/measure/measureText.js +62 -0
  74. package/dist/lib/pdf.d.ts +3 -0
  75. package/dist/lib/pdf.d.ts.map +1 -0
  76. package/dist/lib/pdf.js +106 -0
  77. package/dist/lib/render/measureSvg.d.ts +3 -0
  78. package/dist/lib/render/measureSvg.d.ts.map +1 -0
  79. package/dist/lib/render/measureSvg.js +30 -0
  80. package/dist/lib/render/renderBarCode.d.ts +3 -0
  81. package/dist/lib/render/renderBarCode.d.ts.map +1 -0
  82. package/dist/lib/render/renderBarCode.js +53 -0
  83. package/dist/lib/render/renderFlex.d.ts +3 -0
  84. package/dist/lib/render/renderFlex.d.ts.map +1 -0
  85. package/dist/lib/render/renderFlex.js +148 -0
  86. package/dist/lib/render/renderImage.d.ts +3 -0
  87. package/dist/lib/render/renderImage.d.ts.map +1 -0
  88. package/dist/lib/render/renderImage.js +41 -0
  89. package/dist/lib/render/renderNode.d.ts +3 -0
  90. package/dist/lib/render/renderNode.d.ts.map +1 -0
  91. package/dist/lib/render/renderNode.js +53 -0
  92. package/dist/lib/render/renderPage.d.ts +3 -0
  93. package/dist/lib/render/renderPage.d.ts.map +1 -0
  94. package/dist/lib/render/renderPage.js +36 -0
  95. package/dist/lib/render/renderQrCode.d.ts +3 -0
  96. package/dist/lib/render/renderQrCode.d.ts.map +1 -0
  97. package/dist/lib/render/renderQrCode.js +45 -0
  98. package/dist/lib/render/renderSvg.d.ts +3 -0
  99. package/dist/lib/render/renderSvg.d.ts.map +1 -0
  100. package/dist/lib/render/renderSvg.js +74 -0
  101. package/dist/lib/render/renderTable.d.ts +3 -0
  102. package/dist/lib/render/renderTable.d.ts.map +1 -0
  103. package/dist/lib/render/renderTable.js +159 -0
  104. package/dist/lib/render/renderTableCell.d.ts +3 -0
  105. package/dist/lib/render/renderTableCell.d.ts.map +1 -0
  106. package/dist/lib/render/renderTableCell.js +70 -0
  107. package/dist/lib/render/renderText.d.ts +3 -0
  108. package/dist/lib/render/renderText.d.ts.map +1 -0
  109. package/dist/lib/render/renderText.js +102 -0
  110. package/dist/lib/types/BaseProps.d.ts +51 -0
  111. package/dist/lib/types/BaseProps.d.ts.map +1 -0
  112. package/dist/lib/types/BaseProps.js +20 -0
  113. package/dist/lib/types/FlexAlign.d.ts +2 -0
  114. package/dist/lib/types/FlexAlign.d.ts.map +1 -0
  115. package/dist/lib/types/FlexAlign.js +20 -0
  116. package/dist/lib/types/HorizontalTextAlignment.d.ts +2 -0
  117. package/dist/lib/types/HorizontalTextAlignment.d.ts.map +1 -0
  118. package/dist/lib/types/HorizontalTextAlignment.js +20 -0
  119. package/dist/lib/types/LayoutBox.d.ts +7 -0
  120. package/dist/lib/types/LayoutBox.d.ts.map +1 -0
  121. package/dist/lib/types/LayoutBox.js +20 -0
  122. package/dist/lib/types/LineBreakMode.d.ts +2 -0
  123. package/dist/lib/types/LineBreakMode.d.ts.map +1 -0
  124. package/dist/lib/types/LineBreakMode.js +20 -0
  125. package/dist/lib/types/MarginOptions.d.ts +7 -0
  126. package/dist/lib/types/MarginOptions.d.ts.map +1 -0
  127. package/dist/lib/types/MarginOptions.js +20 -0
  128. package/dist/lib/types/NodeElement.d.ts +7 -0
  129. package/dist/lib/types/NodeElement.d.ts.map +1 -0
  130. package/dist/lib/types/NodeElement.js +20 -0
  131. package/dist/lib/types/PaperFormat.d.ts +12 -0
  132. package/dist/lib/types/PaperFormat.d.ts.map +1 -0
  133. package/dist/lib/types/PaperFormat.js +33 -0
  134. package/dist/lib/types/PdfOptions.d.ts +10 -0
  135. package/dist/lib/types/PdfOptions.d.ts.map +1 -0
  136. package/dist/lib/types/PdfOptions.js +20 -0
  137. package/dist/lib/types/TextSegment.d.ts +7 -0
  138. package/dist/lib/types/TextSegment.d.ts.map +1 -0
  139. package/dist/lib/types/TextSegment.js +20 -0
  140. package/dist/lib/types/TextTransform.d.ts +2 -0
  141. package/dist/lib/types/TextTransform.d.ts.map +1 -0
  142. package/dist/lib/types/TextTransform.js +20 -0
  143. package/dist/lib/types/TextType.d.ts +2 -0
  144. package/dist/lib/types/TextType.d.ts.map +1 -0
  145. package/dist/lib/types/TextType.js +20 -0
  146. package/dist/lib/types/VerticalTextAlignment.d.ts +2 -0
  147. package/dist/lib/types/VerticalTextAlignment.d.ts.map +1 -0
  148. package/dist/lib/types/VerticalTextAlignment.js +20 -0
  149. package/dist/lib/types/index.d.ts +14 -0
  150. package/dist/lib/types/index.d.ts.map +1 -0
  151. package/dist/lib/types/index.js +23 -0
  152. package/dist/program.d.ts +5 -0
  153. package/dist/program.d.ts.map +1 -0
  154. package/dist/program.js +116 -0
  155. package/package.json +76 -0
  156. package/singleton/Courier-Bold.afm +342 -0
  157. package/singleton/Courier-BoldOblique.afm +342 -0
  158. package/singleton/Courier-Oblique.afm +342 -0
  159. package/singleton/Courier.afm +342 -0
  160. package/singleton/Helvetica-Bold.afm +2827 -0
  161. package/singleton/Helvetica-BoldOblique.afm +2827 -0
  162. package/singleton/Helvetica-Oblique.afm +3051 -0
  163. package/singleton/Helvetica.afm +3051 -0
  164. package/singleton/Symbol.afm +213 -0
  165. package/singleton/Times-Bold.afm +2588 -0
  166. package/singleton/Times-BoldItalic.afm +2384 -0
  167. package/singleton/Times-Italic.afm +2667 -0
  168. package/singleton/Times-Roman.afm +2419 -0
  169. package/singleton/ZapfDingbats.afm +225 -0
  170. package/singleton/index.js +101612 -0
  171. package/singleton/sRGB_IEC61966_2_1.icc +0 -0
  172. package/tsconfig.json +12 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.renderBarCode = renderBarCode;
25
+ const getPadding_1 = require("../common/getPadding");
26
+ const resolveSize_1 = require("../common/resolveSize");
27
+ const bwip_js_1 = __importDefault(require("bwip-js"));
28
+ async function renderBarCode(doc, node, box) {
29
+ const value = (node.props.Value || '').toString();
30
+ const padding = (0, getPadding_1.getPadding)(node.props);
31
+ let width = (0, resolveSize_1.resolveSize)(node.props.Width, box.width) ?? (node.props.FillWidth
32
+ ? box.width
33
+ : 200);
34
+ if (node.props.FillWidth && padding.left) {
35
+ width -= padding.left;
36
+ }
37
+ if (node.props.FillWidth && padding.right) {
38
+ width -= padding.right;
39
+ }
40
+ const height = (0, resolveSize_1.resolveSize)(node.props.Height || 50, box.height) ?? (node.props.Height || 50);
41
+ const png = await bwip_js_1.default.toBuffer({
42
+ bcid: 'code128',
43
+ text: value,
44
+ scale: 3,
45
+ height: height,
46
+ includetext: false,
47
+ });
48
+ doc.image(png, box.x, box.y, {
49
+ width,
50
+ height,
51
+ });
52
+ return height;
53
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderFlex(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderFlex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderFlex.d.ts","sourceRoot":"","sources":["../../../lib/render/renderFlex.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGjD,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CA4NjB"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renderFlex = renderFlex;
22
+ const applyBoxStyle_1 = require("../common/applyBoxStyle");
23
+ const cmToPt_1 = require("../common/cmToPt");
24
+ const getMargin_1 = require("../common/getMargin");
25
+ const getPadding_1 = require("../common/getPadding");
26
+ const resolveSize_1 = require("../common/resolveSize");
27
+ const measureNode_1 = require("../measure/measureNode");
28
+ const renderNode_1 = require("./renderNode");
29
+ async function renderFlex(doc, node, box) {
30
+ const isRow = node.type === 'Row';
31
+ const padding = (0, getPadding_1.getPadding)(node.props);
32
+ const gap = (0, cmToPt_1.cmToPt)(node.props.Gap || 0);
33
+ const innerX = box.x + padding.left;
34
+ const innerY = box.y + padding.top;
35
+ const innerWidth = box.width -
36
+ padding.left -
37
+ padding.right;
38
+ const childNodes = node.children.filter((c) => typeof c !== 'string');
39
+ if (childNodes.length === 0) {
40
+ let lineHeight = node.props.Height ||
41
+ node.props.BorderWidth ||
42
+ 1;
43
+ if (node.props.MarginBottom)
44
+ lineHeight += node.props.MarginBottom;
45
+ if (node.props.BorderColor) {
46
+ doc.save();
47
+ doc
48
+ .lineWidth(node.props.BorderWidth || 1)
49
+ .strokeColor(node.props.BorderColor)
50
+ .moveTo(box.x, box.y)
51
+ .lineTo(box.x + box.width, box.y)
52
+ .stroke();
53
+ doc.restore();
54
+ }
55
+ return lineHeight;
56
+ }
57
+ const fixedWidths = childNodes.reduce((acc, child) => {
58
+ const margin = (0, getMargin_1.getMargin)(child.props);
59
+ if (isRow && child.props.Width) {
60
+ return (acc +
61
+ child.props.Width +
62
+ margin.left +
63
+ margin.right);
64
+ }
65
+ return acc;
66
+ }, 0);
67
+ const remainingWidth = innerWidth -
68
+ fixedWidths -
69
+ gap *
70
+ Math.max(childNodes.length - 1, 0);
71
+ const flexibleChildren = childNodes.filter((child) => isRow && !child.props.Width);
72
+ const flexWidth = flexibleChildren.length > 0
73
+ ? remainingWidth /
74
+ flexibleChildren.length
75
+ : remainingWidth;
76
+ let cursorX = innerX;
77
+ let cursorY = innerY;
78
+ let contentHeight = 0;
79
+ const renderedChildren = [];
80
+ for (const child of childNodes) {
81
+ const margin = (0, getMargin_1.getMargin)(child.props);
82
+ const resolvedWidth = (0, resolveSize_1.resolveSize)(child.props.Width, innerWidth);
83
+ const childWidth = isRow
84
+ ? resolvedWidth ?? flexWidth
85
+ : resolvedWidth ?? innerWidth;
86
+ const finalWidth = childWidth -
87
+ margin.left -
88
+ margin.right;
89
+ const childHeight = (0, resolveSize_1.resolveSize)(child.props.Height, box.height) ??
90
+ await (0, measureNode_1.measureNode)(doc, child, {
91
+ x: cursorX + margin.left,
92
+ y: cursorY + margin.top,
93
+ width: finalWidth,
94
+ height: box.height,
95
+ });
96
+ renderedChildren.push({
97
+ node: child,
98
+ box: {
99
+ x: cursorX + margin.left,
100
+ y: cursorY + margin.top,
101
+ width: finalWidth,
102
+ height: childHeight,
103
+ },
104
+ });
105
+ if (isRow) {
106
+ cursorX +=
107
+ childWidth +
108
+ margin.left +
109
+ margin.right +
110
+ gap;
111
+ contentHeight = Math.max(contentHeight, childHeight +
112
+ margin.top +
113
+ margin.bottom);
114
+ }
115
+ else {
116
+ cursorY +=
117
+ childHeight +
118
+ margin.top +
119
+ margin.bottom +
120
+ gap;
121
+ contentHeight +=
122
+ childHeight +
123
+ margin.top +
124
+ margin.bottom;
125
+ }
126
+ }
127
+ if (!isRow) {
128
+ contentHeight +=
129
+ gap *
130
+ Math.max(childNodes.length - 1, 0);
131
+ }
132
+ const finalHeight = (0, resolveSize_1.resolveSize)(node.props.Height, box.height) ??
133
+ (contentHeight +
134
+ padding.top +
135
+ padding.bottom);
136
+ (0, applyBoxStyle_1.applyBoxStyle)(doc, node, {
137
+ x: box.x,
138
+ y: box.y,
139
+ width: box.width,
140
+ height: finalHeight,
141
+ });
142
+ for (const item of renderedChildren) {
143
+ await (0, renderNode_1.renderNode)(doc, item.node, item.box);
144
+ }
145
+ //if (node.props.Height)
146
+ // finalHeight = resolveSize(node.props.Height, box.width) ?? finalHeight;
147
+ return finalHeight;
148
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderImage(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderImage.d.ts","sourceRoot":"","sources":["../../../lib/render/renderImage.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CA0CjB"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renderImage = renderImage;
22
+ const getPadding_1 = require("../common/getPadding");
23
+ const resolveSize_1 = require("../common/resolveSize");
24
+ async function renderImage(doc, node, box) {
25
+ const padding = (0, getPadding_1.getPadding)(node.props);
26
+ const source = node.props
27
+ .Source;
28
+ if (!source) {
29
+ return 0;
30
+ }
31
+ const input = Buffer.from(source, 'base64');
32
+ const width = (0, resolveSize_1.resolveSize)(node.props.Width, box.width) ?? 1;
33
+ const height = (0, resolveSize_1.resolveSize)(node.props.Height, box.height) ?? width;
34
+ doc.image(input, box.x + padding.left, box.y + padding.top, {
35
+ width,
36
+ height,
37
+ });
38
+ return (height +
39
+ padding.top +
40
+ padding.bottom);
41
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderNode(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderNode.d.ts","sourceRoot":"","sources":["../../../lib/render/renderNode.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAUjD,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAuCjB"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renderNode = renderNode;
22
+ const renderBarCode_1 = require("./renderBarCode");
23
+ const renderFlex_1 = require("./renderFlex");
24
+ const renderImage_1 = require("./renderImage");
25
+ const renderPage_1 = require("./renderPage");
26
+ const renderQrCode_1 = require("./renderQrCode");
27
+ const renderSvg_1 = require("./renderSvg");
28
+ const renderTable_1 = require("./renderTable");
29
+ const renderText_1 = require("./renderText");
30
+ async function renderNode(doc, node, box) {
31
+ switch (node.type) {
32
+ case 'Text':
33
+ return await (0, renderText_1.renderText)(doc, node, box);
34
+ case 'Column':
35
+ case 'Row':
36
+ return await (0, renderFlex_1.renderFlex)(doc, node, box);
37
+ case 'Table':
38
+ return await (0, renderTable_1.renderTable)(doc, node, box);
39
+ case 'Page':
40
+ return await (0, renderPage_1.renderPage)(doc, node, box);
41
+ case 'Svg':
42
+ return (0, renderSvg_1.renderSvg)(doc, node, box);
43
+ case 'Image':
44
+ return (0, renderImage_1.renderImage)(doc, node, box);
45
+ case 'QRCode':
46
+ case 'QrCode':
47
+ return await (0, renderQrCode_1.renderQrCode)(doc, node, box);
48
+ case 'BarCode':
49
+ return await (0, renderBarCode_1.renderBarCode)(doc, node, box);
50
+ default:
51
+ return 0;
52
+ }
53
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderPage(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderPage.d.ts","sourceRoot":"","sources":["../../../lib/render/renderPage.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGlD,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAuBjB"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renderPage = renderPage;
22
+ const renderNode_1 = require("./renderNode");
23
+ async function renderPage(doc, node, box) {
24
+ node.props.AutoPageBreak = false;
25
+ const content = node.children.filter((c) => typeof c !== 'string');
26
+ let usedHeight = 0;
27
+ for (const child of content) {
28
+ usedHeight += await (0, renderNode_1.renderNode)(doc, child, {
29
+ x: box.x,
30
+ y: box.y + usedHeight,
31
+ width: box.width,
32
+ height: box.height,
33
+ });
34
+ }
35
+ return usedHeight;
36
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderQrCode(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderQrCode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderQrCode.d.ts","sourceRoot":"","sources":["../../../lib/render/renderQrCode.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGjD,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAoCjB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.renderQrCode = renderQrCode;
25
+ const resolveSize_1 = require("../common/resolveSize");
26
+ const qrcode_1 = __importDefault(require("qrcode"));
27
+ async function renderQrCode(doc, node, box) {
28
+ const value = (node.props.Value || '').toString();
29
+ let size = (0, resolveSize_1.resolveSize)(node.props.Width ||
30
+ node.props.Height ||
31
+ 100, box.width) ?? (node.props.FillWidth
32
+ ? box.width
33
+ : 200);
34
+ const dataUrl = await qrcode_1.default.toDataURL(value, {
35
+ margin: 0,
36
+ width: size
37
+ });
38
+ const base64 = dataUrl.replace(/^data:image\/png;base64,/, '');
39
+ const buffer = Buffer.from(base64, 'base64');
40
+ doc.image(buffer, box.x, box.y, {
41
+ width: size,
42
+ height: size,
43
+ });
44
+ return size;
45
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderSvg(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): number;
3
+ //# sourceMappingURL=renderSvg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSvg.d.ts","sourceRoot":"","sources":["../../../lib/render/renderSvg.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,MAAM,CAwFR"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.renderSvg = renderSvg;
25
+ const svg_to_pdfkit_1 = __importDefault(require("svg-to-pdfkit"));
26
+ const getPadding_1 = require("../common/getPadding");
27
+ const getSvgSize_1 = require("../common/getSvgSize");
28
+ const resolveSize_1 = require("../common/resolveSize");
29
+ function renderSvg(doc, node, box) {
30
+ const padding = (0, getPadding_1.getPadding)(node.props);
31
+ let svg = '';
32
+ const source = node.props
33
+ .Source;
34
+ if (source) {
35
+ svg = Buffer.from(source, 'base64').toString('utf8');
36
+ }
37
+ else {
38
+ svg = node.children
39
+ .filter((x) => typeof x === 'string')
40
+ .join('\n');
41
+ }
42
+ const original = (0, getSvgSize_1.getSvgSize)(svg);
43
+ let width = (0, resolveSize_1.resolveSize)(node.props.Width, box.width) ?? 1;
44
+ let height = (0, resolveSize_1.resolveSize)(node.props.Height, box.height) ?? width;
45
+ // if (width && !height) {
46
+ // height =
47
+ // original.height *
48
+ // (width / original.width)
49
+ // }
50
+ // if (height && !width) {
51
+ // width =
52
+ // original.width *
53
+ // (height / original.height)
54
+ // }
55
+ // if (!width) {
56
+ // width = original.width
57
+ // }
58
+ // if (!height) {
59
+ // height = original.height
60
+ // }
61
+ const scaleX = width / original.width;
62
+ const scaleY = height / original.height;
63
+ doc.save();
64
+ doc.translate(box.x + padding.left, box.y + padding.top);
65
+ doc.scale(scaleX, scaleY);
66
+ (0, svg_to_pdfkit_1.default)(doc, svg, box.x + padding.left, box.y + padding.top, {
67
+ width,
68
+ height
69
+ });
70
+ doc.restore();
71
+ return (height +
72
+ padding.top +
73
+ padding.bottom);
74
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderTable(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderTable.d.ts","sourceRoot":"","sources":["../../../lib/render/renderTable.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGjD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CA2PjB"}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2026 josedinizdev
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ *
15
+ * Author: José Diogo Caetano Diniz
16
+ * GitHub: https://github.com/josedinizdev
17
+ * Project: https://github.com/josedinizdev/PDFXml
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.renderTable = renderTable;
22
+ const applyBoxStyle_1 = require("../common/applyBoxStyle");
23
+ const calculateTableColumnWidths_1 = require("../common/calculateTableColumnWidths");
24
+ const extractTableRows_1 = require("../common/extractTableRows");
25
+ const measureTableCell_1 = require("../measure/measureTableCell");
26
+ const renderTableCell_1 = require("./renderTableCell");
27
+ async function renderTable(doc, node, box) {
28
+ const padding = node.props.Padding || 0;
29
+ const innerBox = {
30
+ x: box.x + padding,
31
+ y: box.y + padding,
32
+ width: box.width - padding * 2,
33
+ height: box.height - padding * 2,
34
+ };
35
+ const rows = (0, extractTableRows_1.extractTableRows)(node);
36
+ const columnWidths = node.props.ColumnWidths ||
37
+ (0, calculateTableColumnWidths_1.calculateTableColumnWidths)(doc, rows, innerBox.width);
38
+ const pageBottom = doc.page.height -
39
+ doc.page.margins.bottom;
40
+ let cursorY = innerBox.y;
41
+ const head = node.children.find((c) => typeof c !== 'string' &&
42
+ c.type === 'THead');
43
+ const foot = node.children.find((c) => typeof c !== 'string' &&
44
+ c.type === 'TFoot');
45
+ let headerRows = [];
46
+ if (head) {
47
+ headerRows = head.children.filter((c) => typeof c !== 'string' &&
48
+ c.type === 'TRow');
49
+ }
50
+ let footerRows = [];
51
+ if (foot) {
52
+ footerRows = foot.children.filter((c) => typeof c !== 'string' &&
53
+ c.type === 'TRow');
54
+ }
55
+ const bodyRows = rows.filter((r) => (!head ||
56
+ !head.children.includes(r)) &&
57
+ (!foot ||
58
+ !foot.children.includes(r)));
59
+ const getRowHeight = async (row) => {
60
+ const cells = row.children.filter((c) => typeof c !== 'string');
61
+ let rowHeight = 0;
62
+ for (let i = 0; i < cells.length; i++) {
63
+ const cell = cells[i];
64
+ const width = columnWidths[i];
65
+ const measuredHeight = await (0, measureTableCell_1.measureTableCell)(doc, cell, {
66
+ x: 0,
67
+ y: 0,
68
+ width,
69
+ height: 99999,
70
+ });
71
+ rowHeight = Math.max(rowHeight, measuredHeight);
72
+ }
73
+ return rowHeight;
74
+ };
75
+ const renderRow = async (row, startY, section) => {
76
+ const cells = row.children.filter((c) => typeof c !== 'string');
77
+ const rowHeight = await getRowHeight(row);
78
+ // aplica background/border
79
+ // do THead/TFoot
80
+ if (section) {
81
+ (0, applyBoxStyle_1.applyBoxStyle)(doc, section, {
82
+ x: innerBox.x,
83
+ y: startY,
84
+ width: innerBox.width,
85
+ height: rowHeight,
86
+ });
87
+ }
88
+ let cursorX = innerBox.x;
89
+ for (let i = 0; i < cells.length; i++) {
90
+ await (0, renderTableCell_1.renderTableCell)(doc, cells[i], {
91
+ x: cursorX,
92
+ y: startY,
93
+ width: columnWidths[i],
94
+ height: rowHeight,
95
+ });
96
+ cursorX += columnWidths[i];
97
+ }
98
+ return startY + rowHeight;
99
+ };
100
+ const renderHeaders = async () => {
101
+ let headerCursorY = cursorY;
102
+ for (const headerRow of headerRows) {
103
+ const rowHeight = await getRowHeight(headerRow);
104
+ if (headerCursorY + rowHeight >
105
+ pageBottom &&
106
+ node.props.AutoPageBreak != false) {
107
+ doc.addPage();
108
+ headerCursorY =
109
+ doc.page.margins.top;
110
+ }
111
+ headerCursorY = await renderRow(headerRow, headerCursorY, head);
112
+ }
113
+ return headerCursorY;
114
+ };
115
+ if (headerRows.length > 0) {
116
+ cursorY = await renderHeaders();
117
+ }
118
+ let tableStartY = innerBox.y;
119
+ for (const row of bodyRows) {
120
+ const predictedHeight = await getRowHeight(row);
121
+ if (cursorY + predictedHeight >
122
+ pageBottom &&
123
+ node.props.AutoPageBreak != false) {
124
+ const tableHeight = cursorY - tableStartY;
125
+ (0, applyBoxStyle_1.applyBoxStyle)(doc, node, {
126
+ x: box.x,
127
+ y: tableStartY - padding,
128
+ width: box.width,
129
+ height: tableHeight + padding * 2,
130
+ });
131
+ doc.addPage();
132
+ cursorY = doc.page.margins.top;
133
+ tableStartY = cursorY;
134
+ if (headerRows.length > 0) {
135
+ cursorY = await renderHeaders();
136
+ }
137
+ }
138
+ cursorY = await renderRow(row, cursorY);
139
+ }
140
+ // render footer
141
+ for (const footerRow of footerRows) {
142
+ const rowHeight = await getRowHeight(footerRow);
143
+ if (cursorY + rowHeight >
144
+ pageBottom &&
145
+ node.props.AutoPageBreak != false) {
146
+ doc.addPage();
147
+ cursorY = doc.page.margins.top;
148
+ }
149
+ cursorY = await renderRow(footerRow, cursorY, foot);
150
+ }
151
+ const finalTableHeight = cursorY - tableStartY;
152
+ (0, applyBoxStyle_1.applyBoxStyle)(doc, node, {
153
+ x: box.x,
154
+ y: tableStartY - padding,
155
+ width: box.width,
156
+ height: finalTableHeight + padding * 2,
157
+ });
158
+ return finalTableHeight + padding * 2;
159
+ }