Browse Source

适配自定义的LibreOffice路径和convert路径

SSDesk-hacked
fellow99 3 years ago
parent
commit
919fad4ac4
4 changed files with 38 additions and 7 deletions
  1. 13
    0
      converter-debug.js
  2. 13
    0
      converter-win32.js
  3. 4
    0
      converter.js
  4. 8
    7
      index.js

+ 13
- 0
converter-debug.js View File

@@ -0,0 +1,13 @@
const path = require('path');
const index = require('./index');

let libreofficeBin = path.resolve(__dirname, '../../../../etc/LibreOffice/App/libreoffice/program/soffice.exe');
let convertBin = path.resolve(__dirname, '../../../../etc/ImageMagick-convert/convert.exe');

exports.convert = (args)=>{
args = args || {};
args.libreofficeBin = args.libreofficeBin || libreofficeBin;
args.convertBin = args.convertBin || convertBin;
console.log(args)
return index.convert(args);
}

+ 13
- 0
converter-win32.js View File

@@ -0,0 +1,13 @@
const path = require('path');
const index = require('./index');

let libreofficeBin = path.resolve(__dirname, '../../third/LibreOffice/App/libreoffice/program/soffice.exe');
let convertBin = path.resolve(__dirname, '../../third/ImageMagick-convert/convert.exe');

exports.convert = (args)=>{
args = args || {};
args.libreofficeBin = args.libreofficeBin || libreofficeBin;
args.convertBin = args.convertBin || convertBin;
console.log(args)
return index.convert(args);
}

+ 4
- 0
converter.js View File

@@ -0,0 +1,4 @@
const path = require('path');
const index = require('./index');

exports.convert = index.convert;

+ 8
- 7
index.js View File

@@ -45,11 +45,11 @@ function run(libreOfficeBin, cmd, convert) {
const {_args} = parseCommand(libreOfficeBin, cmd, convert);
let _cmd = libreOfficeBin;

if (convert === "img") {
_cmd = "convert";
} else if (process.platform === "win32" && convert === "pdf") {
_cmd = process.env.ComSpec;
}
// if (convert === "img") {
// _cmd = "convert";
// } else if (process.platform === "win32" && convert === "pdf") {
// _cmd = process.env.ComSpec;
// }

const proc = spawn(_cmd, _args);

@@ -71,6 +71,7 @@ function run(libreOfficeBin, cmd, convert) {
exports.convert = async ({
libreofficeBin,
libreofficeBins,
convertBin,
sourceFile,
outputDir,
img,
@@ -85,7 +86,7 @@ exports.convert = async ({
const outputImg = outputFile.replace(/\.pdf$/, `-%d.${imgExt || "png"}`);

const ext = path.extname(sourceFile.toLowerCase());
const extensions = [".pdf", ".pptx", ".ppt", ".odp", ".key"];
const extensions = [".pdf", ".pptx", ".ppt", ".docx", ".doc", ".xlsx", ".xls", ".odp", ".key"];

const pdf = [
"--headless",
@@ -147,7 +148,7 @@ exports.convert = async ({
if (!img) {
return pdfRes;
} else {
return run(libreofficeBin, image, "img").then((imageRes) => {
return run(convertBin, image, "img").then((imageRes) => {
if (imageRes !== "Error") {
return imageRes;
} else {

Loading…
Cancel
Save