|
@@ -322,20 +322,29 @@ export async function mergePdfListReduce(pdfList,convertOpts){
|
|
plist.push(new Promise(async resolve=>{
|
|
plist.push(new Promise(async resolve=>{
|
|
if(files?.length==1){ // 单文件直接加载 自动获取后缀
|
|
if(files?.length==1){ // 单文件直接加载 自动获取后缀
|
|
let onefile = files[0]
|
|
let onefile = files[0]
|
|
- if(!onefile?.ext){
|
|
|
|
- let extname = path.extname(files[0]).slice(1)?.toLocaleLowerCase();
|
|
|
|
- onefile = {data:fs.readFileSync(onefile),ext:extname}
|
|
|
|
- }
|
|
|
|
|
|
+ // if(!onefile?.ext){
|
|
|
|
+ // let extname = path.extname(files[0]).slice(1)?.toLocaleLowerCase();
|
|
|
|
+ // onefile = {data:fs.readFileSync(onefile),ext:extname}
|
|
|
|
+ // }
|
|
resolve(onefile);
|
|
resolve(onefile);
|
|
}else{ // 多文件合并
|
|
}else{ // 多文件合并
|
|
convertOpts = {}
|
|
convertOpts = {}
|
|
convertOpts.files = files;
|
|
convertOpts.files = files;
|
|
// console.log("多文件合并",convertOpts)
|
|
// console.log("多文件合并",convertOpts)
|
|
- let mergeBuffer = await PDFEngines.merge(convertOpts)
|
|
|
|
- // let mergeBuffer = await LibreOffice.convert(convertOpts);
|
|
|
|
|
|
+ // pdfEngine合并
|
|
|
|
+ if(false){
|
|
|
|
+ let mergeBuffer = await PDFEngines.merge(convertOpts)
|
|
let mergeFilePath = files[0]+".merge.pdf"
|
|
let mergeFilePath = files[0]+".merge.pdf"
|
|
fs.writeFileSync(mergeFilePath,mergeBuffer)
|
|
fs.writeFileSync(mergeFilePath,mergeBuffer)
|
|
resolve(mergeFilePath)
|
|
resolve(mergeFilePath)
|
|
|
|
+ }
|
|
|
|
+ // pdfunite合并
|
|
|
|
+ if(true){
|
|
|
|
+ let mergeFilePath = files[0]+".merge.pdf"
|
|
|
|
+ pdfUnite(files,mergeFilePath)
|
|
|
|
+ resolve(mergeFilePath)
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}))
|
|
}))
|
|
}
|
|
}
|
|
@@ -351,6 +360,18 @@ export async function mergePdfListReduce(pdfList,convertOpts){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function pdfUnite(pdfList,outputPath){
|
|
|
|
+ let params = ["pdfunite",...pdfList,outputPath].join(" ")
|
|
|
|
+ try{
|
|
|
|
+ shell.exec(params)
|
|
|
|
+ }catch(err){}
|
|
|
|
+ if(fs.existsSync(outputPath)){
|
|
|
|
+ return outputPath
|
|
|
|
+ }else{
|
|
|
|
+ throw "error: pdfunit merge error"
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
export function renderDocx(inputDocxPath, outputDocxName, data,options){
|
|
export function renderDocx(inputDocxPath, outputDocxName, data,options){
|
|
|
|
|
|
let imageOptions = {
|
|
let imageOptions = {
|