소스 검색

fix: pdf merge with pdf engines

ryanemax 2 달 전
부모
커밋
6758747a0e
2개의 변경된 파일18개의 추가작업 그리고 4개의 파일을 삭제
  1. 8 1
      server/cloud/tbook/test/test-export.js
  2. 10 3
      server/lib/docs/index.js

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

@@ -12,6 +12,11 @@ global.Parse = Parse;
  npx vite build
  node temp/test-export.js
 
+ @desc 本地合成测试指令
+ sudo apt install poppler-utils
+ libreoffice --headless --convert-to pdf *.jpg
+ pdfunite 1*.pdf final.pdf
+ libreoffice 更多用法可以在终端输入 libreoffice --help 或者 man libreoffice 。
  */
 import { exportProcessReportDocs } from "../func-tbook-export";
 
@@ -25,7 +30,9 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["c2WUE5PgCo"]))
         // console.log(await exportProcessReportDocs(null,["R9r0XtMsK3"])) // CIP顺序问题,后两个pdf到了最前面
         // console.log(await exportProcessReportDocs(null,["MU5YpUizfW"]))
-        console.log(await exportProcessReportDocs(null,["UUGgHPHsIC"]))
+        // console.log(await exportProcessReportDocs(null,["UUGgHPHsIC"]))
+        console.log(await exportProcessReportDocs(null,["KxhErArSbB"]))
+
         // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))
         // console.log(await exportProcessReportDocs(null,["cgTEtIvkK4"]))
         // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))

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

@@ -14,6 +14,8 @@ const Docxtemplater = require("docxtemplater");
 import { Chromiumly } from "chromiumly";
 // Chromiumly.configure({ endpoint: "http://8.140.98.43/docs" });
 Chromiumly.configure({ endpoint: "http://123.57.204.89/docs" });
+
+import { PDFEngines } from "chromiumly";
 const { LibreOffice } = require("chromiumly");
 // const { PDFEngines } = require("chromiumly");
 const tempDir = path.join(__dirname , "temp");
@@ -277,8 +279,11 @@ export async function mergePdfListReduce(pdfList,convertOpts){
         let file = pdfList.shift();
         // console.log(file,index,length)
         if(!file) break;
-        let files = [file,pdfList.shift(),pdfList.shift(),pdfList.shift(),pdfList.shift(),pdfList.shift()
-            // ,pdfList.shift(),pdfList.shift(),pdfList.shift()
+        let files = [file,pdfList.shift(),pdfList.shift(),pdfList.shift()
+            ,pdfList.shift()
+            ,pdfList.shift()
+            ,pdfList.shift(),pdfList.shift(),pdfList.shift()
+            ,pdfList.shift(),pdfList.shift(),pdfList.shift()
             // ,pdfList.shift(),pdfList.shift(),pdfList.shift(),pdfList.shift()
         ]; // 每次合并四个
         files=files?.filter(item=>item);
@@ -292,9 +297,11 @@ export async function mergePdfListReduce(pdfList,convertOpts){
                 }
                 resolve(onefile);
             }else{ // 多文件合并
+                convertOpts = {}
                 convertOpts.files = files;
                 // console.log("多文件合并",convertOpts)
-                    let mergeBuffer = await LibreOffice.convert(convertOpts);
+                let mergeBuffer = await PDFEngines.merge(convertOpts)
+                    // let mergeBuffer = await LibreOffice.convert(convertOpts);
                     resolve({data:mergeBuffer,ext:"pdf"})
             }
         }))