zhangyuhan 3 жил өмнө
parent
commit
752756973a
1 өөрчлөгдсөн 16 нэмэгдсэн , 2 устгасан
  1. 16 2
      bin/create-pdf/pdf.js

+ 16 - 2
bin/create-pdf/pdf.js

@@ -19,6 +19,15 @@ function checkCache (fPath) {
   }
 }
 
+function wait(ms) {
+  return new Promise((resolve, reject) => {
+    setTimeout(() => {
+      console.log("Done waiting");
+      resolve(ms)
+    }, ms)
+  })
+}
+
 
 async function createPDFOfURL (url, config = {}) {
   config = Object.assign( {
@@ -26,7 +35,11 @@ async function createPDFOfURL (url, config = {}) {
     dir: '',
     cache: true,
     width: '950px',
-    height: '1360px'
+    height: '1360px',
+    margin: {
+      top: 0,
+      bottom: 0
+    },
   }, config)
   // 文件路径
   const outPath = path.join(PATH_FILES, config.dir)
@@ -46,12 +59,13 @@ async function createPDFOfURL (url, config = {}) {
   // 生成
   logger.log.debug('启动', new Date().toLocaleString())
   const browser = await puppeteer.launch({
-    headless:true,
+    headless: true,
     args: ['--no-sandbox', '--disable-setuid-sandbox']
   });
   const page = await browser.newPage();
   await page.setDefaultNavigationTimeout(0)
   await page.goto(url, {waitUntil: 'networkidle2'});
+  await wait(1000)
   logger.log.debug('等待生成', new Date().toLocaleString())
 
   await page.pdf(outConfig);