Przeglądaj źródła

fix: mergepdf after convert to pdf

ryanemax 2 miesięcy temu
rodzic
commit
f6290428b6
1 zmienionych plików z 11 dodań i 0 usunięć
  1. 11 0
      server/lib/docs/index.js

+ 11 - 0
server/lib/docs/index.js

@@ -283,6 +283,17 @@ const sizeOf = require("image-size");
  */
 export async function mergePdfListReduce(pdfList,convertOpts){
     console.log("pdfList",pdfList)
+    // 所有非PDF转PDF
+    for (let index = 0; index < pdfList.length; index++) {
+        let file = pdfList[index];
+        if(file?.toLocaleLowerCase()?.indexOf("pdf")==-1){
+            convertOpts.files = [file];
+            let pdfBuffer = await LibreOffice.convert(convertOpts);
+            fs.writeFileSync(file+".pdf",pdfBuffer)
+            pdfList[index] = file+".pdf"
+        }
+    }
+
     let mergeList = []
     let plist = []
     let length = pdfList.length