|
@@ -236,13 +236,24 @@ async function downloadUrl(url) {
|
|
|
// pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
// }
|
|
|
|
|
|
+ let mainPdfPath = docxPath
|
|
|
+ if(docxPath){
|
|
|
+ convertOpts.files = [files[0]];
|
|
|
+ console.log(convertOpts)
|
|
|
+ let mainPdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
+ mainPdfPath = path.dirname(docxPath)+"/109_"+path.basename(docxPath)+".pdf"
|
|
|
+ fs.writeFileSync(mainPdfPath,mainPdfBuffer)
|
|
|
+ }
|
|
|
+
|
|
|
// 方式2:先合并pdf,后合并docx
|
|
|
if(files?.length>4){
|
|
|
- let pdfList = files.slice(1);
|
|
|
+ let pdfList = [mainPdfPath,...files.slice(1)];
|
|
|
+ pdfList = pdfList.filter(item=>item)
|
|
|
let mergedFileList = await mergePdfListReduce(pdfList,convertOpts)
|
|
|
- convertOpts.files = [files[0],...mergedFileList]
|
|
|
+ pdfBuffer = mergedFileList[0]?.data;
|
|
|
+ // convertOpts.files = [files[0],...mergedFileList]
|
|
|
// console.log(convertOpts)
|
|
|
- pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
+ // pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
}else{
|
|
|
pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
}
|
|
@@ -280,10 +291,11 @@ export async function mergePdfListReduce(pdfList,convertOpts){
|
|
|
// 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()
|
|
|
- ,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()
|
|
|
+ // ,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);
|