pim-import 3.4.0 → 3.4.1
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/libs/puppeteer.js +38 -45
- package/dist/libs/puppeteer.js.map +1 -1
- package/package.json +1 -1
- package/src/libs/puppeteer.ts +61 -75
package/dist/libs/puppeteer.js
CHANGED
|
@@ -17,53 +17,46 @@ const generatePDFByUrl = async (url, path = "", contents) => {
|
|
|
17
17
|
const browser = await puppeteer_core_1.default.connect({
|
|
18
18
|
browserWSEndpoint: `wss://chrome.browserless.io?token=${process.env.BROWSERLESS_TOKEN}`,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (res.status() !== 200) {
|
|
27
|
-
await browser.close();
|
|
28
|
-
throw new Error(`Error ${res.status()} - ${res.url()}`);
|
|
29
|
-
}
|
|
30
|
-
const headerLeft = contents?.header?.left ??
|
|
31
|
-
'<a href="https://flos.com"><?xml version="1.0" encoding="UTF-8"?><svg style="width: 100%;" width="116px" height="44px" viewBox="0 0 116 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Flos_logo</title> <defs> <polygon id="path-1" points="0.06 0.039 115.026 0.039 115.026 43.986 0.06 43.986"></polygon> </defs> <g id="Product-finder" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="03_Components/Footer/1680" transform="translate(-1377.000000, -598.000000)"> <g id="Flos_logo" transform="translate(1377.000000, 598.000000)"> <g id="Group-5"> <mask id="mask-2" fill="white"> <use xlink:href="#path-1"></use> </mask> <g id="Clip-2"></g> <path d="M103.938,43.986 C103.389,43.986 102.841,43.954 102.303,43.89 C101.425,43.762 100.579,43.569 99.749,43.314 C98.201,42.819 96.748,42.118 95.359,41.256 C95.072,41.063 94.817,40.793 94.77,40.441 L94.753,39.483 L94.625,35.796 L94.513,32.795 C94.545,32.636 94.609,32.46 94.77,32.395 C94.858,32.377 94.952,32.355 95.04,32.355 C95.11,32.355 95.176,32.369 95.232,32.412 C95.487,32.523 95.535,32.795 95.615,33.003 C96.126,34.631 96.557,36.274 97.323,37.792 C98.169,39.468 99.701,41.111 101.441,41.83 C102.511,42.356 103.708,42.612 104.969,42.66 C106.246,42.612 107.491,42.356 108.545,41.734 C109.87,40.968 111.194,39.707 111.674,38.255 C111.945,37.456 112.2,36.626 112.152,35.701 C112.041,34.406 111.833,33.163 111.194,32.108 C110.828,31.47 110.396,30.895 109.902,30.337 C109.902,30.337 106.519,26.745 106.39,26.601 L100.563,20.328 C99.206,18.891 97.898,17.359 96.716,15.81 C96.253,15.108 95.806,14.406 95.503,13.64 C95.152,12.809 94.896,11.964 94.785,11.054 C94.641,10.224 94.641,9.33 94.673,8.468 C94.833,7.015 95.264,5.642 96.03,4.429 C96.461,3.646 97.195,2.961 97.865,2.322 C98.249,2.002 98.68,1.763 99.095,1.492 C100.053,0.965 101.074,0.566 102.176,0.359 C103.002,0.162 103.884,0.061 104.767,0.061 C105.537,0.061 106.308,0.138 107.044,0.295 C108.225,0.534 109.327,0.949 110.381,1.476 C111.051,1.827 111.737,2.21 112.296,2.753 C112.521,2.945 112.567,3.2 112.615,3.455 L112.759,4.828 C112.855,6.312 113.063,7.717 113.143,9.202 C113.126,9.425 112.983,9.665 112.759,9.745 C112.615,9.745 112.488,9.713 112.408,9.601 C112.168,9.266 112.136,8.835 111.993,8.452 C111.643,7.255 111.258,6.104 110.524,5.083 L110.492,5.036 C110.141,4.589 109.774,4.094 109.327,3.679 C108.481,2.817 107.491,2.258 106.47,1.827 C105.714,1.55 104.832,1.414 103.948,1.414 C103,1.414 102.05,1.569 101.25,1.874 C100.1,2.306 98.951,3.216 98.36,4.365 C97.771,5.354 97.626,6.648 97.738,7.861 L97.757,8.027 C97.869,9.112 98.36,10.048 98.887,10.974 C99.334,11.692 99.877,12.363 100.437,13.033 L102.782,15.538 L105.959,18.874 L108.609,21.669 C111.003,24.175 113.525,26.681 114.515,29.842 C114.866,31.07 115.09,32.428 115.01,33.768 L114.994,33.801 C115.042,34.089 114.962,34.406 114.93,34.694 C114.675,36.194 114.371,37.68 113.525,38.957 C113.015,39.818 112.393,40.585 111.626,41.303 C111.131,41.798 110.572,42.196 109.982,42.517 C108.736,43.171 107.364,43.586 105.943,43.842 C105.284,43.938 104.61,43.986 103.938,43.986" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path> <path d="M22.857,43.785 C22.667,43.785 22.479,43.772 22.296,43.729 C22.153,43.698 22.041,43.554 21.977,43.41 C21.93,43.251 21.914,43.075 22.025,42.948 C22.185,42.724 22.457,42.692 22.695,42.612 C23.638,42.484 24.58,42.373 25.346,41.813 C25.904,41.303 26.191,40.617 26.255,39.867 L26.224,18.668 L26.319,3.87 C26.239,3.152 26.128,2.418 25.441,1.987 C24.611,1.316 23.431,1.444 22.457,1.125 C22.313,1.013 22.266,0.853 22.266,0.694 C22.266,0.55 22.296,0.39 22.424,0.311 C22.601,0.215 22.808,0.167 23.016,0.151 L34.477,0.199 C34.535,0.199 34.56,0.199 34.687,0.192 C34.719,0.194 34.752,0.194 34.786,0.194 C34.846,0.194 34.907,0.192 34.968,0.19 C35.03,0.188 35.092,0.186 35.154,0.186 C35.429,0.186 35.692,0.228 35.833,0.502 C35.881,0.646 35.93,0.837 35.85,0.981 C35.706,1.22 35.451,1.22 35.21,1.252 C34.062,1.252 32.913,1.348 31.938,1.843 C31.603,1.987 31.285,2.29 31.044,2.609 C30.9,2.928 30.773,3.248 30.789,3.631 L30.726,8.627 L30.598,19.657 C30.565,21.462 30.598,23.329 30.582,25.133 L30.582,34.95 L30.613,40.713 C30.623,41.362 30.492,42.011 30.997,42.228 C31.279,42.309 31.587,42.33 31.897,42.33 C32.147,42.33 32.399,42.316 32.641,42.308 C34.173,42.213 35.659,42.038 37.079,41.671 C38.291,41.367 39.474,40.968 40.526,40.234 C42.027,39.02 42.426,37.281 43.097,35.7 L43.911,33.322 C43.991,33.178 44.119,33.067 44.277,33.067 C44.47,33.083 44.662,33.178 44.756,33.353 L44.82,33.593 L44.692,34.79 L43.64,43.314 C43.543,43.601 43.241,43.618 42.984,43.634 L39.889,43.618 L35.387,43.65 L29.161,43.729 L23.782,43.762 C23.742,43.76 23.703,43.76 23.664,43.76 C23.53,43.76 23.395,43.766 23.26,43.772 C23.125,43.779 22.99,43.785 22.857,43.785" id="Fill-3" fill="#000000" mask="url(#mask-2)"></path> <path d="M13.23,43.475 L6.654,43.458 L1.098,43.475 C0.715,43.458 0.252,43.522 0.045,43.155 C-0.019,42.995 -0.019,42.804 0.077,42.66 C0.108,42.533 0.236,42.5 0.348,42.468 C1.354,42.309 2.375,42.149 3.221,41.59 C3.764,41.112 3.972,40.441 4.115,39.787 C4.259,38.574 4.291,37.329 4.339,36.083 L4.371,34.423 L4.498,23.84 L4.515,21.605 L4.546,17.886 L4.53,13.767 L4.498,12.554 L4.45,7.27 L4.387,3.71 C4.291,3.008 4.163,2.258 3.509,1.811 C2.726,1.284 1.785,1.172 0.859,0.997 C0.715,0.933 0.588,0.789 0.556,0.645 C0.524,0.518 0.571,0.374 0.619,0.262 C0.731,0.071 0.939,0.071 1.13,0.039 C1.602,0.051 2.071,0.055 2.54,0.055 C3.008,0.055 3.475,0.051 3.944,0.047 C4.411,0.043 4.88,0.039 5.35,0.039 C5.824,0.039 6.3,0.043 6.781,0.055 L10.293,0.071 L17.827,0.055 L19.775,0.039 C19.966,0.071 20.11,0.198 20.19,0.358 L20.238,0.55 L20.43,4.397 L20.749,8.898 C20.749,9.122 20.749,9.329 20.573,9.473 C20.491,9.537 20.378,9.564 20.267,9.564 C20.182,9.564 20.099,9.549 20.03,9.521 C19.823,9.441 19.759,9.202 19.695,9.026 C19.248,7.605 18.801,6.201 18.195,4.86 C17.795,4.03 17.253,3.088 16.375,2.609 C14.38,1.508 11.857,1.571 9.479,1.508 C9.351,1.539 9.159,1.508 9.096,1.651 L9.064,1.97 L8.968,7.478 L8.952,9.441 L8.824,19.29 L8.84,20.232 C8.856,20.328 8.984,20.36 9.064,20.376 C9.314,20.381 9.566,20.384 9.818,20.384 C11.171,20.384 12.532,20.295 13.757,19.945 C14.874,19.53 15.449,18.396 15.8,17.375 C16.088,16.465 16.327,15.523 16.614,14.629 C16.699,14.489 16.846,14.385 17.011,14.385 C17.032,14.385 17.055,14.386 17.077,14.39 C17.237,14.437 17.412,14.517 17.492,14.677 L17.556,14.916 L17.428,20.104 L17.412,22.18 L17.54,27.432 C17.524,27.639 17.38,27.831 17.189,27.894 C17.147,27.907 17.103,27.913 17.059,27.913 C16.934,27.913 16.809,27.865 16.726,27.782 C16.598,27.671 16.55,27.543 16.503,27.399 C16.135,26.362 15.992,25.244 15.561,24.239 C15.257,23.489 14.874,22.61 14.044,22.259 C13.358,21.908 12.512,21.908 11.698,21.828 C11.027,21.794 10.365,21.734 9.699,21.734 C9.446,21.734 9.191,21.743 8.936,21.765 L8.824,21.94 L8.713,28.629 L8.713,28.932 L8.76,34.471 L8.84,39.084 C8.888,39.531 8.856,40.01 9.048,40.409 C9.191,41.064 9.782,41.67 10.437,41.878 C11.363,42.277 12.432,42.293 13.438,42.5 C13.581,42.533 13.693,42.66 13.741,42.788 C13.773,42.931 13.821,43.139 13.709,43.251 C13.597,43.442 13.406,43.442 13.23,43.475" id="Fill-4" fill="#000000" mask="url(#mask-2)"></path> </g> <path d="M69.161,44 C61.377,44 53.858,40.286 50,33.602 C43.185,21.799 48.795,9.012 59,3.12 C62.599,1.042 66.558,0.052 70.458,0.03 L70.73,0.03 C78.47,0.075 85.934,3.927 89.814,10.649 C95.6,20.668 92.782,34.367 80.823,41.006 C77.167,43.035 73.13,44 69.161,44 M68.056,1.896 C65.21,1.896 62.354,2.659 59.644,4.261 C51.285,9.203 48.923,21.517 54.271,31.095 C57.575,37.014 64.48,42.234 71.875,42.234 C74.626,42.234 77.444,41.512 80.171,39.835 C90.623,33.405 89.577,19.536 85.518,13.057 C81.044,5.915 74.581,1.896 68.056,1.896" id="Fill-6" fill="#000000"></path> </g> </g> </g> </svg></a>';
|
|
32
|
-
const headerRight = contents?.header?.right ?? "";
|
|
33
|
-
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
34
|
-
const footerLeft = contents?.footer?.left ?? "";
|
|
35
|
-
const footerRight = contents?.footer?.right ?? "www.flos.com - info@flos.com";
|
|
36
|
-
const footerTemplate = `<div class="pdf-footer" style="margin: 0 32px; padding: 10px 0; width: 100%; border-top: 0.3pt solid #000000; font-size: 4pt; font-weight:300;"> <div class="pdf-row" style="margin:0; padding: 0"> <span class="left" style="margin:0; padding: 0; width: 70%; white-space: normal; overflow: hidden; text-overflow: hidden; float: left;">${footerLeft}</span> <span class="right" style="margin:0; padding: 0; width: 30%; float: right; text-align: right;">${footerRight}</span> </div> </div>`;
|
|
37
|
-
const options = {
|
|
38
|
-
format: "a4",
|
|
39
|
-
printBackground: true,
|
|
40
|
-
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
41
|
-
headerTemplate,
|
|
42
|
-
footerTemplate,
|
|
43
|
-
margin: {
|
|
44
|
-
top: "110px",
|
|
45
|
-
left: "44px",
|
|
46
|
-
right: "44px",
|
|
47
|
-
bottom: "60px",
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
if (path) {
|
|
51
|
-
options.path = path;
|
|
52
|
-
}
|
|
53
|
-
logs_1.log(`Before page.pdf - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
54
|
-
const pdf = await page.pdf(options);
|
|
55
|
-
logs_1.log(`After page.pdf - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
56
|
-
const timeEnd = new Date();
|
|
57
|
-
const seconds = utils_1.secondBetweenTwoDate(timeStart, timeEnd);
|
|
58
|
-
logs_1.log(`Request time: ${seconds} seconds - generatePDFByUrl`);
|
|
59
|
-
return pdf;
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
throw new Error(err);
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
20
|
+
logs_1.log(`After puppeteer.connect - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
21
|
+
const page = await browser.newPage();
|
|
22
|
+
logs_1.log(`Before page.goto - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
23
|
+
const res = await page.goto(url, { waitUntil: "networkidle0", timeout: 0 });
|
|
24
|
+
logs_1.log(`After page.goto - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
25
|
+
if (res.status() !== 200) {
|
|
65
26
|
await browser.close();
|
|
27
|
+
throw new Error(`Error ${res.status()} - ${res.url()}`);
|
|
28
|
+
}
|
|
29
|
+
const headerLeft = contents?.header?.left ??
|
|
30
|
+
'<a href="https://flos.com"><?xml version="1.0" encoding="UTF-8"?><svg style="width: 100%;" width="116px" height="44px" viewBox="0 0 116 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Flos_logo</title> <defs> <polygon id="path-1" points="0.06 0.039 115.026 0.039 115.026 43.986 0.06 43.986"></polygon> </defs> <g id="Product-finder" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="03_Components/Footer/1680" transform="translate(-1377.000000, -598.000000)"> <g id="Flos_logo" transform="translate(1377.000000, 598.000000)"> <g id="Group-5"> <mask id="mask-2" fill="white"> <use xlink:href="#path-1"></use> </mask> <g id="Clip-2"></g> <path d="M103.938,43.986 C103.389,43.986 102.841,43.954 102.303,43.89 C101.425,43.762 100.579,43.569 99.749,43.314 C98.201,42.819 96.748,42.118 95.359,41.256 C95.072,41.063 94.817,40.793 94.77,40.441 L94.753,39.483 L94.625,35.796 L94.513,32.795 C94.545,32.636 94.609,32.46 94.77,32.395 C94.858,32.377 94.952,32.355 95.04,32.355 C95.11,32.355 95.176,32.369 95.232,32.412 C95.487,32.523 95.535,32.795 95.615,33.003 C96.126,34.631 96.557,36.274 97.323,37.792 C98.169,39.468 99.701,41.111 101.441,41.83 C102.511,42.356 103.708,42.612 104.969,42.66 C106.246,42.612 107.491,42.356 108.545,41.734 C109.87,40.968 111.194,39.707 111.674,38.255 C111.945,37.456 112.2,36.626 112.152,35.701 C112.041,34.406 111.833,33.163 111.194,32.108 C110.828,31.47 110.396,30.895 109.902,30.337 C109.902,30.337 106.519,26.745 106.39,26.601 L100.563,20.328 C99.206,18.891 97.898,17.359 96.716,15.81 C96.253,15.108 95.806,14.406 95.503,13.64 C95.152,12.809 94.896,11.964 94.785,11.054 C94.641,10.224 94.641,9.33 94.673,8.468 C94.833,7.015 95.264,5.642 96.03,4.429 C96.461,3.646 97.195,2.961 97.865,2.322 C98.249,2.002 98.68,1.763 99.095,1.492 C100.053,0.965 101.074,0.566 102.176,0.359 C103.002,0.162 103.884,0.061 104.767,0.061 C105.537,0.061 106.308,0.138 107.044,0.295 C108.225,0.534 109.327,0.949 110.381,1.476 C111.051,1.827 111.737,2.21 112.296,2.753 C112.521,2.945 112.567,3.2 112.615,3.455 L112.759,4.828 C112.855,6.312 113.063,7.717 113.143,9.202 C113.126,9.425 112.983,9.665 112.759,9.745 C112.615,9.745 112.488,9.713 112.408,9.601 C112.168,9.266 112.136,8.835 111.993,8.452 C111.643,7.255 111.258,6.104 110.524,5.083 L110.492,5.036 C110.141,4.589 109.774,4.094 109.327,3.679 C108.481,2.817 107.491,2.258 106.47,1.827 C105.714,1.55 104.832,1.414 103.948,1.414 C103,1.414 102.05,1.569 101.25,1.874 C100.1,2.306 98.951,3.216 98.36,4.365 C97.771,5.354 97.626,6.648 97.738,7.861 L97.757,8.027 C97.869,9.112 98.36,10.048 98.887,10.974 C99.334,11.692 99.877,12.363 100.437,13.033 L102.782,15.538 L105.959,18.874 L108.609,21.669 C111.003,24.175 113.525,26.681 114.515,29.842 C114.866,31.07 115.09,32.428 115.01,33.768 L114.994,33.801 C115.042,34.089 114.962,34.406 114.93,34.694 C114.675,36.194 114.371,37.68 113.525,38.957 C113.015,39.818 112.393,40.585 111.626,41.303 C111.131,41.798 110.572,42.196 109.982,42.517 C108.736,43.171 107.364,43.586 105.943,43.842 C105.284,43.938 104.61,43.986 103.938,43.986" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path> <path d="M22.857,43.785 C22.667,43.785 22.479,43.772 22.296,43.729 C22.153,43.698 22.041,43.554 21.977,43.41 C21.93,43.251 21.914,43.075 22.025,42.948 C22.185,42.724 22.457,42.692 22.695,42.612 C23.638,42.484 24.58,42.373 25.346,41.813 C25.904,41.303 26.191,40.617 26.255,39.867 L26.224,18.668 L26.319,3.87 C26.239,3.152 26.128,2.418 25.441,1.987 C24.611,1.316 23.431,1.444 22.457,1.125 C22.313,1.013 22.266,0.853 22.266,0.694 C22.266,0.55 22.296,0.39 22.424,0.311 C22.601,0.215 22.808,0.167 23.016,0.151 L34.477,0.199 C34.535,0.199 34.56,0.199 34.687,0.192 C34.719,0.194 34.752,0.194 34.786,0.194 C34.846,0.194 34.907,0.192 34.968,0.19 C35.03,0.188 35.092,0.186 35.154,0.186 C35.429,0.186 35.692,0.228 35.833,0.502 C35.881,0.646 35.93,0.837 35.85,0.981 C35.706,1.22 35.451,1.22 35.21,1.252 C34.062,1.252 32.913,1.348 31.938,1.843 C31.603,1.987 31.285,2.29 31.044,2.609 C30.9,2.928 30.773,3.248 30.789,3.631 L30.726,8.627 L30.598,19.657 C30.565,21.462 30.598,23.329 30.582,25.133 L30.582,34.95 L30.613,40.713 C30.623,41.362 30.492,42.011 30.997,42.228 C31.279,42.309 31.587,42.33 31.897,42.33 C32.147,42.33 32.399,42.316 32.641,42.308 C34.173,42.213 35.659,42.038 37.079,41.671 C38.291,41.367 39.474,40.968 40.526,40.234 C42.027,39.02 42.426,37.281 43.097,35.7 L43.911,33.322 C43.991,33.178 44.119,33.067 44.277,33.067 C44.47,33.083 44.662,33.178 44.756,33.353 L44.82,33.593 L44.692,34.79 L43.64,43.314 C43.543,43.601 43.241,43.618 42.984,43.634 L39.889,43.618 L35.387,43.65 L29.161,43.729 L23.782,43.762 C23.742,43.76 23.703,43.76 23.664,43.76 C23.53,43.76 23.395,43.766 23.26,43.772 C23.125,43.779 22.99,43.785 22.857,43.785" id="Fill-3" fill="#000000" mask="url(#mask-2)"></path> <path d="M13.23,43.475 L6.654,43.458 L1.098,43.475 C0.715,43.458 0.252,43.522 0.045,43.155 C-0.019,42.995 -0.019,42.804 0.077,42.66 C0.108,42.533 0.236,42.5 0.348,42.468 C1.354,42.309 2.375,42.149 3.221,41.59 C3.764,41.112 3.972,40.441 4.115,39.787 C4.259,38.574 4.291,37.329 4.339,36.083 L4.371,34.423 L4.498,23.84 L4.515,21.605 L4.546,17.886 L4.53,13.767 L4.498,12.554 L4.45,7.27 L4.387,3.71 C4.291,3.008 4.163,2.258 3.509,1.811 C2.726,1.284 1.785,1.172 0.859,0.997 C0.715,0.933 0.588,0.789 0.556,0.645 C0.524,0.518 0.571,0.374 0.619,0.262 C0.731,0.071 0.939,0.071 1.13,0.039 C1.602,0.051 2.071,0.055 2.54,0.055 C3.008,0.055 3.475,0.051 3.944,0.047 C4.411,0.043 4.88,0.039 5.35,0.039 C5.824,0.039 6.3,0.043 6.781,0.055 L10.293,0.071 L17.827,0.055 L19.775,0.039 C19.966,0.071 20.11,0.198 20.19,0.358 L20.238,0.55 L20.43,4.397 L20.749,8.898 C20.749,9.122 20.749,9.329 20.573,9.473 C20.491,9.537 20.378,9.564 20.267,9.564 C20.182,9.564 20.099,9.549 20.03,9.521 C19.823,9.441 19.759,9.202 19.695,9.026 C19.248,7.605 18.801,6.201 18.195,4.86 C17.795,4.03 17.253,3.088 16.375,2.609 C14.38,1.508 11.857,1.571 9.479,1.508 C9.351,1.539 9.159,1.508 9.096,1.651 L9.064,1.97 L8.968,7.478 L8.952,9.441 L8.824,19.29 L8.84,20.232 C8.856,20.328 8.984,20.36 9.064,20.376 C9.314,20.381 9.566,20.384 9.818,20.384 C11.171,20.384 12.532,20.295 13.757,19.945 C14.874,19.53 15.449,18.396 15.8,17.375 C16.088,16.465 16.327,15.523 16.614,14.629 C16.699,14.489 16.846,14.385 17.011,14.385 C17.032,14.385 17.055,14.386 17.077,14.39 C17.237,14.437 17.412,14.517 17.492,14.677 L17.556,14.916 L17.428,20.104 L17.412,22.18 L17.54,27.432 C17.524,27.639 17.38,27.831 17.189,27.894 C17.147,27.907 17.103,27.913 17.059,27.913 C16.934,27.913 16.809,27.865 16.726,27.782 C16.598,27.671 16.55,27.543 16.503,27.399 C16.135,26.362 15.992,25.244 15.561,24.239 C15.257,23.489 14.874,22.61 14.044,22.259 C13.358,21.908 12.512,21.908 11.698,21.828 C11.027,21.794 10.365,21.734 9.699,21.734 C9.446,21.734 9.191,21.743 8.936,21.765 L8.824,21.94 L8.713,28.629 L8.713,28.932 L8.76,34.471 L8.84,39.084 C8.888,39.531 8.856,40.01 9.048,40.409 C9.191,41.064 9.782,41.67 10.437,41.878 C11.363,42.277 12.432,42.293 13.438,42.5 C13.581,42.533 13.693,42.66 13.741,42.788 C13.773,42.931 13.821,43.139 13.709,43.251 C13.597,43.442 13.406,43.442 13.23,43.475" id="Fill-4" fill="#000000" mask="url(#mask-2)"></path> </g> <path d="M69.161,44 C61.377,44 53.858,40.286 50,33.602 C43.185,21.799 48.795,9.012 59,3.12 C62.599,1.042 66.558,0.052 70.458,0.03 L70.73,0.03 C78.47,0.075 85.934,3.927 89.814,10.649 C95.6,20.668 92.782,34.367 80.823,41.006 C77.167,43.035 73.13,44 69.161,44 M68.056,1.896 C65.21,1.896 62.354,2.659 59.644,4.261 C51.285,9.203 48.923,21.517 54.271,31.095 C57.575,37.014 64.48,42.234 71.875,42.234 C74.626,42.234 77.444,41.512 80.171,39.835 C90.623,33.405 89.577,19.536 85.518,13.057 C81.044,5.915 74.581,1.896 68.056,1.896" id="Fill-6" fill="#000000"></path> </g> </g> </g> </svg></a>';
|
|
31
|
+
const headerRight = contents?.header?.right ?? "";
|
|
32
|
+
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
33
|
+
const footerLeft = contents?.footer?.left ?? "";
|
|
34
|
+
const footerRight = contents?.footer?.right ?? "www.flos.com - info@flos.com";
|
|
35
|
+
const footerTemplate = `<div class="pdf-footer" style="margin: 0 32px; padding: 10px 0; width: 100%; border-top: 0.3pt solid #000000; font-size: 4pt; font-weight:300;"> <div class="pdf-row" style="margin:0; padding: 0"> <span class="left" style="margin:0; padding: 0; width: 70%; white-space: normal; overflow: hidden; text-overflow: hidden; float: left;">${footerLeft}</span> <span class="right" style="margin:0; padding: 0; width: 30%; float: right; text-align: right;">${footerRight}</span> </div> </div>`;
|
|
36
|
+
const options = {
|
|
37
|
+
format: "a4",
|
|
38
|
+
printBackground: true,
|
|
39
|
+
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
40
|
+
headerTemplate,
|
|
41
|
+
footerTemplate,
|
|
42
|
+
margin: {
|
|
43
|
+
top: "110px",
|
|
44
|
+
left: "44px",
|
|
45
|
+
right: "44px",
|
|
46
|
+
bottom: "60px",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
if (path) {
|
|
50
|
+
options.path = path;
|
|
66
51
|
}
|
|
52
|
+
logs_1.log(`Before page.pdf - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
53
|
+
const pdf = await page.pdf(options);
|
|
54
|
+
logs_1.log(`After page.pdf - ${utils_1.secondBetweenTwoDate(timeStart, new Date())} seconds`, "DEBUG");
|
|
55
|
+
await browser.close();
|
|
56
|
+
const timeEnd = new Date();
|
|
57
|
+
const seconds = utils_1.secondBetweenTwoDate(timeStart, timeEnd);
|
|
58
|
+
logs_1.log(`Request time: ${seconds} seconds - generatePDFByUrl`);
|
|
59
|
+
return pdf;
|
|
67
60
|
};
|
|
68
61
|
exports.generatePDFByUrl = generatePDFByUrl;
|
|
69
62
|
//# sourceMappingURL=puppeteer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"puppeteer.js","sourceRoot":"","sources":["../../src/libs/puppeteer.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAuC;AACvC,oCAAgD;AAChD,iCAA6B;AAqBtB,MAAM,gBAAgB,GAAG,KAAK,EACnC,GAAW,EACX,OAAe,EAAE,EACjB,QAA6B,EAC7B,EAAE;IACF,UAAG,CAAC,2BAA2B,GAAG,UAAU,IAAI,EAAE,CAAC,CAAC;IAEpD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;QAClC,UAAG,CAAC,kDAAkD,EAAE,OAAO,CAAC,CAAC;KAClE;IAED,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,UAAG,CACD,8BAA8B,4BAAoB,CAChD,SAAS,EACT,IAAI,IAAI,EAAE,CACX,UAAU,EACX,OAAO,CACR,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,wBAAS,CAAC,OAAO,CAAC;QACtC,iBAAiB,EAAE,qCAAqC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;KACxF,CAAC,CAAC;IAEH,
|
|
1
|
+
{"version":3,"file":"puppeteer.js","sourceRoot":"","sources":["../../src/libs/puppeteer.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
package/src/libs/puppeteer.ts
CHANGED
|
@@ -45,86 +45,72 @@ export const generatePDFByUrl = async (
|
|
|
45
45
|
browserWSEndpoint: `wss://chrome.browserless.io?token=${process.env.BROWSERLESS_TOKEN}`,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
log(
|
|
49
|
+
`After puppeteer.connect - ${secondBetweenTwoDate(
|
|
50
|
+
timeStart,
|
|
51
|
+
new Date()
|
|
52
|
+
)} seconds`,
|
|
53
|
+
"DEBUG"
|
|
54
|
+
);
|
|
55
|
+
const page = await browser.newPage();
|
|
56
|
+
|
|
57
|
+
log(
|
|
58
|
+
`Before page.goto - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
59
|
+
"DEBUG"
|
|
60
|
+
);
|
|
61
|
+
const res = await page.goto(url, { waitUntil: "networkidle0", timeout: 0 });
|
|
62
|
+
log(
|
|
63
|
+
`After page.goto - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
64
|
+
"DEBUG"
|
|
65
|
+
);
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)} seconds`,
|
|
63
|
-
"DEBUG"
|
|
64
|
-
);
|
|
65
|
-
const res = await page.goto(url, { waitUntil: "networkidle0", timeout: 0 });
|
|
66
|
-
log(
|
|
67
|
-
`After page.goto - ${secondBetweenTwoDate(
|
|
68
|
-
timeStart,
|
|
69
|
-
new Date()
|
|
70
|
-
)} seconds`,
|
|
71
|
-
"DEBUG"
|
|
72
|
-
);
|
|
67
|
+
if (res.status() !== 200) {
|
|
68
|
+
await browser.close();
|
|
69
|
+
throw new Error(`Error ${res.status()} - ${res.url()}`);
|
|
70
|
+
}
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
const headerLeft =
|
|
73
|
+
contents?.header?.left ??
|
|
74
|
+
'<a href="https://flos.com"><?xml version="1.0" encoding="UTF-8"?><svg style="width: 100%;" width="116px" height="44px" viewBox="0 0 116 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Flos_logo</title> <defs> <polygon id="path-1" points="0.06 0.039 115.026 0.039 115.026 43.986 0.06 43.986"></polygon> </defs> <g id="Product-finder" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="03_Components/Footer/1680" transform="translate(-1377.000000, -598.000000)"> <g id="Flos_logo" transform="translate(1377.000000, 598.000000)"> <g id="Group-5"> <mask id="mask-2" fill="white"> <use xlink:href="#path-1"></use> </mask> <g id="Clip-2"></g> <path d="M103.938,43.986 C103.389,43.986 102.841,43.954 102.303,43.89 C101.425,43.762 100.579,43.569 99.749,43.314 C98.201,42.819 96.748,42.118 95.359,41.256 C95.072,41.063 94.817,40.793 94.77,40.441 L94.753,39.483 L94.625,35.796 L94.513,32.795 C94.545,32.636 94.609,32.46 94.77,32.395 C94.858,32.377 94.952,32.355 95.04,32.355 C95.11,32.355 95.176,32.369 95.232,32.412 C95.487,32.523 95.535,32.795 95.615,33.003 C96.126,34.631 96.557,36.274 97.323,37.792 C98.169,39.468 99.701,41.111 101.441,41.83 C102.511,42.356 103.708,42.612 104.969,42.66 C106.246,42.612 107.491,42.356 108.545,41.734 C109.87,40.968 111.194,39.707 111.674,38.255 C111.945,37.456 112.2,36.626 112.152,35.701 C112.041,34.406 111.833,33.163 111.194,32.108 C110.828,31.47 110.396,30.895 109.902,30.337 C109.902,30.337 106.519,26.745 106.39,26.601 L100.563,20.328 C99.206,18.891 97.898,17.359 96.716,15.81 C96.253,15.108 95.806,14.406 95.503,13.64 C95.152,12.809 94.896,11.964 94.785,11.054 C94.641,10.224 94.641,9.33 94.673,8.468 C94.833,7.015 95.264,5.642 96.03,4.429 C96.461,3.646 97.195,2.961 97.865,2.322 C98.249,2.002 98.68,1.763 99.095,1.492 C100.053,0.965 101.074,0.566 102.176,0.359 C103.002,0.162 103.884,0.061 104.767,0.061 C105.537,0.061 106.308,0.138 107.044,0.295 C108.225,0.534 109.327,0.949 110.381,1.476 C111.051,1.827 111.737,2.21 112.296,2.753 C112.521,2.945 112.567,3.2 112.615,3.455 L112.759,4.828 C112.855,6.312 113.063,7.717 113.143,9.202 C113.126,9.425 112.983,9.665 112.759,9.745 C112.615,9.745 112.488,9.713 112.408,9.601 C112.168,9.266 112.136,8.835 111.993,8.452 C111.643,7.255 111.258,6.104 110.524,5.083 L110.492,5.036 C110.141,4.589 109.774,4.094 109.327,3.679 C108.481,2.817 107.491,2.258 106.47,1.827 C105.714,1.55 104.832,1.414 103.948,1.414 C103,1.414 102.05,1.569 101.25,1.874 C100.1,2.306 98.951,3.216 98.36,4.365 C97.771,5.354 97.626,6.648 97.738,7.861 L97.757,8.027 C97.869,9.112 98.36,10.048 98.887,10.974 C99.334,11.692 99.877,12.363 100.437,13.033 L102.782,15.538 L105.959,18.874 L108.609,21.669 C111.003,24.175 113.525,26.681 114.515,29.842 C114.866,31.07 115.09,32.428 115.01,33.768 L114.994,33.801 C115.042,34.089 114.962,34.406 114.93,34.694 C114.675,36.194 114.371,37.68 113.525,38.957 C113.015,39.818 112.393,40.585 111.626,41.303 C111.131,41.798 110.572,42.196 109.982,42.517 C108.736,43.171 107.364,43.586 105.943,43.842 C105.284,43.938 104.61,43.986 103.938,43.986" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path> <path d="M22.857,43.785 C22.667,43.785 22.479,43.772 22.296,43.729 C22.153,43.698 22.041,43.554 21.977,43.41 C21.93,43.251 21.914,43.075 22.025,42.948 C22.185,42.724 22.457,42.692 22.695,42.612 C23.638,42.484 24.58,42.373 25.346,41.813 C25.904,41.303 26.191,40.617 26.255,39.867 L26.224,18.668 L26.319,3.87 C26.239,3.152 26.128,2.418 25.441,1.987 C24.611,1.316 23.431,1.444 22.457,1.125 C22.313,1.013 22.266,0.853 22.266,0.694 C22.266,0.55 22.296,0.39 22.424,0.311 C22.601,0.215 22.808,0.167 23.016,0.151 L34.477,0.199 C34.535,0.199 34.56,0.199 34.687,0.192 C34.719,0.194 34.752,0.194 34.786,0.194 C34.846,0.194 34.907,0.192 34.968,0.19 C35.03,0.188 35.092,0.186 35.154,0.186 C35.429,0.186 35.692,0.228 35.833,0.502 C35.881,0.646 35.93,0.837 35.85,0.981 C35.706,1.22 35.451,1.22 35.21,1.252 C34.062,1.252 32.913,1.348 31.938,1.843 C31.603,1.987 31.285,2.29 31.044,2.609 C30.9,2.928 30.773,3.248 30.789,3.631 L30.726,8.627 L30.598,19.657 C30.565,21.462 30.598,23.329 30.582,25.133 L30.582,34.95 L30.613,40.713 C30.623,41.362 30.492,42.011 30.997,42.228 C31.279,42.309 31.587,42.33 31.897,42.33 C32.147,42.33 32.399,42.316 32.641,42.308 C34.173,42.213 35.659,42.038 37.079,41.671 C38.291,41.367 39.474,40.968 40.526,40.234 C42.027,39.02 42.426,37.281 43.097,35.7 L43.911,33.322 C43.991,33.178 44.119,33.067 44.277,33.067 C44.47,33.083 44.662,33.178 44.756,33.353 L44.82,33.593 L44.692,34.79 L43.64,43.314 C43.543,43.601 43.241,43.618 42.984,43.634 L39.889,43.618 L35.387,43.65 L29.161,43.729 L23.782,43.762 C23.742,43.76 23.703,43.76 23.664,43.76 C23.53,43.76 23.395,43.766 23.26,43.772 C23.125,43.779 22.99,43.785 22.857,43.785" id="Fill-3" fill="#000000" mask="url(#mask-2)"></path> <path d="M13.23,43.475 L6.654,43.458 L1.098,43.475 C0.715,43.458 0.252,43.522 0.045,43.155 C-0.019,42.995 -0.019,42.804 0.077,42.66 C0.108,42.533 0.236,42.5 0.348,42.468 C1.354,42.309 2.375,42.149 3.221,41.59 C3.764,41.112 3.972,40.441 4.115,39.787 C4.259,38.574 4.291,37.329 4.339,36.083 L4.371,34.423 L4.498,23.84 L4.515,21.605 L4.546,17.886 L4.53,13.767 L4.498,12.554 L4.45,7.27 L4.387,3.71 C4.291,3.008 4.163,2.258 3.509,1.811 C2.726,1.284 1.785,1.172 0.859,0.997 C0.715,0.933 0.588,0.789 0.556,0.645 C0.524,0.518 0.571,0.374 0.619,0.262 C0.731,0.071 0.939,0.071 1.13,0.039 C1.602,0.051 2.071,0.055 2.54,0.055 C3.008,0.055 3.475,0.051 3.944,0.047 C4.411,0.043 4.88,0.039 5.35,0.039 C5.824,0.039 6.3,0.043 6.781,0.055 L10.293,0.071 L17.827,0.055 L19.775,0.039 C19.966,0.071 20.11,0.198 20.19,0.358 L20.238,0.55 L20.43,4.397 L20.749,8.898 C20.749,9.122 20.749,9.329 20.573,9.473 C20.491,9.537 20.378,9.564 20.267,9.564 C20.182,9.564 20.099,9.549 20.03,9.521 C19.823,9.441 19.759,9.202 19.695,9.026 C19.248,7.605 18.801,6.201 18.195,4.86 C17.795,4.03 17.253,3.088 16.375,2.609 C14.38,1.508 11.857,1.571 9.479,1.508 C9.351,1.539 9.159,1.508 9.096,1.651 L9.064,1.97 L8.968,7.478 L8.952,9.441 L8.824,19.29 L8.84,20.232 C8.856,20.328 8.984,20.36 9.064,20.376 C9.314,20.381 9.566,20.384 9.818,20.384 C11.171,20.384 12.532,20.295 13.757,19.945 C14.874,19.53 15.449,18.396 15.8,17.375 C16.088,16.465 16.327,15.523 16.614,14.629 C16.699,14.489 16.846,14.385 17.011,14.385 C17.032,14.385 17.055,14.386 17.077,14.39 C17.237,14.437 17.412,14.517 17.492,14.677 L17.556,14.916 L17.428,20.104 L17.412,22.18 L17.54,27.432 C17.524,27.639 17.38,27.831 17.189,27.894 C17.147,27.907 17.103,27.913 17.059,27.913 C16.934,27.913 16.809,27.865 16.726,27.782 C16.598,27.671 16.55,27.543 16.503,27.399 C16.135,26.362 15.992,25.244 15.561,24.239 C15.257,23.489 14.874,22.61 14.044,22.259 C13.358,21.908 12.512,21.908 11.698,21.828 C11.027,21.794 10.365,21.734 9.699,21.734 C9.446,21.734 9.191,21.743 8.936,21.765 L8.824,21.94 L8.713,28.629 L8.713,28.932 L8.76,34.471 L8.84,39.084 C8.888,39.531 8.856,40.01 9.048,40.409 C9.191,41.064 9.782,41.67 10.437,41.878 C11.363,42.277 12.432,42.293 13.438,42.5 C13.581,42.533 13.693,42.66 13.741,42.788 C13.773,42.931 13.821,43.139 13.709,43.251 C13.597,43.442 13.406,43.442 13.23,43.475" id="Fill-4" fill="#000000" mask="url(#mask-2)"></path> </g> <path d="M69.161,44 C61.377,44 53.858,40.286 50,33.602 C43.185,21.799 48.795,9.012 59,3.12 C62.599,1.042 66.558,0.052 70.458,0.03 L70.73,0.03 C78.47,0.075 85.934,3.927 89.814,10.649 C95.6,20.668 92.782,34.367 80.823,41.006 C77.167,43.035 73.13,44 69.161,44 M68.056,1.896 C65.21,1.896 62.354,2.659 59.644,4.261 C51.285,9.203 48.923,21.517 54.271,31.095 C57.575,37.014 64.48,42.234 71.875,42.234 C74.626,42.234 77.444,41.512 80.171,39.835 C90.623,33.405 89.577,19.536 85.518,13.057 C81.044,5.915 74.581,1.896 68.056,1.896" id="Fill-6" fill="#000000"></path> </g> </g> </g> </svg></a>';
|
|
75
|
+
const headerRight = contents?.header?.right ?? "";
|
|
76
|
+
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const headerRight = contents?.header?.right ?? "";
|
|
83
|
-
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
78
|
+
const footerLeft = contents?.footer?.left ?? "";
|
|
79
|
+
const footerRight = contents?.footer?.right ?? "www.flos.com - info@flos.com";
|
|
80
|
+
const footerTemplate = `<div class="pdf-footer" style="margin: 0 32px; padding: 10px 0; width: 100%; border-top: 0.3pt solid #000000; font-size: 4pt; font-weight:300;"> <div class="pdf-row" style="margin:0; padding: 0"> <span class="left" style="margin:0; padding: 0; width: 70%; white-space: normal; overflow: hidden; text-overflow: hidden; float: left;">${footerLeft}</span> <span class="right" style="margin:0; padding: 0; width: 30%; float: right; text-align: right;">${footerRight}</span> </div> </div>`;
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
// See: https://github.com/puppeteer/puppeteer/blob/v11.0.0/docs/api.md#pagepdfoptions
|
|
83
|
+
const options: PDFOptions = {
|
|
84
|
+
format: "a4",
|
|
85
|
+
printBackground: true,
|
|
86
|
+
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
87
|
+
headerTemplate,
|
|
88
|
+
footerTemplate,
|
|
89
|
+
margin: {
|
|
90
|
+
top: "110px",
|
|
91
|
+
left: "44px",
|
|
92
|
+
right: "44px",
|
|
93
|
+
bottom: "60px",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
if (path) {
|
|
97
|
+
options.path = path;
|
|
98
|
+
}
|
|
99
|
+
log(
|
|
100
|
+
`Before page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
101
|
+
"DEBUG"
|
|
102
|
+
);
|
|
103
|
+
const pdf = await page.pdf(options);
|
|
104
|
+
log(
|
|
105
|
+
`After page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
106
|
+
"DEBUG"
|
|
107
|
+
);
|
|
89
108
|
|
|
90
|
-
|
|
91
|
-
const options: PDFOptions = {
|
|
92
|
-
format: "a4",
|
|
93
|
-
printBackground: true,
|
|
94
|
-
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
95
|
-
headerTemplate,
|
|
96
|
-
footerTemplate,
|
|
97
|
-
margin: {
|
|
98
|
-
top: "110px",
|
|
99
|
-
left: "44px",
|
|
100
|
-
right: "44px",
|
|
101
|
-
bottom: "60px",
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
if (path) {
|
|
105
|
-
options.path = path;
|
|
106
|
-
}
|
|
107
|
-
log(
|
|
108
|
-
`Before page.pdf - ${secondBetweenTwoDate(
|
|
109
|
-
timeStart,
|
|
110
|
-
new Date()
|
|
111
|
-
)} seconds`,
|
|
112
|
-
"DEBUG"
|
|
113
|
-
);
|
|
114
|
-
const pdf = await page.pdf(options);
|
|
115
|
-
log(
|
|
116
|
-
`After page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
117
|
-
"DEBUG"
|
|
118
|
-
);
|
|
109
|
+
await browser.close();
|
|
119
110
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
111
|
+
const timeEnd = new Date();
|
|
112
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
113
|
+
log(`Request time: ${seconds} seconds - generatePDFByUrl`);
|
|
123
114
|
|
|
124
|
-
|
|
125
|
-
} catch (err) {
|
|
126
|
-
throw new Error(err);
|
|
127
|
-
} finally {
|
|
128
|
-
await browser.close();
|
|
129
|
-
}
|
|
115
|
+
return pdf;
|
|
130
116
|
};
|