|
@@ -124,7 +124,7 @@ module.exports.createZip = createZip
|
|
|
|
|
|
const download = require('download')
|
|
|
async function downloadUrl(url) {
|
|
|
- console.log(url)
|
|
|
+ // console.log(url)
|
|
|
if(url?.startsWith("/")) {return url};
|
|
|
let md5 = crypto.createHash('md5');
|
|
|
let extname = path.extname(url)?.toLocaleLowerCase();
|
|
@@ -200,7 +200,7 @@ async function downloadUrl(url) {
|
|
|
properties: {
|
|
|
// 设置页面属性,例如纸张大小和方向
|
|
|
pageSize: 'A4',
|
|
|
- orientation: 'portrait',
|
|
|
+ // orientation: 'portrait',
|
|
|
margin: {
|
|
|
top: 0,
|
|
|
right: 0,
|
|
@@ -237,8 +237,8 @@ async function downloadUrl(url) {
|
|
|
// 方式2:先合并pdf,后合并docx
|
|
|
if(files?.length>4){
|
|
|
let pdfList = files.slice(1);
|
|
|
- let mergedFile = await mergePdfListReduce(pdfList,convertOpts)
|
|
|
- convertOpts.files = [files[0],mergedFile]
|
|
|
+ let mergedFileList = await mergePdfListReduce(pdfList,convertOpts)
|
|
|
+ convertOpts.files = [files[0],...mergedFileList]
|
|
|
// console.log(convertOpts)
|
|
|
pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
}else{
|
|
@@ -269,7 +269,7 @@ const sizeOf = require("image-size");
|
|
|
* @returns
|
|
|
*/
|
|
|
export async function mergePdfListReduce(pdfList,convertOpts){
|
|
|
- // console.log("pdfList",pdfList)
|
|
|
+ console.log("pdfList",pdfList)
|
|
|
let mergeList = []
|
|
|
let plist = []
|
|
|
let length = pdfList.length
|
|
@@ -277,7 +277,10 @@ 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()]; // 每次合并三个
|
|
|
+ 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()
|
|
|
+ ]; // 每次合并四个
|
|
|
files=files?.filter(item=>item);
|
|
|
// console.log(files)
|
|
|
plist.push(new Promise(async resolve=>{
|
|
@@ -300,8 +303,8 @@ export async function mergePdfListReduce(pdfList,convertOpts){
|
|
|
mergeList = await Promise.all(plist);
|
|
|
}
|
|
|
// console.log("mergeList",mergeList)
|
|
|
- if(mergeList?.length==1){
|
|
|
- return mergeList[0];
|
|
|
+ if(mergeList?.length<=3){
|
|
|
+ return mergeList;
|
|
|
}else{
|
|
|
// console.log("mergePdfListReduce continue:",mergeList)
|
|
|
return await mergePdfListReduce(mergeList,convertOpts)
|