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,42 @@
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.truncateWithEllipsis = truncateWithEllipsis;
22
+ function truncateWithEllipsis(doc, text, maxWidth, characterSpacing = 0) {
23
+ const ellipsis = '...';
24
+ const ellipsisWidth = doc.widthOfString(ellipsis, {
25
+ characterSpacing,
26
+ });
27
+ if (doc.widthOfString(text, {
28
+ characterSpacing,
29
+ }) <= maxWidth) {
30
+ return text;
31
+ }
32
+ let result = text;
33
+ while (result.length > 0 &&
34
+ doc.widthOfString(result, {
35
+ characterSpacing,
36
+ }) +
37
+ ellipsisWidth >
38
+ maxWidth) {
39
+ result = result.slice(0, -1);
40
+ }
41
+ return result + ellipsis;
42
+ }
@@ -0,0 +1,2 @@
1
+ export declare const TEXT_VERTICAL_OFFSET = 0;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,oBAAoB,IAAI,CAAA"}
@@ -0,0 +1,22 @@
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.TEXT_VERTICAL_OFFSET = void 0;
22
+ exports.TEXT_VERTICAL_OFFSET = 0;
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureFlex(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=measureFlex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureFlex.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureFlex.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,CAuHjB"}
@@ -0,0 +1,91 @@
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.measureFlex = measureFlex;
22
+ const cmToPt_1 = require("../common/cmToPt");
23
+ const getMargin_1 = require("../common/getMargin");
24
+ const getPadding_1 = require("../common/getPadding");
25
+ const resolveSize_1 = require("../common/resolveSize");
26
+ const measureNode_1 = require("./measureNode");
27
+ async function measureFlex(doc, node, box) {
28
+ const isRow = node.type === 'Row';
29
+ const padding = (0, getPadding_1.getPadding)(node.props);
30
+ const gap = (0, cmToPt_1.cmToPt)(node.props.Gap || 0);
31
+ const innerWidth = box.width -
32
+ padding.left -
33
+ padding.right;
34
+ const childNodes = node.children.filter((c) => typeof c !== 'string');
35
+ const fixedWidths = childNodes.reduce((acc, child) => {
36
+ const margin = (0, getMargin_1.getMargin)(child.props);
37
+ if (isRow && child.props.Width) {
38
+ return (acc +
39
+ child.props.Width +
40
+ margin.left +
41
+ margin.right);
42
+ }
43
+ return acc;
44
+ }, 0);
45
+ const flexibleChildren = childNodes.filter((child) => isRow && !child.props.Width);
46
+ const remainingWidth = innerWidth -
47
+ fixedWidths -
48
+ gap *
49
+ (childNodes.length - 1);
50
+ const flexWidth = flexibleChildren.length > 0
51
+ ? remainingWidth /
52
+ flexibleChildren.length
53
+ : remainingWidth;
54
+ let usedHeight = 0;
55
+ for (const child of childNodes) {
56
+ const margin = (0, getMargin_1.getMargin)(child.props);
57
+ const resolvedWidth = (0, resolveSize_1.resolveSize)(child.props.Width, innerWidth);
58
+ const childWidth = isRow
59
+ ? resolvedWidth ?? flexWidth
60
+ : resolvedWidth ?? innerWidth;
61
+ const finalWidth = childWidth -
62
+ margin.left -
63
+ margin.right;
64
+ const measured = await (0, measureNode_1.measureNode)(doc, child, {
65
+ x: 0,
66
+ y: 0,
67
+ width: finalWidth,
68
+ height: box.height,
69
+ });
70
+ if (isRow) {
71
+ usedHeight = Math.max(usedHeight, measured +
72
+ margin.top +
73
+ margin.bottom);
74
+ }
75
+ else {
76
+ usedHeight +=
77
+ measured +
78
+ margin.top +
79
+ margin.bottom +
80
+ gap;
81
+ }
82
+ }
83
+ if (!isRow && childNodes.length > 0) {
84
+ usedHeight -= gap;
85
+ }
86
+ const measuredHeight = usedHeight +
87
+ padding.top +
88
+ padding.bottom;
89
+ return ((0, resolveSize_1.resolveSize)(node.props.Height, box.height) ??
90
+ measuredHeight);
91
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureImage(node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=measureImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureImage.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureImage.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,wBAAsB,YAAY,CAChC,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
@@ -0,0 +1,37 @@
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.measureImage = measureImage;
22
+ const getPadding_1 = require("../common/getPadding");
23
+ const resolveSize_1 = require("../common/resolveSize");
24
+ async function measureImage(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 buffer = Buffer.from(source.replace(/^data:.*?;base64,/, ''), '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
+ return (height +
35
+ padding.top +
36
+ padding.bottom);
37
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureNode(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=measureNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureNode.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureNode.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAMjD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CA+CjB"}
@@ -0,0 +1,54 @@
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.measureNode = measureNode;
22
+ const resolveSize_1 = require("../common/resolveSize");
23
+ const measureSvg_1 = require("../render/measureSvg");
24
+ const measureFlex_1 = require("./measureFlex");
25
+ const measureImage_1 = require("./measureImage");
26
+ const measureTable_1 = require("./measureTable");
27
+ const measureText_1 = require("./measureText");
28
+ async function measureNode(doc, node, box) {
29
+ const explicitHeight = (0, resolveSize_1.resolveSize)(node.props.Height, box.height);
30
+ if (explicitHeight !== undefined &&
31
+ explicitHeight > 0) {
32
+ return explicitHeight;
33
+ }
34
+ switch (node.type) {
35
+ case 'Text':
36
+ return (0, measureText_1.measureText)(doc, node, box);
37
+ case 'Row':
38
+ case 'Column':
39
+ return await (0, measureFlex_1.measureFlex)(doc, node, box);
40
+ case 'Table':
41
+ return await (0, measureTable_1.measureTable)(doc, node, box);
42
+ case 'Svg':
43
+ return (0, measureSvg_1.measureSvg)(node, box);
44
+ case 'Image':
45
+ return await (0, measureImage_1.measureImage)(node, box);
46
+ case 'QRCode':
47
+ case 'QrCode':
48
+ return node.props.Width || node.props.Height || 100;
49
+ case 'BarCode':
50
+ return node.props.Height || 50;
51
+ default:
52
+ return 0;
53
+ }
54
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureTable(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=measureTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureTable.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureTable.ts"],"names":[],"mappings":"AAqBA,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,CAyCjB"}
@@ -0,0 +1,46 @@
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.measureTable = measureTable;
22
+ const calculateTableColumnWidths_1 = require("../common/calculateTableColumnWidths");
23
+ const extractTableRows_1 = require("../common/extractTableRows");
24
+ const measureTableCell_1 = require("./measureTableCell");
25
+ async function measureTable(doc, node, box) {
26
+ const padding = node.props.Padding || 0;
27
+ const rows = (0, extractTableRows_1.extractTableRows)(node);
28
+ const columnWidths = node.props.ColumnWidths ||
29
+ (0, calculateTableColumnWidths_1.calculateTableColumnWidths)(doc, rows, box.width - padding * 2);
30
+ let totalHeight = 0;
31
+ for (const row of rows) {
32
+ const cells = row.children.filter((c) => typeof c !== 'string');
33
+ let rowHeight = 0;
34
+ for (let i = 0; i < cells.length; i++) {
35
+ const cell = cells[i];
36
+ rowHeight = Math.max(rowHeight, await (0, measureTableCell_1.measureTableCell)(doc, cell, {
37
+ x: 0,
38
+ y: 0,
39
+ width: columnWidths[i],
40
+ height: 99999,
41
+ }));
42
+ }
43
+ totalHeight += rowHeight;
44
+ }
45
+ return totalHeight + padding * 2;
46
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureTableCell(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=measureTableCell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureTableCell.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureTableCell.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAIjD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAgDjB"}
@@ -0,0 +1,57 @@
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.measureTableCell = measureTableCell;
22
+ const getPadding_1 = require("../common/getPadding");
23
+ const measureNode_1 = require("./measureNode");
24
+ const measureText_1 = require("./measureText");
25
+ async function measureTableCell(doc, node, box) {
26
+ const padding = (0, getPadding_1.getPadding)(node.props);
27
+ let usedHeight = 0;
28
+ for (const child of node.children) {
29
+ if (typeof child === 'string') {
30
+ const textNode = {
31
+ type: 'Text',
32
+ props: node.props,
33
+ children: [child],
34
+ };
35
+ usedHeight = Math.max(usedHeight, (0, measureText_1.measureText)(doc, textNode, {
36
+ x: 0,
37
+ y: 0,
38
+ width: box.width -
39
+ padding.left -
40
+ padding.right,
41
+ height: box.height,
42
+ }));
43
+ continue;
44
+ }
45
+ usedHeight = Math.max(usedHeight, await (0, measureNode_1.measureNode)(doc, child, {
46
+ x: 0,
47
+ y: 0,
48
+ width: box.width -
49
+ padding.left -
50
+ padding.right,
51
+ height: box.height,
52
+ }));
53
+ }
54
+ return (usedHeight +
55
+ padding.top +
56
+ padding.bottom);
57
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureText(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): number;
3
+ //# sourceMappingURL=measureText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureText.d.ts","sourceRoot":"","sources":["../../../lib/measure/measureText.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,MAAM,CA0DR"}
@@ -0,0 +1,62 @@
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.measureText = measureText;
22
+ const applyTextStyle_1 = require("../common/applyTextStyle");
23
+ const getPadding_1 = require("../common/getPadding");
24
+ const parseInlineMarkdown_1 = require("../common/parseInlineMarkdown");
25
+ const resolveSize_1 = require("../common/resolveSize");
26
+ const constants_1 = require("../constants");
27
+ function measureText(doc, node, box) {
28
+ const padding = (0, getPadding_1.getPadding)(node.props);
29
+ (0, applyTextStyle_1.applyTextStyle)(doc, node);
30
+ const rawText = node.children
31
+ .filter((c) => typeof c === 'string')
32
+ .join(' ');
33
+ const text = (0, parseInlineMarkdown_1.parseInlineMarkdown)(rawText)
34
+ .map((s) => s.text)
35
+ .join('');
36
+ const resolvedWidth = (0, resolveSize_1.resolveSize)(node.props.Width, box.width);
37
+ const innerWidth = (resolvedWidth ?? box.width)
38
+ - padding.left
39
+ - padding.right;
40
+ const noLineBreak = node.props.NoLineBreak === true;
41
+ let measuredHeight;
42
+ if (noLineBreak) {
43
+ measuredHeight =
44
+ doc.currentLineHeight();
45
+ }
46
+ else {
47
+ measuredHeight =
48
+ doc.heightOfString(text, {
49
+ width: innerWidth,
50
+ align: node.props
51
+ .HorizontalTextAlignment ||
52
+ 'left',
53
+ lineGap: node.props.LineHeight || 0,
54
+ characterSpacing: node.props
55
+ .CharacterSpacing || 0,
56
+ });
57
+ }
58
+ return (measuredHeight +
59
+ padding.top +
60
+ padding.bottom +
61
+ constants_1.TEXT_VERTICAL_OFFSET);
62
+ }
@@ -0,0 +1,3 @@
1
+ import { PdfOptions } from "./types";
2
+ export declare function pdf(xml: string, options?: PdfOptions): Promise<Buffer>;
3
+ //# sourceMappingURL=pdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../../lib/pdf.ts"],"names":[],"mappings":"AAoBA,OAAO,EAA4B,UAAU,EAAE,MAAM,SAAS,CAAC;AAQ/D,wBAAsB,GAAG,CACvB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,MAAM,CAAC,CA0GjB"}
@@ -0,0 +1,106 @@
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.pdf = pdf;
25
+ const fast_xml_parser_1 = require("fast-xml-parser");
26
+ const types_1 = require("./types");
27
+ const normalize_1 = require("./common/normalize");
28
+ const cmToPt_1 = require("./common/cmToPt");
29
+ const stream_1 = require("stream");
30
+ const pdfkit_1 = __importDefault(require("pdfkit"));
31
+ const renderPage_1 = require("./render/renderPage");
32
+ const renderNode_1 = require("./render/renderNode");
33
+ async function pdf(xml, options) {
34
+ xml = '<Column FillWidth="true">' + xml + '</Column>';
35
+ const parser = new fast_xml_parser_1.XMLParser({
36
+ ignoreAttributes: false,
37
+ attributeNamePrefix: '',
38
+ preserveOrder: true,
39
+ trimValues: true,
40
+ });
41
+ const parsed = parser.parse(xml);
42
+ const root = (0, normalize_1.normalize)(parsed);
43
+ const margins = {
44
+ top: (0, cmToPt_1.cmToPt)(options?.MarginOptions?.Top ?? '1cm'),
45
+ bottom: (0, cmToPt_1.cmToPt)(options?.MarginOptions?.Bottom ??
46
+ '1cm'),
47
+ left: (0, cmToPt_1.cmToPt)(options?.MarginOptions?.Left ?? '1cm'),
48
+ right: (0, cmToPt_1.cmToPt)(options?.MarginOptions?.Right ?? '1cm'),
49
+ };
50
+ //cmToPt
51
+ let size = options?.Format || types_1.PaperFormat.A4;
52
+ if (options?.Width && options?.Height) {
53
+ size = [(0, cmToPt_1.cmToPt)(options.Width), (0, cmToPt_1.cmToPt)(options.Height)];
54
+ }
55
+ const doc = new pdfkit_1.default({
56
+ size: size,
57
+ layout: options?.Landscape
58
+ ? 'landscape'
59
+ : 'portrait',
60
+ margins,
61
+ });
62
+ const chunks = [];
63
+ const writable = new stream_1.Writable({
64
+ write(chunk, _, callback) {
65
+ chunks.push(Buffer.from(chunk));
66
+ callback();
67
+ },
68
+ });
69
+ doc.pipe(writable);
70
+ const pages = root.children.filter((c) => typeof c !== 'string' &&
71
+ c.type === 'Page');
72
+ if (pages.length > 0) {
73
+ for (let page of pages) {
74
+ if (pages.indexOf(page) > 0)
75
+ doc.addPage();
76
+ await (0, renderPage_1.renderPage)(doc, page, {
77
+ x: margins.left,
78
+ y: margins.top,
79
+ width: doc.page.width -
80
+ margins.left -
81
+ margins.right,
82
+ height: doc.page.height -
83
+ margins.top -
84
+ margins.bottom,
85
+ });
86
+ }
87
+ }
88
+ else {
89
+ await (0, renderNode_1.renderNode)(doc, root, {
90
+ x: margins.left,
91
+ y: margins.top,
92
+ width: doc.page.width -
93
+ margins.left -
94
+ margins.right,
95
+ height: doc.page.height -
96
+ margins.top -
97
+ margins.bottom,
98
+ });
99
+ }
100
+ doc.end();
101
+ await new Promise((resolve) => {
102
+ writable.on('finish', () => resolve());
103
+ });
104
+ return Buffer.concat(chunks);
105
+ }
106
+ ``;
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function measureSvg(node: NodeElement, box: LayoutBox): number;
3
+ //# sourceMappingURL=measureSvg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureSvg.d.ts","sourceRoot":"","sources":["../../../lib/render/measureSvg.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,MAAM,CAcR"}
@@ -0,0 +1,30 @@
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.measureSvg = measureSvg;
22
+ const getPadding_1 = require("../common/getPadding");
23
+ const resolveSize_1 = require("../common/resolveSize");
24
+ function measureSvg(node, box) {
25
+ const padding = (0, getPadding_1.getPadding)(node.props);
26
+ const height = (0, resolveSize_1.resolveSize)(node.props.Height, box.height) ?? 100;
27
+ return (height +
28
+ padding.top +
29
+ padding.bottom);
30
+ }
@@ -0,0 +1,3 @@
1
+ import { LayoutBox, NodeElement } from "../types";
2
+ export declare function renderBarCode(doc: PDFKit.PDFDocument, node: NodeElement, box: LayoutBox): Promise<number>;
3
+ //# sourceMappingURL=renderBarCode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderBarCode.d.ts","sourceRoot":"","sources":["../../../lib/render/renderBarCode.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGlD,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,CAAC,WAAW,EACvB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CA+CjB"}