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.
- package/CHANGELOG.md +17 -0
- package/CONTRIBUTING.md +152 -0
- package/LICENSE +201 -0
- package/README.md +140 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/lib/common/applyBoxStyle.d.ts +3 -0
- package/dist/lib/common/applyBoxStyle.d.ts.map +1 -0
- package/dist/lib/common/applyBoxStyle.js +38 -0
- package/dist/lib/common/applyTextStyle.d.ts +3 -0
- package/dist/lib/common/applyTextStyle.d.ts.map +1 -0
- package/dist/lib/common/applyTextStyle.js +46 -0
- package/dist/lib/common/calculateTableColumnWidths.d.ts +3 -0
- package/dist/lib/common/calculateTableColumnWidths.d.ts.map +1 -0
- package/dist/lib/common/calculateTableColumnWidths.js +57 -0
- package/dist/lib/common/cmToPt.d.ts +2 -0
- package/dist/lib/common/cmToPt.d.ts.map +1 -0
- package/dist/lib/common/cmToPt.js +35 -0
- package/dist/lib/common/extractTableRows.d.ts +3 -0
- package/dist/lib/common/extractTableRows.d.ts.map +1 -0
- package/dist/lib/common/extractTableRows.js +43 -0
- package/dist/lib/common/getFontName.d.ts +2 -0
- package/dist/lib/common/getFontName.d.ts.map +1 -0
- package/dist/lib/common/getFontName.js +33 -0
- package/dist/lib/common/getMargin.d.ts +8 -0
- package/dist/lib/common/getMargin.d.ts.map +1 -0
- package/dist/lib/common/getMargin.js +30 -0
- package/dist/lib/common/getPadding.d.ts +8 -0
- package/dist/lib/common/getPadding.d.ts.map +1 -0
- package/dist/lib/common/getPadding.js +31 -0
- package/dist/lib/common/getSvgSize.d.ts +5 -0
- package/dist/lib/common/getSvgSize.d.ts.map +1 -0
- package/dist/lib/common/getSvgSize.js +40 -0
- package/dist/lib/common/mergeProps.d.ts +3 -0
- package/dist/lib/common/mergeProps.d.ts.map +1 -0
- package/dist/lib/common/mergeProps.js +27 -0
- package/dist/lib/common/normalize.d.ts +3 -0
- package/dist/lib/common/normalize.d.ts.map +1 -0
- package/dist/lib/common/normalize.js +67 -0
- package/dist/lib/common/parseInlineMarkdown.d.ts +3 -0
- package/dist/lib/common/parseInlineMarkdown.d.ts.map +1 -0
- package/dist/lib/common/parseInlineMarkdown.js +65 -0
- package/dist/lib/common/prepareText.d.ts +3 -0
- package/dist/lib/common/prepareText.d.ts.map +1 -0
- package/dist/lib/common/prepareText.js +38 -0
- package/dist/lib/common/resolveSize.d.ts +2 -0
- package/dist/lib/common/resolveSize.d.ts.map +1 -0
- package/dist/lib/common/resolveSize.js +42 -0
- package/dist/lib/common/truncateWithEllipsis.d.ts +2 -0
- package/dist/lib/common/truncateWithEllipsis.d.ts.map +1 -0
- package/dist/lib/common/truncateWithEllipsis.js +42 -0
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +22 -0
- package/dist/lib/measure/measureFlex.d.ts +3 -0
- package/dist/lib/measure/measureFlex.d.ts.map +1 -0
- package/dist/lib/measure/measureFlex.js +91 -0
- package/dist/lib/measure/measureImage.d.ts +3 -0
- package/dist/lib/measure/measureImage.d.ts.map +1 -0
- package/dist/lib/measure/measureImage.js +37 -0
- package/dist/lib/measure/measureNode.d.ts +3 -0
- package/dist/lib/measure/measureNode.d.ts.map +1 -0
- package/dist/lib/measure/measureNode.js +54 -0
- package/dist/lib/measure/measureTable.d.ts +3 -0
- package/dist/lib/measure/measureTable.d.ts.map +1 -0
- package/dist/lib/measure/measureTable.js +46 -0
- package/dist/lib/measure/measureTableCell.d.ts +3 -0
- package/dist/lib/measure/measureTableCell.d.ts.map +1 -0
- package/dist/lib/measure/measureTableCell.js +57 -0
- package/dist/lib/measure/measureText.d.ts +3 -0
- package/dist/lib/measure/measureText.d.ts.map +1 -0
- package/dist/lib/measure/measureText.js +62 -0
- package/dist/lib/pdf.d.ts +3 -0
- package/dist/lib/pdf.d.ts.map +1 -0
- package/dist/lib/pdf.js +106 -0
- package/dist/lib/render/measureSvg.d.ts +3 -0
- package/dist/lib/render/measureSvg.d.ts.map +1 -0
- package/dist/lib/render/measureSvg.js +30 -0
- package/dist/lib/render/renderBarCode.d.ts +3 -0
- package/dist/lib/render/renderBarCode.d.ts.map +1 -0
- package/dist/lib/render/renderBarCode.js +53 -0
- package/dist/lib/render/renderFlex.d.ts +3 -0
- package/dist/lib/render/renderFlex.d.ts.map +1 -0
- package/dist/lib/render/renderFlex.js +148 -0
- package/dist/lib/render/renderImage.d.ts +3 -0
- package/dist/lib/render/renderImage.d.ts.map +1 -0
- package/dist/lib/render/renderImage.js +41 -0
- package/dist/lib/render/renderNode.d.ts +3 -0
- package/dist/lib/render/renderNode.d.ts.map +1 -0
- package/dist/lib/render/renderNode.js +53 -0
- package/dist/lib/render/renderPage.d.ts +3 -0
- package/dist/lib/render/renderPage.d.ts.map +1 -0
- package/dist/lib/render/renderPage.js +36 -0
- package/dist/lib/render/renderQrCode.d.ts +3 -0
- package/dist/lib/render/renderQrCode.d.ts.map +1 -0
- package/dist/lib/render/renderQrCode.js +45 -0
- package/dist/lib/render/renderSvg.d.ts +3 -0
- package/dist/lib/render/renderSvg.d.ts.map +1 -0
- package/dist/lib/render/renderSvg.js +74 -0
- package/dist/lib/render/renderTable.d.ts +3 -0
- package/dist/lib/render/renderTable.d.ts.map +1 -0
- package/dist/lib/render/renderTable.js +159 -0
- package/dist/lib/render/renderTableCell.d.ts +3 -0
- package/dist/lib/render/renderTableCell.d.ts.map +1 -0
- package/dist/lib/render/renderTableCell.js +70 -0
- package/dist/lib/render/renderText.d.ts +3 -0
- package/dist/lib/render/renderText.d.ts.map +1 -0
- package/dist/lib/render/renderText.js +102 -0
- package/dist/lib/types/BaseProps.d.ts +51 -0
- package/dist/lib/types/BaseProps.d.ts.map +1 -0
- package/dist/lib/types/BaseProps.js +20 -0
- package/dist/lib/types/FlexAlign.d.ts +2 -0
- package/dist/lib/types/FlexAlign.d.ts.map +1 -0
- package/dist/lib/types/FlexAlign.js +20 -0
- package/dist/lib/types/HorizontalTextAlignment.d.ts +2 -0
- package/dist/lib/types/HorizontalTextAlignment.d.ts.map +1 -0
- package/dist/lib/types/HorizontalTextAlignment.js +20 -0
- package/dist/lib/types/LayoutBox.d.ts +7 -0
- package/dist/lib/types/LayoutBox.d.ts.map +1 -0
- package/dist/lib/types/LayoutBox.js +20 -0
- package/dist/lib/types/LineBreakMode.d.ts +2 -0
- package/dist/lib/types/LineBreakMode.d.ts.map +1 -0
- package/dist/lib/types/LineBreakMode.js +20 -0
- package/dist/lib/types/MarginOptions.d.ts +7 -0
- package/dist/lib/types/MarginOptions.d.ts.map +1 -0
- package/dist/lib/types/MarginOptions.js +20 -0
- package/dist/lib/types/NodeElement.d.ts +7 -0
- package/dist/lib/types/NodeElement.d.ts.map +1 -0
- package/dist/lib/types/NodeElement.js +20 -0
- package/dist/lib/types/PaperFormat.d.ts +12 -0
- package/dist/lib/types/PaperFormat.d.ts.map +1 -0
- package/dist/lib/types/PaperFormat.js +33 -0
- package/dist/lib/types/PdfOptions.d.ts +10 -0
- package/dist/lib/types/PdfOptions.d.ts.map +1 -0
- package/dist/lib/types/PdfOptions.js +20 -0
- package/dist/lib/types/TextSegment.d.ts +7 -0
- package/dist/lib/types/TextSegment.d.ts.map +1 -0
- package/dist/lib/types/TextSegment.js +20 -0
- package/dist/lib/types/TextTransform.d.ts +2 -0
- package/dist/lib/types/TextTransform.d.ts.map +1 -0
- package/dist/lib/types/TextTransform.js +20 -0
- package/dist/lib/types/TextType.d.ts +2 -0
- package/dist/lib/types/TextType.d.ts.map +1 -0
- package/dist/lib/types/TextType.js +20 -0
- package/dist/lib/types/VerticalTextAlignment.d.ts +2 -0
- package/dist/lib/types/VerticalTextAlignment.d.ts.map +1 -0
- package/dist/lib/types/VerticalTextAlignment.js +20 -0
- package/dist/lib/types/index.d.ts +14 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +23 -0
- package/dist/program.d.ts +5 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +116 -0
- package/package.json +76 -0
- package/singleton/Courier-Bold.afm +342 -0
- package/singleton/Courier-BoldOblique.afm +342 -0
- package/singleton/Courier-Oblique.afm +342 -0
- package/singleton/Courier.afm +342 -0
- package/singleton/Helvetica-Bold.afm +2827 -0
- package/singleton/Helvetica-BoldOblique.afm +2827 -0
- package/singleton/Helvetica-Oblique.afm +3051 -0
- package/singleton/Helvetica.afm +3051 -0
- package/singleton/Symbol.afm +213 -0
- package/singleton/Times-Bold.afm +2588 -0
- package/singleton/Times-BoldItalic.afm +2384 -0
- package/singleton/Times-Italic.afm +2667 -0
- package/singleton/Times-Roman.afm +2419 -0
- package/singleton/ZapfDingbats.afm +225 -0
- package/singleton/index.js +101612 -0
- package/singleton/sRGB_IEC61966_2_1.icc +0 -0
- 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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/dist/lib/pdf.js
ADDED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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"}
|