@ind-rcg/plugins-printengine 250.1002.0 → 252.1008.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/dist/dev/printEngine.js +4 -4
- package/dist/dev/src/contractToIntermediateJSONClass.js +1 -1
- package/dist/dev/src/index.js +21 -10
- package/dist/dev/src/pdfConverterClass.js +73 -4
- package/dist/dev/src/printEngineParams.js +18 -2
- package/dist/prod/printEngine.js +1 -1
- package/package.json +1 -2
|
@@ -167,7 +167,7 @@ class ContractToIntermediateJSON {
|
|
|
167
167
|
let documentPropertiesRaw = _.find(printLayoutNode.elements, {name:DOCUMENT_PROPERTIES_NODE});
|
|
168
168
|
let documentProperties = this.__reformatDocumentProperties(documentPropertiesRaw);
|
|
169
169
|
|
|
170
|
-
return {"reportLayout": reportLayout, "documentProperties": documentProperties};
|
|
170
|
+
return {"reportLayout": reportLayout, "documentProperties": documentProperties, "printFont": params.getPrintFont() };
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
__processDivs(params) {
|
package/dist/dev/src/index.js
CHANGED
|
@@ -52,18 +52,29 @@ function __validateCommonParameters(contract, params, format){
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function __innerPrintLogic(printType, contract, params, _stream, format) {
|
|
55
|
+
function __innerPrintLogic(printType, contract, params, _stream, format, config) {
|
|
56
56
|
let json = contractParser.toJson(contract, params);
|
|
57
57
|
let pdfDefinition = pdfConverter.toPdfDefinition(json, format, testReportName);
|
|
58
|
-
|
|
59
58
|
switch (printType) {
|
|
60
59
|
case PRINT_TYPE.STREAM:
|
|
61
60
|
pdfConverter.writeToStream(pdfDefinition, _stream);
|
|
62
61
|
break;
|
|
63
62
|
|
|
64
63
|
case PRINT_TYPE.BLOB:
|
|
65
|
-
return
|
|
66
|
-
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
pdfConverter.toBlob(pdfDefinition).then((blobData)=>{
|
|
66
|
+
if(config && config.metaData === true){
|
|
67
|
+
resolve({
|
|
68
|
+
data: blobData,
|
|
69
|
+
pdfJson: json
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
resolve(blobData);
|
|
73
|
+
}
|
|
74
|
+
}, (err)=>{
|
|
75
|
+
reject(err);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
67
78
|
case PRINT_TYPE.DATA_URL:
|
|
68
79
|
return pdfConverter.toDataUrl(pdfDefinition);
|
|
69
80
|
|
|
@@ -73,25 +84,25 @@ function __innerPrintLogic(printType, contract, params, _stream, format) {
|
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
function printToStream(contract, params, _stream, format = "A4") {
|
|
87
|
+
function printToStream(contract, params, _stream, format = "A4", config = {}) {
|
|
77
88
|
// Validate parameters
|
|
78
89
|
if(!(_stream instanceof stream.Stream)) {
|
|
79
90
|
throw new TypeError("Not a valid stream.");
|
|
80
91
|
}
|
|
81
92
|
__validateCommonParameters(contract, params, format);
|
|
82
|
-
__innerPrintLogic(PRINT_TYPE.STREAM, contract, params, _stream, format);
|
|
93
|
+
__innerPrintLogic(PRINT_TYPE.STREAM, contract, params, _stream, format, config);
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
function printToDataUrl(contract, params, format = "A4") {
|
|
96
|
+
function printToDataUrl(contract, params, format = "A4", config = {}) {
|
|
86
97
|
// Validate parameters
|
|
87
98
|
__validateCommonParameters(contract, params, format);
|
|
88
|
-
return __innerPrintLogic(PRINT_TYPE.DATA_URL, contract, params, null, format);
|
|
99
|
+
return __innerPrintLogic(PRINT_TYPE.DATA_URL, contract, params, null, format, config);
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
function printToBlob(contract, params, format = "A4") {
|
|
102
|
+
function printToBlob(contract, params, format = "A4", config = {}) {
|
|
92
103
|
// Validate parameters
|
|
93
104
|
__validateCommonParameters(contract, params, format);
|
|
94
|
-
return __innerPrintLogic(PRINT_TYPE.BLOB, contract, params, null, format);
|
|
105
|
+
return __innerPrintLogic(PRINT_TYPE.BLOB, contract, params, null, format, config);
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
|
|
@@ -28,6 +28,12 @@ const BrowserFonts = {
|
|
|
28
28
|
bold: 'Roboto-Medium.ttf',
|
|
29
29
|
italics: 'Roboto-Italic.ttf',
|
|
30
30
|
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
31
|
+
},
|
|
32
|
+
PrintFont: {
|
|
33
|
+
normal: 'Regular',
|
|
34
|
+
bold: 'Bold',
|
|
35
|
+
italics: 'Italic',
|
|
36
|
+
bolditalics: 'BoldItalic'
|
|
31
37
|
}
|
|
32
38
|
};
|
|
33
39
|
|
|
@@ -96,6 +102,7 @@ class PdfConverter {
|
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
this.__format = new Format();
|
|
105
|
+
this.__pdfHeight = null;
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
__applyPageBreakData(pdfDefinition) {
|
|
@@ -206,7 +213,11 @@ class PdfConverter {
|
|
|
206
213
|
}
|
|
207
214
|
|
|
208
215
|
__getParagraphDefinition(paragraphNode, paragraphStyle) {
|
|
209
|
-
|
|
216
|
+
let text = '';
|
|
217
|
+
if (paragraphNode.elements) {
|
|
218
|
+
text = paragraphNode.elements[0].text;
|
|
219
|
+
}
|
|
220
|
+
return this.__createHeadingOrParagraphText(paragraphNode, text, paragraphStyle);
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
__getImageDefinition(imageNode, useAlignment) {
|
|
@@ -353,6 +364,10 @@ class PdfConverter {
|
|
|
353
364
|
let i = 0;
|
|
354
365
|
|
|
355
366
|
if (bAllowedStrings && _.isString(attribute)){
|
|
367
|
+
//the width can be given as a percentage only if the layout is 3-inch endless printer i.e, the height is auto
|
|
368
|
+
if(this.__pdfHeight === 'auto' && (/^\d+(\.\d+)?%$/).test(attribute)){
|
|
369
|
+
return attribute;
|
|
370
|
+
}
|
|
356
371
|
for (i=0; i<allowedStrings.length; i++) {
|
|
357
372
|
if (attribute === allowedStrings[i]) {
|
|
358
373
|
return attribute;
|
|
@@ -705,6 +720,17 @@ class PdfConverter {
|
|
|
705
720
|
}
|
|
706
721
|
}
|
|
707
722
|
|
|
723
|
+
__addPrintFont(definition, printFont) {
|
|
724
|
+
if (_.isObject(printFont)
|
|
725
|
+
&& ("Regular" in printFont)
|
|
726
|
+
&& ("Bold" in printFont)
|
|
727
|
+
&& ("Italic" in printFont)
|
|
728
|
+
&& ("BoldItalic" in printFont)) {
|
|
729
|
+
definition.defaultStyle.font = "PrintFont";
|
|
730
|
+
definition.printFont = printFont;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
708
734
|
__addDocumentMetadata(definition, documentProperties){
|
|
709
735
|
definition.info = {};
|
|
710
736
|
definition.info.creator = "Consumer Goods Cloud";
|
|
@@ -722,7 +748,21 @@ class PdfConverter {
|
|
|
722
748
|
|
|
723
749
|
__addPageDimensionsOrientationMarginsWatermark(definition, reportLayout){
|
|
724
750
|
if(!_.isNil(reportLayout.attributes) && !_.isNil(reportLayout.attributes.pageSize)){
|
|
725
|
-
|
|
751
|
+
if (/^\s*\[\s*\d+\s*,\s*(\d+|auto)\s*\]\s*$/.test(reportLayout.attributes.pageSize)) {
|
|
752
|
+
// pageSize is given as [width, height]
|
|
753
|
+
const [width, height] = reportLayout.attributes.pageSize
|
|
754
|
+
.replace(/\s/g, '') // remove whitespace
|
|
755
|
+
.replace('[', '').replace(']', '') //remove brackets
|
|
756
|
+
.split(',');
|
|
757
|
+
definition.pageSize = {
|
|
758
|
+
width : Number(width),
|
|
759
|
+
height: height === 'auto' ? height : Number(height)
|
|
760
|
+
};
|
|
761
|
+
this.__pdfHeight = height;
|
|
762
|
+
} else {
|
|
763
|
+
// assuming no other possibility for invalid pageSize format as it will be caught by during build
|
|
764
|
+
definition.pageSize = reportLayout.attributes.pageSize;
|
|
765
|
+
}
|
|
726
766
|
}
|
|
727
767
|
if(!_.isNil(reportLayout.attributes) && !_.isNil(reportLayout.attributes.watermark)){
|
|
728
768
|
definition.watermark = {text: reportLayout.attributes.watermark, opacity:0.1, fontSize: 120};
|
|
@@ -732,6 +772,27 @@ class PdfConverter {
|
|
|
732
772
|
}
|
|
733
773
|
}
|
|
734
774
|
|
|
775
|
+
__addStyles(definition, json) {
|
|
776
|
+
let stylesNode = _.find(json.elements, {name:"styles"});
|
|
777
|
+
if(_.isNil(stylesNode)) return;
|
|
778
|
+
for (const styleElement of stylesNode.elements) {
|
|
779
|
+
for (let [property, value] of Object.entries(styleElement.attributes)) {
|
|
780
|
+
// invalid formats will be caught during build
|
|
781
|
+
if (property === 'fontSize') {
|
|
782
|
+
value = Number(value);
|
|
783
|
+
} else if (property === 'bold' || property === 'italics') {
|
|
784
|
+
value = value === 'true' || value === '1';
|
|
785
|
+
} else if (property === 'margin') {
|
|
786
|
+
value = JSON.parse(value);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (property !== 'name') {
|
|
790
|
+
definition.styles[styleElement.attributes.name][property] = value;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
735
796
|
__isLastMainRowOnPage(followingNodesOnPage) {
|
|
736
797
|
let result = false;
|
|
737
798
|
|
|
@@ -926,10 +987,12 @@ class PdfConverter {
|
|
|
926
987
|
|
|
927
988
|
toPdfDefinition(json/*, format*/) {
|
|
928
989
|
this.__initializePdfDefinition();
|
|
990
|
+
this.__addPrintFont(this.__definition, json.printFont);
|
|
929
991
|
this.__addDocumentMetadata(this.__definition, json.documentProperties);
|
|
930
992
|
let reportLayout = json.reportLayout;
|
|
931
993
|
this.__configureAutomaticPageBreak(reportLayout);
|
|
932
994
|
this.__addPageDimensionsOrientationMarginsWatermark(this.__definition, reportLayout);
|
|
995
|
+
this.__addStyles(this.__definition, reportLayout);
|
|
933
996
|
this.__addHeader(this.__definition, reportLayout);
|
|
934
997
|
this.__addBody(this.__definition, reportLayout);
|
|
935
998
|
this.__addFooter(this.__definition,reportLayout);
|
|
@@ -1030,8 +1093,14 @@ class PdfConverter {
|
|
|
1030
1093
|
if (_.isNil(pdfDefinition) && !_.isNil(previousResult)) {
|
|
1031
1094
|
resolve(previousResult);
|
|
1032
1095
|
} else {
|
|
1033
|
-
let pdfDocGenerator =
|
|
1034
|
-
|
|
1096
|
+
let pdfDocGenerator = null;
|
|
1097
|
+
if (pdfDefinition.defaultStyle.font !== "PrintFont") {
|
|
1098
|
+
pdfDocGenerator = this.__pdfMake.createPdf(pdfDefinition, TableLayouts, BrowserFonts, BrowserFontsVfs.pdfMake.vfs);
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
pdfDocGenerator = this.__pdfMake.createPdf(pdfDefinition, TableLayouts, BrowserFonts, pdfDefinition.printFont);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1035
1104
|
switch (type) {
|
|
1036
1105
|
case EXPORT_TYPE.BASE_64:
|
|
1037
1106
|
pdfDocGenerator.getBase64((data) => {
|
|
@@ -10,7 +10,8 @@ const STORAGE_KEYS = {
|
|
|
10
10
|
"LOCALIZATION": "LOCALIZATION",
|
|
11
11
|
"IMAGES": "IMAGES",
|
|
12
12
|
"TOGGLES":"TOGGLES",
|
|
13
|
-
"METADATA": "METADATA"
|
|
13
|
+
"METADATA": "METADATA",
|
|
14
|
+
"PRINTFONT": "PRINTFONT"
|
|
14
15
|
};
|
|
15
16
|
Object.freeze(STORAGE_KEYS);
|
|
16
17
|
|
|
@@ -24,19 +25,21 @@ const DATATYPE_ERROR_MSG = "Wrong datatype.";
|
|
|
24
25
|
|
|
25
26
|
class PrintEngineParams {
|
|
26
27
|
|
|
27
|
-
constructor(bos = {}, images = {}, localization = {}, toggles = new ClassToggles({}), metadata = {}) {
|
|
28
|
+
constructor(bos = {}, images = {}, localization = {}, toggles = new ClassToggles({}), metadata = {}, printfont = {}) {
|
|
28
29
|
//Optional parameters for constructor via destructuring assignments including call without parameters.
|
|
29
30
|
this.__checkInputSetBOs(bos);
|
|
30
31
|
this.__checkInputSetImages(images);
|
|
31
32
|
this.__checkInputSetLocalization(localization);
|
|
32
33
|
this.__checkInputSetToggles(toggles);
|
|
33
34
|
this.__checkInputSetMetadata(metadata);
|
|
35
|
+
this.__checkInputSetPrintFont(printfont);
|
|
34
36
|
this.__internalStorage = {};
|
|
35
37
|
this.__internalStorage[STORAGE_KEYS.BOS] = bos;
|
|
36
38
|
this.__internalStorage[STORAGE_KEYS.IMAGES] = images;
|
|
37
39
|
this.__internalStorage[STORAGE_KEYS.LOCALIZATION] = localization;
|
|
38
40
|
this.__internalStorage[STORAGE_KEYS.TOGGLES] = toggles;
|
|
39
41
|
this.__internalStorage[STORAGE_KEYS.METADATA] = metadata;
|
|
42
|
+
this.__internalStorage[STORAGE_KEYS.PRINTFONT] = printfont;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
__checkInputSetBOs(boDictionary){
|
|
@@ -69,6 +72,19 @@ class PrintEngineParams {
|
|
|
69
72
|
this.__checkInputSetMetadata(metadataDictionary);
|
|
70
73
|
this.__internalStorage[STORAGE_KEYS.METADATA] = metadataDictionary;
|
|
71
74
|
}
|
|
75
|
+
|
|
76
|
+
getPrintFont(){
|
|
77
|
+
return this.__internalStorage[STORAGE_KEYS.PRINTFONT];
|
|
78
|
+
}
|
|
79
|
+
__checkInputSetPrintFont(printFont){
|
|
80
|
+
if(!_.isObject(printFont)) {
|
|
81
|
+
throw new Error(DATATYPE_ERROR_MSG);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
setPrintFont(printFont) {
|
|
85
|
+
this.__checkInputSetPrintFont(printFont);
|
|
86
|
+
this.__internalStorage[STORAGE_KEYS.PRINTFONT] = printFont;
|
|
87
|
+
}
|
|
72
88
|
|
|
73
89
|
__checkInputSetImages(imageDictionary){
|
|
74
90
|
if(!_.isObject(imageDictionary) || _.isArray(imageDictionary)) {
|