@resolveio/server-lib 4.6.2 → 4.6.3
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/methods/pdf.js +41 -0
- package/package.json +1 -1
package/methods/pdf.js
CHANGED
|
@@ -64,7 +64,48 @@ function loadPDFMethods(methodManager) {
|
|
|
64
64
|
});
|
|
65
65
|
page.property('content', "\n\t\t\t\t\t\t<head>\n\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Bold.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Italic.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-BoldItalic.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-size: " + (fontSize ? fontSize : '8px') + ";\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\t\tmargin-bottom: 1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\t\tfont-family: Open Sans; \n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t</head>\n\t\t\t\t\t\t<body>\n\t\t\t\t\t" + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>');
|
|
66
66
|
var tmpFileName = (pdfCnt++) + '-' + fileName;
|
|
67
|
+
var afterLoad = false;
|
|
68
|
+
var timeOut = setTimeout(function () {
|
|
69
|
+
if (!afterLoad) {
|
|
70
|
+
page.render(tmpFileName, {
|
|
71
|
+
format: 'pdf',
|
|
72
|
+
quality: '100'
|
|
73
|
+
}).then(function () {
|
|
74
|
+
if (fs.existsSync(tmpFileName)) {
|
|
75
|
+
fs.readFile(tmpFileName, function (errRead, data) {
|
|
76
|
+
if (!errRead) {
|
|
77
|
+
fs.unlinkSync(tmpFileName);
|
|
78
|
+
if (!upload) {
|
|
79
|
+
resolve('data:application/pdf;base64,' + Buffer.from(data).toString('base64'));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
var fileData = 'data:application/pdf;base64,' + Buffer.from(data).toString('base64');
|
|
83
|
+
that.callMethodInternal.call(that, 'uploadFileAndSave', fileName, fileData, (4 * Math.ceil(fileData.length / 3)), uploadFileOrder, uploadFileType, function (err, res) {
|
|
84
|
+
if (err) {
|
|
85
|
+
reject(err);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
resolve(res);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.log(errRead);
|
|
95
|
+
}
|
|
96
|
+
phInstance.exit();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
reject('No tmp file');
|
|
101
|
+
console.log('No tmp file ', tmpFileName);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}, 5000);
|
|
67
106
|
page.on('onLoadFinished', function (status) {
|
|
107
|
+
afterLoad = true;
|
|
108
|
+
clearTimeout(timeOut);
|
|
68
109
|
page.render(tmpFileName, {
|
|
69
110
|
format: 'pdf',
|
|
70
111
|
quality: '100'
|