@resolveio/server-lib 20.7.119 → 20.7.121
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/client-server-app.js +51 -1
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +51 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +55 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +136 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +87 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +98 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +60 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +73 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag-update.collection.js +56 -1
- package/collections/flag-update.collection.js.map +1 -1
- package/collections/flag.collection.js +56 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +72 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +75 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +87 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +66 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +64 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-function.collection.js +73 -1
- package/collections/monitor-function.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +76 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +70 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +56 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +108 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +86 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +148 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +88 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +56 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +265 -1
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +97 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +95 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +78 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +869 -1
- package/http/auth.js.map +1 -1
- package/http/health.js +11 -1
- package/http/health.js.map +1 -1
- package/http/home.js +114 -1
- package/http/home.js.map +1 -1
- package/index.js +18 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +461 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/local-log.manager.js +79 -1
- package/managers/local-log.manager.js.map +1 -1
- package/managers/method.manager.js +1023 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +4223 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +534 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1292 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/websocket.manager.js +165 -1
- package/managers/websocket.manager.js.map +1 -1
- package/managers/worker-dispatcher.manager.js +335 -1
- package/managers/worker-dispatcher.manager.js.map +1 -1
- package/managers/worker-server.manager.js +292 -1
- package/managers/worker-server.manager.js.map +1 -1
- package/methods/accounts.js +302 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +748 -1
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +542 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +111 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1476 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flag-updates.js +8 -1
- package/methods/flag-updates.js.map +1 -1
- package/methods/flags.js +8 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +417 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +543 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +742 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +840 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +232 -1
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +3 -1
- package/models/app-status.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +3 -1
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +3 -1
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +3 -1
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +3 -1
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +3 -1
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +3 -1
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +15 -1
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +3 -1
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +3 -1
- package/models/file.model.js.map +1 -1
- package/models/flag-update.model.js +3 -1
- package/models/flag-update.model.js.map +1 -1
- package/models/flag.model.js +3 -1
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +3 -1
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +3 -1
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +3 -1
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +3 -1
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-response.model.js +3 -1
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.d.ts +0 -1
- package/models/method.model.js +3 -1
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +3 -1
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-function.model.js +3 -1
- package/models/monitor-function.model.js.map +1 -1
- package/models/monitor-memory.model.js +3 -1
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +3 -1
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +3 -1
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +23 -1
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +3 -1
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +3 -1
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +3 -1
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +3 -1
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +3 -1
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +3 -1
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-message.model.js +3 -1
- package/models/server-message.model.js.map +1 -1
- package/models/subscription.model.js +3 -1
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +3 -1
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +3 -1
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +3 -1
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +3 -1
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
- package/public_api.js +77 -1
- package/public_api.js.map +1 -1
- package/publications/app-status.js +16 -1
- package/publications/app-status.js.map +1 -1
- package/publications/cron-jobs.js +32 -1
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +36 -1
- package/publications/files.js.map +1 -1
- package/publications/flags-update.js +22 -1
- package/publications/flags-update.js.map +1 -1
- package/publications/flags.js +22 -1
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +164 -1
- package/publications/logs.js.map +1 -1
- package/publications/notifications.js +16 -1
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +42 -1
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +90 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +50 -1
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +16 -1
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +16 -1
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +16 -1
- package/publications/user-guides.js.map +1 -1
- package/resolveio-server-app.js +176 -1
- package/resolveio-server-app.js.map +1 -1
- package/server-app.js +1159 -1
- package/server-app.js.map +1 -1
- package/util/common.js +632 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +454 -1
- package/util/schema-report-builder.js.map +1 -1
package/methods/pdf.js
CHANGED
|
@@ -1,2 +1,743 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,a,r,i){return new(r=r||Promise)(function(n,e){function fulfilled(t){try{step(i.next(t))}catch(t){e(t)}}function rejected(t){try{step(i.throw(t))}catch(t){e(t)}}function step(t){var e;t.done?n(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(fulfilled,rejected)}step((i=i.apply(t,a||[])).next())})},__generator=this&&this.__generator||function(a,r){var i,o,s,l={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},f={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(f[Symbol.iterator]=function(){return this}),f;function verb(n){return function(t){var e=[n,t];if(i)throw new TypeError("Generator is already executing.");for(;l=f&&e[f=0]?0:l;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return l.label++,{value:e[1],done:!1};case 5:l.label++,o=e[1],e=[0];continue;case 7:e=l.ops.pop(),l.trys.pop();continue;default:if(!(s=0<(s=l.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){l=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3]))l.label=e[1];else if(6===e[0]&&l.label<s[1])l.label=s[1],s=e;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(e)}}e=r.call(a,l)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}},fs=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadPDFMethods=void 0,require("fs")),path=require("path"),pdf_lib_1=require("pdf-lib"),puppeteer=require("puppeteer"),simpl_schema_1=require("simpl-schema"),flag_collection_1=require("../collections/flag.collection"),common_1=require("../util/common");function loadPDFMethods(t){t.methods({generatePDF:{check:new simpl_schema_1.default({html:{type:String},fileName:{type:String},orientation:{type:String,optional:!0},fontSize:{type:String,optional:!0},upload:{type:Boolean,optional:!0},uploadFileOrder:{type:Number,optional:!0},uploadFileType:{type:String,optional:!0}}),function:function(p,g,u,h,b,m,w){return void 0===u&&(u="portrait"),void 0===h&&(h="12px"),void 0===b&&(b=!1),void 0===m&&(m=-1),void 0===w&&(w=""),__awaiter(this,void 0,void 0,function(){var e,n,a,r,i,o,s,l,f,c,d;return __generator(this,function(t){switch(t.label){case 0:return e=["--disable-dev-shm-usage","--no-sandbox","--disable-setuid-sandbox","--disable-accelerated-2d-canvas","--disable-gpu","--allow-file-access-from-files","--enable-local-file-accesses","--font-render-hinting=none"],n=null,[4,flag_collection_1.Flags.findOne({type:"Enable Debug PDF"})];case 1:return(a=t.sent())&&a.value?[4,puppeteer.launch({headless:!1,devtools:!0,args:e,ignoreDefaultArgs:["--disable-extensions"]})]:[3,3];case 2:return n=t.sent(),[3,5];case 3:return[4,puppeteer.launch({headless:!0,devtools:!1,args:e,ignoreDefaultArgs:["--disable-extensions"]})];case 4:n=t.sent(),t.label=5;case 5:return[4,n.newPage()];case 6:return r=t.sent(),s="",s=fs.existsSync(path.join(__dirname,"../private/fonts/dejavuserif.woff"))?path.join(__dirname,"../private/fonts/"):fs.existsSync(path.join(this.clientDir,"./private/fonts/dejavuserif.woff"))?path.join(this.clientDir,"./private/fonts/"):"/usr/share/fonts/dejavu/",l="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(s+"dejavuserif.woff").buffer).toString("base64"),i="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(s+"dejavuserif-bold.woff").buffer).toString("base64"),o="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(s+"dejavuserif-italic.woff").buffer).toString("base64"),s="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(s+"dejavuserif-bolditalic.woff").buffer).toString("base64"),l='\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<style type="text/css">\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: \'Dejavu Serif\';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url("'+l+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\""+i+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\""+o+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\""+s+"\") format('woff');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\tfont-size: "+(h||"12px")+";\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\tpage-break-inside: avoid !important;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\tpadding-top: 1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif'; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t"+p.replace(new RegExp("flex-basis:","g"),"-webkit-flex-basis:").replace(new RegExp("flex:","g"),"-webkit-flex:")+"</body>",[4,r.setContent(l,{waitUntil:["domcontentloaded","load","networkidle0"]})];case 7:return t.sent(),[4,r.evaluateHandle("document.fonts.ready")];case 8:return t.sent(),f=(0,common_1.objectIdHexString)()+".pdf",[4,r.pdf({scale:1,landscape:"portrait"!==u,format:"letter",margin:{top:"1cm",bottom:"1cm",left:"1cm",right:"1cm"},printBackground:!0,displayHeaderFooter:!0,headerTemplate:"\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#header { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<span></span>\n\t\t\t\t\t",footerTemplate:'\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#footer { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important;\n\t\t\t\t\t\t\t\tfont-size: 10px;\n\t\t\t\t\t\t\t\tfont-family: san-serif;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<div style="padding-bottom: 2px; padding-right: 15px; text-align: right; width: 100%;">\n\t\t\t\t\t\t\tPage <span class="pageNumber"></span> of <span class="totalPages"></span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t',path:path.join(__dirname,f),timeout:0})];case 9:return(t.sent(),a&&a.value)?"landscape"!==u?[3,11]:[4,r.setViewport({width:1100,height:850})]:[3,13];case 10:return t.sent(),[3,13];case 11:return[4,r.setViewport({width:850,height:1100})];case 12:t.sent(),t.label=13;case 13:return[4,n.close()];case 14:if(t.sent(),!fs.existsSync(path.join(__dirname,f)))throw console.log("No tmp file ",f),new Error("Error in Generate PDF: No tmp file");try{return c=fs.readFileSync(path.join(__dirname,f)),fs.unlinkSync(path.join(__dirname,f)),b?(d="data:application/pdf;base64,"+Buffer.from(c).toString("base64"),[2,this.callMethod("uploadFileAndSave",g,d,4*Math.ceil(d.length/3),null!==m?m:-1,w,!1)]):[2,"data:application/pdf;base64,"+Buffer.from(c).toString("base64")]}catch(t){throw t.message="Error in Generate PDF: No file - "+t.message,t}return[2]}})})},workerTaskWeight:2},generatePDFNoPageNumber:{check:new simpl_schema_1.default({html:{type:String},fileName:{type:String},orientation:{type:String,optional:!0},fontSize:{type:String,optional:!0},upload:{type:Boolean,optional:!0},uploadFileOrder:{type:Number,optional:!0},uploadFileType:{type:String,optional:!0}}),function:function(d,p,g,u,h,b,m){return void 0===g&&(g="portrait"),void 0===u&&(u="12px"),void 0===h&&(h=!1),void 0===b&&(b=-1),void 0===m&&(m=""),__awaiter(this,void 0,void 0,function(){var e,n,a,r,i,o,s,l,f,c;return __generator(this,function(t){switch(t.label){case 0:return a=["--disable-dev-shm-usage","--no-sandbox","--disable-setuid-sandbox","--disable-accelerated-2d-canvas","--disable-gpu","--allow-file-access-from-files","--enable-local-file-accesses","--font-render-hinting=none"],[4,puppeteer.launch({headless:!0,devtools:!1,args:a,ignoreDefaultArgs:["--disable-extensions"]})];case 1:return[4,(e=t.sent()).newPage()];case 2:return n=t.sent(),a="",a=fs.existsSync(path.join(__dirname,"../private/fonts/dejavuserif.woff"))?path.join(__dirname,"../private/fonts/"):fs.existsSync(path.join(this.clientDir,"./private/fonts/dejavuserif.woff"))?path.join(this.clientDir,"./private/fonts/"):"/usr/share/fonts/dejavu/",s="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(a+"dejavuserif.woff").buffer).toString("base64"),r="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(a+"dejavuserif-bold.woff").buffer).toString("base64"),i="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(a+"dejavuserif-italic.woff").buffer).toString("base64"),o="data:application/font-woff;base64,"+Buffer.from(fs.readFileSync(a+"dejavuserif-bolditalic.woff").buffer).toString("base64"),s='\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<style type="text/css">\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: \'Dejavu Serif\';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url("'+s+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\""+r+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\""+i+"\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\""+o+"\") format('woff');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\tfont-size: "+(u||"12px")+";\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\tpage-break-inside: avoid !important;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\tpadding-top: 1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif'; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<meta charset=\"UTF-8\">\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t"+d.replace(new RegExp("flex-basis:","g"),"-webkit-flex-basis:").replace(new RegExp("flex:","g"),"-webkit-flex:")+"</body>",[4,n.setContent(s,{waitUntil:["domcontentloaded","load","networkidle0"]})];case 3:return t.sent(),[4,n.evaluateHandle("document.fonts.ready")];case 4:return t.sent(),l=(0,common_1.objectIdHexString)()+".pdf",[4,n.pdf({scale:1,landscape:"portrait"!==g,format:"letter",margin:{top:"1cm",bottom:"1cm",left:"1cm",right:"1cm"},printBackground:!0,displayHeaderFooter:!0,headerTemplate:"\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#header { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<span></span>\n\t\t\t\t\t",footerTemplate:'\n\t\t\t\t\t<style>\n\t\t\t\t\t\t#footer { \n\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important;\n\t\t\t\t\t\t\tfont-size: 10px;\n\t\t\t\t\t\t\tfont-family: san-serif;\n\t\t\t\t\t\t}\n\t\t\t\t\t</style>\n\t\t\t\t\t<div style="padding-bottom: 2px; padding-right: 15px; text-align: right; width: 100%;">\n\t\t\t\t\t\t\n\t\t\t\t\t</div>\n\t\t\t\t\t',path:path.join(__dirname,l),timeout:0})];case 5:return t.sent(),[4,e.close()];case 6:if(t.sent(),!fs.existsSync(path.join(__dirname,l)))throw console.log("No tmp file ",l),new Error("Error in Generate PDF No Page Number: No tmp file");try{return f=fs.readFileSync(path.join(__dirname,l)),fs.unlinkSync(path.join(__dirname,l)),h?(c="data:application/pdf;base64,"+Buffer.from(f).toString("base64"),[2,this.callMethod("uploadFileAndSave",p,c,4*Math.ceil(c.length/3),null!==b?b:-1,m,!1)]):[2,"data:application/pdf;base64,"+Buffer.from(f).toString("base64")]}catch(t){throw t.message="Error in Generate PDF No Page Number: No file - "+t.message,t}return[2]}})})},workerTaskWeight:2},mergePDFResolve:{check:new simpl_schema_1.default({fileKeys:{type:Array},"fileKeys.$":{type:String},fileName:{type:String},fileType:{type:String,optional:!0}}),function:function(g,u,h){return __awaiter(this,void 0,void 0,function(){var e,n,a,r,i,o,s,l,f,c,d,p=this;return __generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,25,,26]),[4,this.callMethod("getSignedUrls",g,900)];case 1:return(c=t.sent())&&c.length?(e=[],c.forEach(function(t){e.push(p.callMethod("getDataURIfromURL",t))}),[4,Promise.all(e)]):[3,24];case 2:return n=t.sent(),[4,pdf_lib_1.PDFDocument.create()];case 3:a=t.sent(),r=0,t.label=4;case 4:if(!(r<n.length))return[3,22];if(!(i=n[r]))return[3,20];t.label=5;case 5:return(t.trys.push([5,18,,19]),i.startsWith("data:application/pdf;base64,"))?[4,pdf_lib_1.PDFDocument.load(i,{updateMetadata:!1,parseSpeed:pdf_lib_1.ParseSpeeds.Fastest,ignoreEncryption:!0})]:[3,8];case 6:return o=t.sent(),[4,a.copyPages(o,o.getPageIndices())];case 7:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 8:return i.startsWith("data:image/jpeg;base64,/9j/")||i.startsWith("data:image/png;base64,/9j/")?[4,pdf_lib_1.PDFDocument.create()]:[3,12];case 9:return[4,(o=t.sent()).embedJpg(i)];case 10:return s=t.sent(),l=o.addPage(),f=s.scaleToFit(.75*l.getWidth(),.75*l.getHeight()),l.drawImage(s,{x:l.getWidth()/2-f.width/2,y:l.getHeight()/2-f.height/2,width:f.width,height:f.height}),[4,a.copyPages(o,o.getPageIndices())];case 11:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 12:return i.startsWith("data:image/png;base64,iVBOR")?[4,pdf_lib_1.PDFDocument.create()]:[3,16];case 13:return[4,(o=t.sent()).embedPng(i)];case 14:return s=t.sent(),l=o.addPage(),f=s.scaleToFit(.75*l.getWidth(),.75*l.getHeight()),l.drawImage(s,{x:l.getWidth()/2-f.width/2,y:l.getHeight()/2-f.height/2,width:f.width,height:f.height}),[4,a.copyPages(o,o.getPageIndices())];case 15:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 16:throw console.log("Error - unsupported!!",i.slice(0,60)),new Error("Error in Merge PDF Resolve: Unsupported document type - "+i.slice(0,60));case 17:return[3,19];case 18:throw c=t.sent(),console.log("Error processing fileData:",i.slice(0,60),c.message),c.message="Error in Merge PDF Resolve: Error processing fileData: ".concat(i.slice(0,60)," - ").concat(c.message),c;case 19:return[3,21];case 20:throw console.log("Error - no filedata!!",i),new Error("Error in Merge PDF Resolve: No File Data");case 21:return r++,[3,4];case 22:return[4,a.save()];case 23:return d=t.sent(),d="data:application/pdf;base64,"+Buffer.from(d).toString("base64"),[2,this.callMethod("uploadFileAndSave",u,d,4*Math.ceil(d.length/3),-1,h,!1)];case 24:return[3,26];case 25:throw(d=t.sent()).message="Error in Merge PDF Resolve: PDF Merge - Get Signed URLs - "+d.message,d;case 26:return[2]}})})},workerTaskWeight:2},mergePDFResolveNoSave:{check:new simpl_schema_1.default({fileKeys:{type:Array},"fileKeys.$":{type:String}}),function:function(g){return __awaiter(this,void 0,void 0,function(){var e,n,a,r,i,o,s,l,f,c,d,p=this;return __generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,26,,27]),[4,this.callMethod("getSignedUrls",g,900)];case 1:return(c=t.sent())&&c.length?(e=[],c.forEach(function(t){e.push(p.callMethod("getDataURIfromURL",t))}),[4,Promise.all(e)]):[3,24];case 2:return n=t.sent(),[4,pdf_lib_1.PDFDocument.create()];case 3:a=t.sent(),r=0,t.label=4;case 4:if(!(r<n.length))return[3,22];if(!(i=n[r]))return[3,20];t.label=5;case 5:return(t.trys.push([5,18,,19]),i.startsWith("data:application/pdf;base64,"))?[4,pdf_lib_1.PDFDocument.load(i,{updateMetadata:!1,parseSpeed:pdf_lib_1.ParseSpeeds.Fastest,ignoreEncryption:!0})]:[3,8];case 6:return o=t.sent(),[4,a.copyPages(o,o.getPageIndices())];case 7:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 8:return i.startsWith("data:image/jpeg;base64,/9j/")||i.startsWith("data:image/png;base64,/9j/")?[4,pdf_lib_1.PDFDocument.create()]:[3,12];case 9:return[4,(o=t.sent()).embedJpg(i)];case 10:return s=t.sent(),l=o.addPage(),f=s.scaleToFit(.75*l.getWidth(),.75*l.getHeight()),l.drawImage(s,{x:l.getWidth()/2-f.width/2,y:l.getHeight()/2-f.height/2,width:f.width,height:f.height}),[4,a.copyPages(o,o.getPageIndices())];case 11:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 12:return i.startsWith("data:image/png;base64,iVBOR")?[4,pdf_lib_1.PDFDocument.create()]:[3,16];case 13:return[4,(o=t.sent()).embedPng(i)];case 14:return s=t.sent(),l=o.addPage(),f=s.scaleToFit(.75*l.getWidth(),.75*l.getHeight()),l.drawImage(s,{x:l.getWidth()/2-f.width/2,y:l.getHeight()/2-f.height/2,width:f.width,height:f.height}),[4,a.copyPages(o,o.getPageIndices())];case 15:return t.sent().forEach(function(t){a.addPage(t)}),[3,17];case 16:console.log("Error - unsupported!!",i.slice(0,60)),t.label=17;case 17:return[3,19];case 18:return c=t.sent(),console.log("Error processing fileData:",i.slice(0,60),c),[3,19];case 19:return[3,21];case 20:console.log("Error - no filedata!!",i),t.label=21;case 21:return r++,[3,4];case 22:return[4,a.save()];case 23:return d=t.sent(),[2,"data:application/pdf;base64,"+Buffer.from(d).toString("base64")];case 24:throw new Error("Error in Merge PDF Resolve No Save: No signed urls");case 25:return[3,27];case 26:throw(d=t.sent()).message="Error in Merge PDF Resolve: ".concat(d.message),d;case 27:return[2]}})})},workerTaskWeight:2},mergePDFResolveHtml:{check:new simpl_schema_1.default({htmls:{type:Array},"htmls.$":{type:String},fileName:{type:String},fileType:{type:String,optional:!0},save:{type:Boolean,optional:!0}}),function:function(c,d,p,g){return void 0===g&&(g=!0),__awaiter(this,void 0,void 0,function(){var e,n,a,r,i,o,s,l,f;return __generator(this,function(t){switch(t.label){case 0:return[4,pdf_lib_1.PDFDocument.create()];case 1:e=t.sent(),n=0,t.label=2;case 2:if(!(n<c.length))return[3,20];if(!(a=c[n]))return[3,18];t.label=3;case 3:return(t.trys.push([3,16,,17]),a.startsWith("data:application/pdf;base64,"))?[4,pdf_lib_1.PDFDocument.load(a,{updateMetadata:!1,parseSpeed:pdf_lib_1.ParseSpeeds.Fastest,ignoreEncryption:!0})]:[3,6];case 4:return r=t.sent(),[4,e.copyPages(r,r.getPageIndices())];case 5:return t.sent().forEach(function(t){e.addPage(t)}),[3,15];case 6:return a.startsWith("data:image/jpeg;base64,/9j/")||a.startsWith("data:image/png;base64,/9j/")?[4,pdf_lib_1.PDFDocument.create()]:[3,10];case 7:return[4,(r=t.sent()).embedJpg(a)];case 8:return i=t.sent(),o=r.addPage(),s=i.scaleToFit(.75*o.getWidth(),.75*o.getHeight()),o.drawImage(i,{x:o.getWidth()/2-s.width/2,y:o.getHeight()/2-s.height/2,width:s.width,height:s.height}),[4,e.copyPages(r,r.getPageIndices())];case 9:return t.sent().forEach(function(t){e.addPage(t)}),[3,15];case 10:return a.startsWith("data:image/png;base64,iVBOR")?[4,pdf_lib_1.PDFDocument.create()]:[3,14];case 11:return[4,(r=t.sent()).embedPng(a)];case 12:return i=t.sent(),o=r.addPage(),s=i.scaleToFit(.75*o.getWidth(),.75*o.getHeight()),o.drawImage(i,{x:o.getWidth()/2-s.width/2,y:o.getHeight()/2-s.height/2,width:s.width,height:s.height}),[4,e.copyPages(r,r.getPageIndices())];case 13:return t.sent().forEach(function(t){e.addPage(t)}),[3,15];case 14:throw console.log("Error - unsupported!!",a.slice(0,60)),new Error("Error in Merge PDF Resolve HTML: Unsupported file - "+a.slice(0,60));case 15:return[3,17];case 16:throw l=t.sent(),console.log("Error processing fileData:",a.slice(0,60),l),l.message="Error in Merge PDF Resolve HTML: Error processing filedata - ".concat(l.message),l;case 17:return[3,19];case 18:throw console.log("Error - no filedata!!",a),new Error("Error in Merge PDF Resolve HTML: No File data");case 19:return n++,[3,2];case 20:return[4,e.save()];case 21:return l=t.sent(),f="data:application/pdf;base64,"+Buffer.from(l).toString("base64"),g?[2,this.callMethod("uploadFileAndSave",d,f,4*Math.ceil(f.length/3),-1,p,!1)]:[2,f]}})})},workerTaskWeight:2}})}exports.loadPDFMethods=loadPDFMethods;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.loadPDFMethods = void 0;
|
|
40
|
+
var fs = require("fs");
|
|
41
|
+
var path = require("path");
|
|
42
|
+
var pdf_lib_1 = require("pdf-lib");
|
|
43
|
+
var puppeteer = require("puppeteer");
|
|
44
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
45
|
+
var flag_collection_1 = require("../collections/flag.collection");
|
|
46
|
+
var common_1 = require("../util/common");
|
|
47
|
+
function loadPDFMethods(methodManager) {
|
|
48
|
+
methodManager.methods({
|
|
49
|
+
generatePDF: {
|
|
50
|
+
check: new simpl_schema_1.default({
|
|
51
|
+
html: {
|
|
52
|
+
type: String
|
|
53
|
+
},
|
|
54
|
+
fileName: {
|
|
55
|
+
type: String
|
|
56
|
+
},
|
|
57
|
+
orientation: {
|
|
58
|
+
type: String,
|
|
59
|
+
optional: true
|
|
60
|
+
},
|
|
61
|
+
fontSize: {
|
|
62
|
+
type: String,
|
|
63
|
+
optional: true
|
|
64
|
+
},
|
|
65
|
+
upload: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
optional: true
|
|
68
|
+
},
|
|
69
|
+
uploadFileOrder: {
|
|
70
|
+
type: Number,
|
|
71
|
+
optional: true
|
|
72
|
+
},
|
|
73
|
+
uploadFileType: {
|
|
74
|
+
type: String,
|
|
75
|
+
optional: true
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
function: function (html, fileName, orientation, fontSize, upload, uploadFileOrder, uploadFileType) {
|
|
79
|
+
if (orientation === void 0) { orientation = 'portrait'; }
|
|
80
|
+
if (fontSize === void 0) { fontSize = '12px'; }
|
|
81
|
+
if (upload === void 0) { upload = false; }
|
|
82
|
+
if (uploadFileOrder === void 0) { uploadFileOrder = -1; }
|
|
83
|
+
if (uploadFileType === void 0) { uploadFileType = ''; }
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var args, browser, enableDebugFlag, page, pathToFont, dejavuserif_woff, dejavuserifBold_woff, dejavuserifItalic_woff, dejavuserifBoldItalic_woff, content, tmpFileName, data, fileData;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
args = [
|
|
90
|
+
"--disable-dev-shm-usage",
|
|
91
|
+
"--no-sandbox",
|
|
92
|
+
"--disable-setuid-sandbox",
|
|
93
|
+
"--disable-accelerated-2d-canvas",
|
|
94
|
+
"--disable-gpu",
|
|
95
|
+
"--allow-file-access-from-files",
|
|
96
|
+
"--enable-local-file-accesses",
|
|
97
|
+
'--font-render-hinting=none'
|
|
98
|
+
];
|
|
99
|
+
browser = null;
|
|
100
|
+
return [4 /*yield*/, flag_collection_1.Flags.findOne({ type: 'Enable Debug PDF' })];
|
|
101
|
+
case 1:
|
|
102
|
+
enableDebugFlag = _a.sent();
|
|
103
|
+
if (!(enableDebugFlag && enableDebugFlag.value)) return [3 /*break*/, 3];
|
|
104
|
+
return [4 /*yield*/, puppeteer.launch({
|
|
105
|
+
headless: false,
|
|
106
|
+
devtools: true,
|
|
107
|
+
args: args,
|
|
108
|
+
ignoreDefaultArgs: ["--disable-extensions"]
|
|
109
|
+
})];
|
|
110
|
+
case 2:
|
|
111
|
+
browser = _a.sent(); // run browser
|
|
112
|
+
return [3 /*break*/, 5];
|
|
113
|
+
case 3: return [4 /*yield*/, puppeteer.launch({
|
|
114
|
+
headless: true,
|
|
115
|
+
devtools: false,
|
|
116
|
+
args: args,
|
|
117
|
+
ignoreDefaultArgs: ["--disable-extensions"]
|
|
118
|
+
})];
|
|
119
|
+
case 4:
|
|
120
|
+
browser = _a.sent(); // run browser
|
|
121
|
+
_a.label = 5;
|
|
122
|
+
case 5: return [4 /*yield*/, browser.newPage()];
|
|
123
|
+
case 6:
|
|
124
|
+
page = _a.sent();
|
|
125
|
+
pathToFont = '';
|
|
126
|
+
if (fs.existsSync(path.join(__dirname, ('../private/fonts/dejavuserif.woff')))) {
|
|
127
|
+
pathToFont = path.join(__dirname, ('../private/fonts/'));
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
if (fs.existsSync(path.join(this.clientDir, ('./private/fonts/dejavuserif.woff')))) {
|
|
131
|
+
pathToFont = path.join(this.clientDir, ('./private/fonts/'));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
pathToFont = '/usr/share/fonts/dejavu/';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
dejavuserif_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif.woff').buffer).toString('base64');
|
|
138
|
+
dejavuserifBold_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-bold.woff').buffer).toString('base64');
|
|
139
|
+
dejavuserifItalic_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-italic.woff').buffer).toString('base64');
|
|
140
|
+
dejavuserifBoldItalic_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-bolditalic.woff').buffer).toString('base64');
|
|
141
|
+
content = "\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<style type=\"text/css\">\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserif_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifBold_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifItalic_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifBoldItalic_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\tfont-size: " + (fontSize ? fontSize : '12px') + ";\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\tpage-break-inside: avoid !important;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\tpadding-top: 1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif'; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t" + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>';
|
|
142
|
+
return [4 /*yield*/, page.setContent(content, { waitUntil: ['domcontentloaded', 'load', 'networkidle0'] })];
|
|
143
|
+
case 7:
|
|
144
|
+
_a.sent();
|
|
145
|
+
return [4 /*yield*/, page.evaluateHandle('document.fonts.ready')];
|
|
146
|
+
case 8:
|
|
147
|
+
_a.sent();
|
|
148
|
+
tmpFileName = (0, common_1.objectIdHexString)() + '.pdf';
|
|
149
|
+
return [4 /*yield*/, page.pdf({
|
|
150
|
+
scale: 1,
|
|
151
|
+
landscape: orientation === 'portrait' ? false : true,
|
|
152
|
+
format: 'letter',
|
|
153
|
+
margin: {
|
|
154
|
+
top: '1cm',
|
|
155
|
+
bottom: '1cm',
|
|
156
|
+
left: '1cm',
|
|
157
|
+
right: '1cm'
|
|
158
|
+
},
|
|
159
|
+
printBackground: true,
|
|
160
|
+
displayHeaderFooter: true,
|
|
161
|
+
headerTemplate: "\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#header { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<span></span>\n\t\t\t\t\t",
|
|
162
|
+
footerTemplate: "\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#footer { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important;\n\t\t\t\t\t\t\t\tfont-size: 10px;\n\t\t\t\t\t\t\t\tfont-family: san-serif;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<div style=\"padding-bottom: 2px; padding-right: 15px; text-align: right; width: 100%;\">\n\t\t\t\t\t\t\tPage <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t",
|
|
163
|
+
path: path.join(__dirname, (tmpFileName)),
|
|
164
|
+
timeout: 0
|
|
165
|
+
})];
|
|
166
|
+
case 9:
|
|
167
|
+
_a.sent();
|
|
168
|
+
if (!(enableDebugFlag && enableDebugFlag.value)) return [3 /*break*/, 13];
|
|
169
|
+
if (!(orientation === 'landscape')) return [3 /*break*/, 11];
|
|
170
|
+
return [4 /*yield*/, page.setViewport({ width: 1100, height: 850 })];
|
|
171
|
+
case 10:
|
|
172
|
+
_a.sent();
|
|
173
|
+
return [3 /*break*/, 13];
|
|
174
|
+
case 11: return [4 /*yield*/, page.setViewport({ width: 850, height: 1100 })];
|
|
175
|
+
case 12:
|
|
176
|
+
_a.sent();
|
|
177
|
+
_a.label = 13;
|
|
178
|
+
case 13: return [4 /*yield*/, browser.close()];
|
|
179
|
+
case 14:
|
|
180
|
+
_a.sent();
|
|
181
|
+
if (fs.existsSync(path.join(__dirname, (tmpFileName)))) {
|
|
182
|
+
try {
|
|
183
|
+
data = fs.readFileSync(path.join(__dirname, (tmpFileName)));
|
|
184
|
+
fs.unlinkSync(path.join(__dirname, (tmpFileName)));
|
|
185
|
+
if (!upload) {
|
|
186
|
+
return [2 /*return*/, 'data:application/pdf;base64,' + Buffer.from(data).toString('base64')];
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
fileData = 'data:application/pdf;base64,' + Buffer.from(data).toString('base64');
|
|
190
|
+
return [2 /*return*/, this.callMethod('uploadFileAndSave', fileName, fileData, (4 * Math.ceil(fileData.length / 3)), uploadFileOrder !== null ? uploadFileOrder : -1, uploadFileType, false)];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (errRead) {
|
|
194
|
+
errRead.message = 'Error in Generate PDF: No file - ' + errRead.message;
|
|
195
|
+
throw errRead;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
console.log('No tmp file ', tmpFileName);
|
|
200
|
+
throw new Error('Error in Generate PDF: No tmp file');
|
|
201
|
+
}
|
|
202
|
+
return [2 /*return*/];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
workerTaskWeight: 2
|
|
208
|
+
},
|
|
209
|
+
generatePDFNoPageNumber: {
|
|
210
|
+
check: new simpl_schema_1.default({
|
|
211
|
+
html: {
|
|
212
|
+
type: String
|
|
213
|
+
},
|
|
214
|
+
fileName: {
|
|
215
|
+
type: String
|
|
216
|
+
},
|
|
217
|
+
orientation: {
|
|
218
|
+
type: String,
|
|
219
|
+
optional: true
|
|
220
|
+
},
|
|
221
|
+
fontSize: {
|
|
222
|
+
type: String,
|
|
223
|
+
optional: true
|
|
224
|
+
},
|
|
225
|
+
upload: {
|
|
226
|
+
type: Boolean,
|
|
227
|
+
optional: true
|
|
228
|
+
},
|
|
229
|
+
uploadFileOrder: {
|
|
230
|
+
type: Number,
|
|
231
|
+
optional: true
|
|
232
|
+
},
|
|
233
|
+
uploadFileType: {
|
|
234
|
+
type: String,
|
|
235
|
+
optional: true
|
|
236
|
+
}
|
|
237
|
+
}),
|
|
238
|
+
function: function (html, fileName, orientation, fontSize, upload, uploadFileOrder, uploadFileType) {
|
|
239
|
+
if (orientation === void 0) { orientation = 'portrait'; }
|
|
240
|
+
if (fontSize === void 0) { fontSize = '12px'; }
|
|
241
|
+
if (upload === void 0) { upload = false; }
|
|
242
|
+
if (uploadFileOrder === void 0) { uploadFileOrder = -1; }
|
|
243
|
+
if (uploadFileType === void 0) { uploadFileType = ''; }
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var args, browser, page, pathToFont, dejavuserif_woff, dejavuserifBold_woff, dejavuserifItalic_woff, dejavuserifBoldItalic_woff, content, tmpFileName, data, fileData;
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
switch (_a.label) {
|
|
248
|
+
case 0:
|
|
249
|
+
args = [
|
|
250
|
+
"--disable-dev-shm-usage",
|
|
251
|
+
"--no-sandbox",
|
|
252
|
+
"--disable-setuid-sandbox",
|
|
253
|
+
"--disable-accelerated-2d-canvas",
|
|
254
|
+
"--disable-gpu",
|
|
255
|
+
"--allow-file-access-from-files",
|
|
256
|
+
"--enable-local-file-accesses",
|
|
257
|
+
'--font-render-hinting=none'
|
|
258
|
+
];
|
|
259
|
+
return [4 /*yield*/, puppeteer.launch({
|
|
260
|
+
headless: true,
|
|
261
|
+
devtools: false,
|
|
262
|
+
args: args,
|
|
263
|
+
ignoreDefaultArgs: ["--disable-extensions"]
|
|
264
|
+
})];
|
|
265
|
+
case 1:
|
|
266
|
+
browser = _a.sent();
|
|
267
|
+
return [4 /*yield*/, browser.newPage()];
|
|
268
|
+
case 2:
|
|
269
|
+
page = _a.sent();
|
|
270
|
+
pathToFont = '';
|
|
271
|
+
if (fs.existsSync(path.join(__dirname, ('../private/fonts/dejavuserif.woff')))) {
|
|
272
|
+
pathToFont = path.join(__dirname, ('../private/fonts/'));
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (fs.existsSync(path.join(this.clientDir, ('./private/fonts/dejavuserif.woff')))) {
|
|
276
|
+
pathToFont = path.join(this.clientDir, ('./private/fonts/'));
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
pathToFont = '/usr/share/fonts/dejavu/';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
dejavuserif_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif.woff').buffer).toString('base64');
|
|
283
|
+
dejavuserifBold_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-bold.woff').buffer).toString('base64');
|
|
284
|
+
dejavuserifItalic_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-italic.woff').buffer).toString('base64');
|
|
285
|
+
dejavuserifBoldItalic_woff = 'data:application/font-woff;base64,' + Buffer.from(fs.readFileSync(pathToFont + 'dejavuserif-bolditalic.woff').buffer).toString('base64');
|
|
286
|
+
content = "\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<style type=\"text/css\">\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserif_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifBold_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifItalic_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif';\n\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\tsrc: url(\"" + dejavuserifBoldItalic_woff + "\") format('woff');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\tfont-size: " + (fontSize ? fontSize : '12px') + ";\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\tpage-break-inside: avoid !important;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\tpadding-top: 1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif'; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<meta charset=\"UTF-8\">\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t" + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>';
|
|
287
|
+
return [4 /*yield*/, page.setContent(content, { waitUntil: ['domcontentloaded', 'load', 'networkidle0'] })];
|
|
288
|
+
case 3:
|
|
289
|
+
_a.sent();
|
|
290
|
+
return [4 /*yield*/, page.evaluateHandle('document.fonts.ready')];
|
|
291
|
+
case 4:
|
|
292
|
+
_a.sent();
|
|
293
|
+
tmpFileName = (0, common_1.objectIdHexString)() + '.pdf';
|
|
294
|
+
return [4 /*yield*/, page.pdf({
|
|
295
|
+
scale: 1,
|
|
296
|
+
landscape: orientation === 'portrait' ? false : true,
|
|
297
|
+
format: 'letter',
|
|
298
|
+
margin: {
|
|
299
|
+
top: '1cm',
|
|
300
|
+
bottom: '1cm',
|
|
301
|
+
left: '1cm',
|
|
302
|
+
right: '1cm'
|
|
303
|
+
},
|
|
304
|
+
printBackground: true,
|
|
305
|
+
displayHeaderFooter: true,
|
|
306
|
+
headerTemplate: "\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t#header { \n\t\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t<span></span>\n\t\t\t\t\t",
|
|
307
|
+
footerTemplate: "\n\t\t\t\t\t<style>\n\t\t\t\t\t\t#footer { \n\t\t\t\t\t\t\tpadding: 0 0 10px 10px !important;\n\t\t\t\t\t\t\tfont-size: 10px;\n\t\t\t\t\t\t\tfont-family: san-serif;\n\t\t\t\t\t\t}\n\t\t\t\t\t</style>\n\t\t\t\t\t<div style=\"padding-bottom: 2px; padding-right: 15px; text-align: right; width: 100%;\">\n\t\t\t\t\t\t\n\t\t\t\t\t</div>\n\t\t\t\t\t",
|
|
308
|
+
path: path.join(__dirname, (tmpFileName)),
|
|
309
|
+
timeout: 0
|
|
310
|
+
})];
|
|
311
|
+
case 5:
|
|
312
|
+
_a.sent();
|
|
313
|
+
return [4 /*yield*/, browser.close()];
|
|
314
|
+
case 6:
|
|
315
|
+
_a.sent();
|
|
316
|
+
if (fs.existsSync(path.join(__dirname, (tmpFileName)))) {
|
|
317
|
+
try {
|
|
318
|
+
data = fs.readFileSync(path.join(__dirname, (tmpFileName)));
|
|
319
|
+
fs.unlinkSync(path.join(__dirname, (tmpFileName)));
|
|
320
|
+
if (!upload) {
|
|
321
|
+
return [2 /*return*/, 'data:application/pdf;base64,' + Buffer.from(data).toString('base64')];
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
fileData = 'data:application/pdf;base64,' + Buffer.from(data).toString('base64');
|
|
325
|
+
return [2 /*return*/, this.callMethod('uploadFileAndSave', fileName, fileData, (4 * Math.ceil(fileData.length / 3)), uploadFileOrder !== null ? uploadFileOrder : -1, uploadFileType, false)];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (errRead) {
|
|
329
|
+
errRead.message = 'Error in Generate PDF No Page Number: No file - ' + errRead.message;
|
|
330
|
+
throw errRead;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
console.log('No tmp file ', tmpFileName);
|
|
335
|
+
throw new Error('Error in Generate PDF No Page Number: No tmp file');
|
|
336
|
+
}
|
|
337
|
+
return [2 /*return*/];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
workerTaskWeight: 2
|
|
343
|
+
},
|
|
344
|
+
mergePDFResolve: {
|
|
345
|
+
check: new simpl_schema_1.default({
|
|
346
|
+
fileKeys: {
|
|
347
|
+
type: Array
|
|
348
|
+
},
|
|
349
|
+
'fileKeys.$': {
|
|
350
|
+
type: String
|
|
351
|
+
},
|
|
352
|
+
fileName: {
|
|
353
|
+
type: String
|
|
354
|
+
},
|
|
355
|
+
fileType: {
|
|
356
|
+
type: String,
|
|
357
|
+
optional: true
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
360
|
+
function: function (fileKeys, fileName, fileType) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
+
var resSigneds, promises_1, fileDatas, mergedPdf_1, i, fileData, pdf, copiedPages, pdf, img, page, imgDim, copiedPages, pdf, img, page, imgDim, copiedPages, error_1, mergedPDFUint8, b64PDF, err_1;
|
|
363
|
+
var _this = this;
|
|
364
|
+
return __generator(this, function (_a) {
|
|
365
|
+
switch (_a.label) {
|
|
366
|
+
case 0:
|
|
367
|
+
_a.trys.push([0, 25, , 26]);
|
|
368
|
+
return [4 /*yield*/, this.callMethod('getSignedUrls', fileKeys, 900)];
|
|
369
|
+
case 1:
|
|
370
|
+
resSigneds = _a.sent();
|
|
371
|
+
if (!(resSigneds && resSigneds.length)) return [3 /*break*/, 24];
|
|
372
|
+
promises_1 = [];
|
|
373
|
+
resSigneds.forEach(function (signedUrl) {
|
|
374
|
+
promises_1.push(_this.callMethod('getDataURIfromURL', signedUrl));
|
|
375
|
+
});
|
|
376
|
+
return [4 /*yield*/, Promise.all(promises_1)];
|
|
377
|
+
case 2:
|
|
378
|
+
fileDatas = _a.sent();
|
|
379
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
380
|
+
case 3:
|
|
381
|
+
mergedPdf_1 = _a.sent();
|
|
382
|
+
i = 0;
|
|
383
|
+
_a.label = 4;
|
|
384
|
+
case 4:
|
|
385
|
+
if (!(i < fileDatas.length)) return [3 /*break*/, 22];
|
|
386
|
+
fileData = fileDatas[i];
|
|
387
|
+
if (!fileData) return [3 /*break*/, 20];
|
|
388
|
+
_a.label = 5;
|
|
389
|
+
case 5:
|
|
390
|
+
_a.trys.push([5, 18, , 19]);
|
|
391
|
+
if (!fileData.startsWith('data:application/pdf;base64,')) return [3 /*break*/, 8];
|
|
392
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.load(fileData, { updateMetadata: false, parseSpeed: pdf_lib_1.ParseSpeeds.Fastest, ignoreEncryption: true })];
|
|
393
|
+
case 6:
|
|
394
|
+
pdf = _a.sent();
|
|
395
|
+
return [4 /*yield*/, mergedPdf_1.copyPages(pdf, pdf.getPageIndices())];
|
|
396
|
+
case 7:
|
|
397
|
+
copiedPages = _a.sent();
|
|
398
|
+
copiedPages.forEach(function (page) {
|
|
399
|
+
mergedPdf_1.addPage(page);
|
|
400
|
+
});
|
|
401
|
+
return [3 /*break*/, 17];
|
|
402
|
+
case 8:
|
|
403
|
+
if (!(fileData.startsWith('data:image/jpeg;base64,/9j/') || fileData.startsWith('data:image/png;base64,/9j/'))) return [3 /*break*/, 12];
|
|
404
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
405
|
+
case 9:
|
|
406
|
+
pdf = _a.sent();
|
|
407
|
+
return [4 /*yield*/, pdf.embedJpg(fileData)];
|
|
408
|
+
case 10:
|
|
409
|
+
img = _a.sent();
|
|
410
|
+
page = pdf.addPage();
|
|
411
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
412
|
+
page.drawImage(img, {
|
|
413
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
414
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
415
|
+
width: imgDim.width,
|
|
416
|
+
height: imgDim.height,
|
|
417
|
+
});
|
|
418
|
+
return [4 /*yield*/, mergedPdf_1.copyPages(pdf, pdf.getPageIndices())];
|
|
419
|
+
case 11:
|
|
420
|
+
copiedPages = _a.sent();
|
|
421
|
+
copiedPages.forEach(function (page) {
|
|
422
|
+
mergedPdf_1.addPage(page);
|
|
423
|
+
});
|
|
424
|
+
return [3 /*break*/, 17];
|
|
425
|
+
case 12:
|
|
426
|
+
if (!fileData.startsWith('data:image/png;base64,iVBOR')) return [3 /*break*/, 16];
|
|
427
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
428
|
+
case 13:
|
|
429
|
+
pdf = _a.sent();
|
|
430
|
+
return [4 /*yield*/, pdf.embedPng(fileData)];
|
|
431
|
+
case 14:
|
|
432
|
+
img = _a.sent();
|
|
433
|
+
page = pdf.addPage();
|
|
434
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
435
|
+
page.drawImage(img, {
|
|
436
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
437
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
438
|
+
width: imgDim.width,
|
|
439
|
+
height: imgDim.height,
|
|
440
|
+
});
|
|
441
|
+
return [4 /*yield*/, mergedPdf_1.copyPages(pdf, pdf.getPageIndices())];
|
|
442
|
+
case 15:
|
|
443
|
+
copiedPages = _a.sent();
|
|
444
|
+
copiedPages.forEach(function (page) {
|
|
445
|
+
mergedPdf_1.addPage(page);
|
|
446
|
+
});
|
|
447
|
+
return [3 /*break*/, 17];
|
|
448
|
+
case 16:
|
|
449
|
+
console.log('Error - unsupported!!', fileData.slice(0, 60));
|
|
450
|
+
throw new Error('Error in Merge PDF Resolve: Unsupported document type - ' + fileData.slice(0, 60));
|
|
451
|
+
case 17: return [3 /*break*/, 19];
|
|
452
|
+
case 18:
|
|
453
|
+
error_1 = _a.sent();
|
|
454
|
+
console.log('Error processing fileData:', fileData.slice(0, 60), error_1.message);
|
|
455
|
+
error_1.message = "Error in Merge PDF Resolve: Error processing fileData: ".concat(fileData.slice(0, 60), " - ").concat(error_1.message);
|
|
456
|
+
throw error_1;
|
|
457
|
+
case 19: return [3 /*break*/, 21];
|
|
458
|
+
case 20:
|
|
459
|
+
console.log('Error - no filedata!!', fileData);
|
|
460
|
+
throw new Error('Error in Merge PDF Resolve: No File Data');
|
|
461
|
+
case 21:
|
|
462
|
+
i++;
|
|
463
|
+
return [3 /*break*/, 4];
|
|
464
|
+
case 22: return [4 /*yield*/, mergedPdf_1.save()];
|
|
465
|
+
case 23:
|
|
466
|
+
mergedPDFUint8 = _a.sent();
|
|
467
|
+
b64PDF = 'data:application/pdf;base64,' + Buffer.from(mergedPDFUint8).toString('base64');
|
|
468
|
+
return [2 /*return*/, this.callMethod('uploadFileAndSave', fileName, b64PDF, (4 * Math.ceil(b64PDF.length / 3)), -1, fileType, false)];
|
|
469
|
+
case 24: return [3 /*break*/, 26];
|
|
470
|
+
case 25:
|
|
471
|
+
err_1 = _a.sent();
|
|
472
|
+
err_1.message = 'Error in Merge PDF Resolve: PDF Merge - Get Signed URLs - ' + err_1.message;
|
|
473
|
+
throw err_1;
|
|
474
|
+
case 26: return [2 /*return*/];
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
workerTaskWeight: 2
|
|
480
|
+
},
|
|
481
|
+
mergePDFResolveNoSave: {
|
|
482
|
+
check: new simpl_schema_1.default({
|
|
483
|
+
fileKeys: {
|
|
484
|
+
type: Array
|
|
485
|
+
},
|
|
486
|
+
'fileKeys.$': {
|
|
487
|
+
type: String
|
|
488
|
+
}
|
|
489
|
+
}),
|
|
490
|
+
function: function (fileKeys) {
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
var resSigneds, promises_2, fileDatas, mergedPdf_2, i, fileData, pdf, copiedPages, pdf, img, page, imgDim, copiedPages, pdf, img, page, imgDim, copiedPages, error_2, mergedPDFUint8, b64PDF, err_2;
|
|
493
|
+
var _this = this;
|
|
494
|
+
return __generator(this, function (_a) {
|
|
495
|
+
switch (_a.label) {
|
|
496
|
+
case 0:
|
|
497
|
+
_a.trys.push([0, 26, , 27]);
|
|
498
|
+
return [4 /*yield*/, this.callMethod('getSignedUrls', fileKeys, 900)];
|
|
499
|
+
case 1:
|
|
500
|
+
resSigneds = _a.sent();
|
|
501
|
+
if (!(resSigneds && resSigneds.length)) return [3 /*break*/, 24];
|
|
502
|
+
promises_2 = [];
|
|
503
|
+
resSigneds.forEach(function (signedUrl) {
|
|
504
|
+
promises_2.push(_this.callMethod('getDataURIfromURL', signedUrl));
|
|
505
|
+
});
|
|
506
|
+
return [4 /*yield*/, Promise.all(promises_2)];
|
|
507
|
+
case 2:
|
|
508
|
+
fileDatas = _a.sent();
|
|
509
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
510
|
+
case 3:
|
|
511
|
+
mergedPdf_2 = _a.sent();
|
|
512
|
+
i = 0;
|
|
513
|
+
_a.label = 4;
|
|
514
|
+
case 4:
|
|
515
|
+
if (!(i < fileDatas.length)) return [3 /*break*/, 22];
|
|
516
|
+
fileData = fileDatas[i];
|
|
517
|
+
if (!fileData) return [3 /*break*/, 20];
|
|
518
|
+
_a.label = 5;
|
|
519
|
+
case 5:
|
|
520
|
+
_a.trys.push([5, 18, , 19]);
|
|
521
|
+
if (!fileData.startsWith('data:application/pdf;base64,')) return [3 /*break*/, 8];
|
|
522
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.load(fileData, { updateMetadata: false, parseSpeed: pdf_lib_1.ParseSpeeds.Fastest, ignoreEncryption: true })];
|
|
523
|
+
case 6:
|
|
524
|
+
pdf = _a.sent();
|
|
525
|
+
return [4 /*yield*/, mergedPdf_2.copyPages(pdf, pdf.getPageIndices())];
|
|
526
|
+
case 7:
|
|
527
|
+
copiedPages = _a.sent();
|
|
528
|
+
copiedPages.forEach(function (page) {
|
|
529
|
+
mergedPdf_2.addPage(page);
|
|
530
|
+
});
|
|
531
|
+
return [3 /*break*/, 17];
|
|
532
|
+
case 8:
|
|
533
|
+
if (!(fileData.startsWith('data:image/jpeg;base64,/9j/') || fileData.startsWith('data:image/png;base64,/9j/'))) return [3 /*break*/, 12];
|
|
534
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
535
|
+
case 9:
|
|
536
|
+
pdf = _a.sent();
|
|
537
|
+
return [4 /*yield*/, pdf.embedJpg(fileData)];
|
|
538
|
+
case 10:
|
|
539
|
+
img = _a.sent();
|
|
540
|
+
page = pdf.addPage();
|
|
541
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
542
|
+
page.drawImage(img, {
|
|
543
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
544
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
545
|
+
width: imgDim.width,
|
|
546
|
+
height: imgDim.height,
|
|
547
|
+
});
|
|
548
|
+
return [4 /*yield*/, mergedPdf_2.copyPages(pdf, pdf.getPageIndices())];
|
|
549
|
+
case 11:
|
|
550
|
+
copiedPages = _a.sent();
|
|
551
|
+
copiedPages.forEach(function (page) {
|
|
552
|
+
mergedPdf_2.addPage(page);
|
|
553
|
+
});
|
|
554
|
+
return [3 /*break*/, 17];
|
|
555
|
+
case 12:
|
|
556
|
+
if (!fileData.startsWith('data:image/png;base64,iVBOR')) return [3 /*break*/, 16];
|
|
557
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
558
|
+
case 13:
|
|
559
|
+
pdf = _a.sent();
|
|
560
|
+
return [4 /*yield*/, pdf.embedPng(fileData)];
|
|
561
|
+
case 14:
|
|
562
|
+
img = _a.sent();
|
|
563
|
+
page = pdf.addPage();
|
|
564
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
565
|
+
page.drawImage(img, {
|
|
566
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
567
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
568
|
+
width: imgDim.width,
|
|
569
|
+
height: imgDim.height,
|
|
570
|
+
});
|
|
571
|
+
return [4 /*yield*/, mergedPdf_2.copyPages(pdf, pdf.getPageIndices())];
|
|
572
|
+
case 15:
|
|
573
|
+
copiedPages = _a.sent();
|
|
574
|
+
copiedPages.forEach(function (page) {
|
|
575
|
+
mergedPdf_2.addPage(page);
|
|
576
|
+
});
|
|
577
|
+
return [3 /*break*/, 17];
|
|
578
|
+
case 16:
|
|
579
|
+
console.log('Error - unsupported!!', fileData.slice(0, 60));
|
|
580
|
+
_a.label = 17;
|
|
581
|
+
case 17: return [3 /*break*/, 19];
|
|
582
|
+
case 18:
|
|
583
|
+
error_2 = _a.sent();
|
|
584
|
+
console.log('Error processing fileData:', fileData.slice(0, 60), error_2);
|
|
585
|
+
return [3 /*break*/, 19];
|
|
586
|
+
case 19: return [3 /*break*/, 21];
|
|
587
|
+
case 20:
|
|
588
|
+
console.log('Error - no filedata!!', fileData);
|
|
589
|
+
_a.label = 21;
|
|
590
|
+
case 21:
|
|
591
|
+
i++;
|
|
592
|
+
return [3 /*break*/, 4];
|
|
593
|
+
case 22: return [4 /*yield*/, mergedPdf_2.save()];
|
|
594
|
+
case 23:
|
|
595
|
+
mergedPDFUint8 = _a.sent();
|
|
596
|
+
b64PDF = 'data:application/pdf;base64,' + Buffer.from(mergedPDFUint8).toString('base64');
|
|
597
|
+
return [2 /*return*/, b64PDF];
|
|
598
|
+
case 24: throw new Error('Error in Merge PDF Resolve No Save: No signed urls');
|
|
599
|
+
case 25: return [3 /*break*/, 27];
|
|
600
|
+
case 26:
|
|
601
|
+
err_2 = _a.sent();
|
|
602
|
+
err_2.message = "Error in Merge PDF Resolve: ".concat(err_2.message);
|
|
603
|
+
throw err_2;
|
|
604
|
+
case 27: return [2 /*return*/];
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
},
|
|
609
|
+
workerTaskWeight: 2
|
|
610
|
+
},
|
|
611
|
+
mergePDFResolveHtml: {
|
|
612
|
+
check: new simpl_schema_1.default({
|
|
613
|
+
htmls: {
|
|
614
|
+
type: Array
|
|
615
|
+
},
|
|
616
|
+
'htmls.$': {
|
|
617
|
+
type: String
|
|
618
|
+
},
|
|
619
|
+
fileName: {
|
|
620
|
+
type: String
|
|
621
|
+
},
|
|
622
|
+
fileType: {
|
|
623
|
+
type: String,
|
|
624
|
+
optional: true
|
|
625
|
+
},
|
|
626
|
+
save: {
|
|
627
|
+
type: Boolean,
|
|
628
|
+
optional: true
|
|
629
|
+
}
|
|
630
|
+
}),
|
|
631
|
+
function: function (htmls, fileName, fileType, save) {
|
|
632
|
+
if (save === void 0) { save = true; }
|
|
633
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
634
|
+
var mergedPdf, i, fileData, pdf, copiedPages, pdf, img, page, imgDim, copiedPages, pdf, img, page, imgDim, copiedPages, error_3, mergedPDFUint8, b64PDF;
|
|
635
|
+
return __generator(this, function (_a) {
|
|
636
|
+
switch (_a.label) {
|
|
637
|
+
case 0: return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
638
|
+
case 1:
|
|
639
|
+
mergedPdf = _a.sent();
|
|
640
|
+
i = 0;
|
|
641
|
+
_a.label = 2;
|
|
642
|
+
case 2:
|
|
643
|
+
if (!(i < htmls.length)) return [3 /*break*/, 20];
|
|
644
|
+
fileData = htmls[i];
|
|
645
|
+
if (!fileData) return [3 /*break*/, 18];
|
|
646
|
+
_a.label = 3;
|
|
647
|
+
case 3:
|
|
648
|
+
_a.trys.push([3, 16, , 17]);
|
|
649
|
+
if (!fileData.startsWith('data:application/pdf;base64,')) return [3 /*break*/, 6];
|
|
650
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.load(fileData, { updateMetadata: false, parseSpeed: pdf_lib_1.ParseSpeeds.Fastest, ignoreEncryption: true })];
|
|
651
|
+
case 4:
|
|
652
|
+
pdf = _a.sent();
|
|
653
|
+
return [4 /*yield*/, mergedPdf.copyPages(pdf, pdf.getPageIndices())];
|
|
654
|
+
case 5:
|
|
655
|
+
copiedPages = _a.sent();
|
|
656
|
+
copiedPages.forEach(function (page) {
|
|
657
|
+
mergedPdf.addPage(page);
|
|
658
|
+
});
|
|
659
|
+
return [3 /*break*/, 15];
|
|
660
|
+
case 6:
|
|
661
|
+
if (!(fileData.startsWith('data:image/jpeg;base64,/9j/') || fileData.startsWith('data:image/png;base64,/9j/'))) return [3 /*break*/, 10];
|
|
662
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
663
|
+
case 7:
|
|
664
|
+
pdf = _a.sent();
|
|
665
|
+
return [4 /*yield*/, pdf.embedJpg(fileData)];
|
|
666
|
+
case 8:
|
|
667
|
+
img = _a.sent();
|
|
668
|
+
page = pdf.addPage();
|
|
669
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
670
|
+
page.drawImage(img, {
|
|
671
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
672
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
673
|
+
width: imgDim.width,
|
|
674
|
+
height: imgDim.height,
|
|
675
|
+
});
|
|
676
|
+
return [4 /*yield*/, mergedPdf.copyPages(pdf, pdf.getPageIndices())];
|
|
677
|
+
case 9:
|
|
678
|
+
copiedPages = _a.sent();
|
|
679
|
+
copiedPages.forEach(function (page) {
|
|
680
|
+
mergedPdf.addPage(page);
|
|
681
|
+
});
|
|
682
|
+
return [3 /*break*/, 15];
|
|
683
|
+
case 10:
|
|
684
|
+
if (!fileData.startsWith('data:image/png;base64,iVBOR')) return [3 /*break*/, 14];
|
|
685
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.create()];
|
|
686
|
+
case 11:
|
|
687
|
+
pdf = _a.sent();
|
|
688
|
+
return [4 /*yield*/, pdf.embedPng(fileData)];
|
|
689
|
+
case 12:
|
|
690
|
+
img = _a.sent();
|
|
691
|
+
page = pdf.addPage();
|
|
692
|
+
imgDim = img.scaleToFit(page.getWidth() * 0.75, page.getHeight() * 0.75);
|
|
693
|
+
page.drawImage(img, {
|
|
694
|
+
x: page.getWidth() / 2 - imgDim.width / 2,
|
|
695
|
+
y: page.getHeight() / 2 - imgDim.height / 2,
|
|
696
|
+
width: imgDim.width,
|
|
697
|
+
height: imgDim.height,
|
|
698
|
+
});
|
|
699
|
+
return [4 /*yield*/, mergedPdf.copyPages(pdf, pdf.getPageIndices())];
|
|
700
|
+
case 13:
|
|
701
|
+
copiedPages = _a.sent();
|
|
702
|
+
copiedPages.forEach(function (page) {
|
|
703
|
+
mergedPdf.addPage(page);
|
|
704
|
+
});
|
|
705
|
+
return [3 /*break*/, 15];
|
|
706
|
+
case 14:
|
|
707
|
+
console.log('Error - unsupported!!', fileData.slice(0, 60));
|
|
708
|
+
throw new Error('Error in Merge PDF Resolve HTML: Unsupported file - ' + fileData.slice(0, 60));
|
|
709
|
+
case 15: return [3 /*break*/, 17];
|
|
710
|
+
case 16:
|
|
711
|
+
error_3 = _a.sent();
|
|
712
|
+
console.log('Error processing fileData:', fileData.slice(0, 60), error_3);
|
|
713
|
+
error_3.message = "Error in Merge PDF Resolve HTML: Error processing filedata - ".concat(error_3.message);
|
|
714
|
+
throw error_3;
|
|
715
|
+
case 17: return [3 /*break*/, 19];
|
|
716
|
+
case 18:
|
|
717
|
+
console.log('Error - no filedata!!', fileData);
|
|
718
|
+
throw new Error('Error in Merge PDF Resolve HTML: No File data');
|
|
719
|
+
case 19:
|
|
720
|
+
i++;
|
|
721
|
+
return [3 /*break*/, 2];
|
|
722
|
+
case 20: return [4 /*yield*/, mergedPdf.save()];
|
|
723
|
+
case 21:
|
|
724
|
+
mergedPDFUint8 = _a.sent();
|
|
725
|
+
b64PDF = 'data:application/pdf;base64,' + Buffer.from(mergedPDFUint8).toString('base64');
|
|
726
|
+
if (save) {
|
|
727
|
+
return [2 /*return*/, this.callMethod('uploadFileAndSave', fileName, b64PDF, (4 * Math.ceil(b64PDF.length / 3)), -1, fileType, false)];
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
return [2 /*return*/, b64PDF];
|
|
731
|
+
}
|
|
732
|
+
return [2 /*return*/];
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
},
|
|
737
|
+
workerTaskWeight: 2
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
exports.loadPDFMethods = loadPDFMethods;
|
|
742
|
+
|
|
2
743
|
//# sourceMappingURL=pdf.js.map
|