|
|
|
|
|
|
|
|
_args.push(librePath); |
|
|
_args.push(librePath); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_args = _args.concat(cmd.split(" ")); |
|
|
|
|
|
|
|
|
_args = _args.concat(cmd); |
|
|
|
|
|
|
|
|
return { _args }; |
|
|
return { _args }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
_cmd = librePath; |
|
|
_cmd = librePath; |
|
|
} |
|
|
} |
|
|
console.log(librePath); |
|
|
|
|
|
console.log(_cmd); |
|
|
|
|
|
console.log(_args); |
|
|
|
|
|
|
|
|
|
|
|
const proc = spawn(_cmd, _args); |
|
|
const proc = spawn(_cmd, _args); |
|
|
|
|
|
|
|
|
proc |
|
|
|
|
|
.on("error", function (err) { |
|
|
|
|
|
reject(err); |
|
|
|
|
|
}) |
|
|
|
|
|
.on("close", (code) => { |
|
|
|
|
|
const status = code === 0 ? "Success" : "Error"; |
|
|
|
|
|
resolve(status); |
|
|
|
|
|
}) |
|
|
|
|
|
.stdout.on("data", (data) => { |
|
|
|
|
|
// console.log(++i, data); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
proc.stdout.on("data", (data) => { |
|
|
|
|
|
// console.log("stdout", data.toString()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
proc.stderr.on("error", function (err) { |
|
|
|
|
|
reject(err); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
proc.on("close", (code) => { |
|
|
|
|
|
const status = code === 0 ? "Success" : "Error"; |
|
|
|
|
|
resolve(status); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseFileName = path.basename(sourceFile); |
|
|
const baseFileName = path.basename(sourceFile); |
|
|
const outputFile = baseFileName.replace(/\.[^.]+$/, ".pdf"); |
|
|
const outputFile = baseFileName.replace(/\.[^.]+$/, ".pdf"); |
|
|
|
|
|
|
|
|
const outputPath = `${outputDir}${outputFile}`; |
|
|
|
|
|
const outputImg = outputFile.replace(/\.pdf$/, `-%d.${imgExt}`); |
|
|
const outputImg = outputFile.replace(/\.pdf$/, `-%d.${imgExt}`); |
|
|
|
|
|
|
|
|
const ext = path.extname(sourceFile.toLowerCase()); |
|
|
const ext = path.extname(sourceFile.toLowerCase()); |
|
|
const extensions = [".pdf", ".pptx", ".ppt", ".odp", ".key"]; |
|
|
const extensions = [".pdf", ".pptx", ".ppt", ".odp", ".key"]; |
|
|
|
|
|
|
|
|
const pdf = `--invisible --convert-to pdf --outdir ${outputDir} ${sourceFile}`; |
|
|
|
|
|
const image = `-verbose -resize ${reSize || 1200} -density ${ |
|
|
|
|
|
density || 120 |
|
|
|
|
|
} ${outputPath} ${outputDir}${outputImg}`; |
|
|
|
|
|
|
|
|
|
|
|
const pdf2Img = `-verbose -resize ${reSize || 1200} -density ${ |
|
|
|
|
|
density || 120 |
|
|
|
|
|
} ${sourceFile} ${outputDir}${outputImg}`; |
|
|
|
|
|
|
|
|
const pdf = [ |
|
|
|
|
|
"--headless", |
|
|
|
|
|
"--convert-to", |
|
|
|
|
|
"pdf", |
|
|
|
|
|
"--outdir", |
|
|
|
|
|
outputDir, |
|
|
|
|
|
sourceFile, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const image = [ |
|
|
|
|
|
"-verbose", |
|
|
|
|
|
"-resize", |
|
|
|
|
|
reSize || 1200, |
|
|
|
|
|
"-density", |
|
|
|
|
|
density || 120, |
|
|
|
|
|
`${outputDir}${outputFile}`, |
|
|
|
|
|
`${outputDir}${outputImg}`, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const pdf2Img = [ |
|
|
|
|
|
"-verbose", |
|
|
|
|
|
"-resize", |
|
|
|
|
|
reSize || 1200, |
|
|
|
|
|
"-density", |
|
|
|
|
|
density || 120, |
|
|
|
|
|
sourceFile, |
|
|
|
|
|
`${outputDir}${outputImg}`, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
if (ext === ".pdf") |
|
|
if (ext === ".pdf") |
|
|
return run(res, pdf2Img, "img").then((res) => callback(null, res)); |
|
|
return run(res, pdf2Img, "img").then((res) => callback(null, res)); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
if (extensions.includes(ext)) { |
|
|
if (extensions.includes(ext)) { |
|
|
run(res, pdf, "pdf").then((pdfRes) => { |
|
|
run(res, pdf, "pdf").then((pdfRes) => { |
|
|
if (pdf) { |
|
|
|
|
|
|
|
|
if (pdfRes !== "Error") { |
|
|
if (!img) { |
|
|
if (!img) { |
|
|
return callback(null, pdfRes); |
|
|
return callback(null, pdfRes); |
|
|
} else { |
|
|
} else { |
|
|
run(res, image, "img").then((imageRes) => { |
|
|
run(res, image, "img").then((imageRes) => { |
|
|
return callback(null, imageRes); |
|
|
|
|
|
|
|
|
if (imageRes !== "Error") { |
|
|
|
|
|
return callback(null, imageRes); |
|
|
|
|
|
} else { |
|
|
|
|
|
return callback( |
|
|
|
|
|
new Error("Error on image conversion process.") |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return callback(new Error("Error on pdf conversion process.")); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |