Преглед изворни кода

Merge branch 'master' of http://git.fmode.cn:3000/bin/edu-textbook

warrior пре 1 месец
родитељ
комит
86810a9934

+ 2 - 1
server/cloud/tbook/func-tbook-export.js

@@ -612,7 +612,8 @@ function renderReportDocsByTextbook(textbook){
     lastPageList.push(json?.unitMaterial?.url||docx8);
     lastPageList.push(docx9);
     let lastPageFileName = path.join(bookTempDir,`${bookid}_${bookData.title}_申报书及附件_789.pdf`)
-    let lastPagePdf = await docxToPdf(null,lastPageFileName,{mergeFiles:lastPageList,tempDir:bookTempDir}) // 成功用pdf,失败继续用docx
+    console.log(lastPageList)
+    let lastPagePdf = await docxToPdf(null,lastPageFileName,{mergeFiles:lastPageList,tempDir:bookTempDir,mergeAll:true}) // 成功用pdf,失败继续用docx
     docx7&&fs.rmSync(docx7)
     docx8&&fs.rmSync(docx8)
     docx9&&fs.rmSync(docx9)

+ 3 - 1
server/cloud/tbook/test/test-export.js

@@ -38,7 +38,9 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["VK81UnQmkn"]))
         // console.log(await exportProcessReportDocs(null,["SD0NCAdscz"]))
         // console.log(await exportProcessReportDocs(null,["sbVgvo4qEk"]))
-        console.log(await exportProcessReportDocs(null,["4LnH46Mu03"]))
+        // console.log(await exportProcessReportDocs(null,["4LnH46Mu03"]))
+        console.log(await exportProcessReportDocs(null,["xdIAG8BYnX"]))
+        
         
         // console.log(await exportProcessReportDocs(null,["3wJSkW9HNV"]))
         // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))

+ 8 - 3
server/lib/docs/index.js

@@ -200,7 +200,7 @@ async function downloadUrl(url,options) {
             files.push({ data: docxBuffer, ext: "docx" })
         }
         files = [...files,...filePathList]
-
+        // console.log("files",files)
         let convertOpts = {
             files,
             properties: {
@@ -252,8 +252,13 @@ async function downloadUrl(url,options) {
         }
 
         // 方式2:先合并pdf,后合并docx
-        if(files?.length>4){
-            let pdfList = [mainPdfPath,...files.slice(1)];
+        if(files?.length>=2){
+            // console.log(files)
+            let tmpFiles = files 
+            if(docxPath){
+                tmpFiles = files.slice(1) // 携带首个docx时,从第二个开始
+            }
+            let pdfList = [mainPdfPath,...tmpFiles];
             pdfList = pdfList.filter(item=>item)
             let mergedFileList = await mergePdfListReduce(pdfList,convertOpts) 
             pdfPath = mergedFileList[0];