| @@ -1,4 +1,3 @@ | |||
| node_modules | |||
| source | |||
| files | |||
| sample.js | |||
| files | |||
| @@ -9,20 +9,22 @@ Please install [libreoffice](https://www.libreoffice.org/), [imagemagick](https: | |||
| ## LibreOffice test | |||
| libreOfficePath --headless --convert-to pdf --outdir outputDir sourceFile(test.pdf), | |||
| libreOfficeInstallationPath --headless --convert-to pdf --outdir outputDir sourceFile(test.pdf), | |||
| ## LibreOffice Installation Path | |||
| Windows | |||
| ``` | |||
| C:\\Program Files\\LibreOffice\\program\\soffice.exe or | |||
| C:\\Program Files (x86)\\LibreOffice\\program\\soffice.exe or | |||
| C:\\Program Files\\LibreOffice\\program\\soffice.exe (or) | |||
| C:\\Program Files (x86)\\LibreOffice\\program\\soffice.exe (or) | |||
| C:\\Program Files (x86)\\LIBREO~1\\program\\soffice.exe | |||
| ``` | |||
| Ubuntu | |||
| ``` | |||
| /usr/bin/libreoffice or | |||
| /usr/bin/libreoffice (or) | |||
| /usr/bin/soffice | |||
| ``` | |||
| @@ -160,25 +160,31 @@ exports.convert = ( | |||
| return callback(new Error("Source file does not exist.")); | |||
| } else { | |||
| if (extensions.includes(ext)) { | |||
| run(res, pdf, "pdf").then((pdfRes) => { | |||
| if (pdfRes !== "Error") { | |||
| if (!img) { | |||
| return callback(null, pdfRes); | |||
| run(res, pdf, "pdf") | |||
| .then((pdfRes) => { | |||
| if (pdfRes !== "Error") { | |||
| if (!img) { | |||
| return callback(null, pdfRes); | |||
| } else { | |||
| run(res, image, "img") | |||
| .then((imageRes) => { | |||
| if (imageRes !== "Error") { | |||
| return callback(null, imageRes); | |||
| } else { | |||
| return callback( | |||
| new Error("Error on image conversion process.") | |||
| ); | |||
| } | |||
| }) | |||
| .catch((e) => callback(e)); | |||
| } | |||
| } else { | |||
| run(res, image, "img").then((imageRes) => { | |||
| if (imageRes !== "Error") { | |||
| return callback(null, imageRes); | |||
| } else { | |||
| return callback( | |||
| new Error("Error on image conversion process.") | |||
| ); | |||
| } | |||
| }); | |||
| return callback( | |||
| new Error("Error on pdf conversion process.") | |||
| ); | |||
| } | |||
| } else { | |||
| return callback(new Error("Error on pdf conversion process.")); | |||
| } | |||
| }); | |||
| }) | |||
| .catch((e) => callback(e)); | |||
| } else { | |||
| return callback(new Error("Invalid extension.")); | |||
| } | |||
| @@ -1,16 +0,0 @@ | |||
| const document = require("./convert"); | |||
| const options = { | |||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", | |||
| sourceFile: "/home/convert/source/metro_powerpoint.pptx", | |||
| outputDir: "C:\\convert-pdf-img\\files\\", | |||
| img: true, | |||
| imgExt: "jpg", | |||
| reSize: 800, | |||
| density: 120, | |||
| }; | |||
| document.convert(options, (err, res) => { | |||
| if (err) console.log(err.message); | |||
| console.log(res); | |||
| }); | |||
| @@ -4,33 +4,33 @@ var doc = require("../convert"); | |||
| describe("Convert files to pdf or/and image", function () { | |||
| let options = { | |||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", | |||
| sourceFile: "C:\\convert-pdf-img\\metro_powerpoint.pptx", | |||
| outputDir: "C:\\convert-pdf-img\\files\\", | |||
| sourceFile: "C:\\document-convert\\metro_powerpoint.pptx", | |||
| outputDir: "C:\\document-convert\\files\\", | |||
| img: true, | |||
| imgExt: "jpg", | |||
| reSize: 800, | |||
| density: 120, | |||
| }; | |||
| it("should return source file not exist", function () { | |||
| options.sourceFile = "C:\\convert-pdf-img\\source\\metro_powerpoint.pptex"; | |||
| options.sourceFile = "C:\\document-convert\\source\\metro_powerpoint.pptex"; | |||
| var result = doc.convert(options, function (err) { | |||
| expect(err.message).to.equal("Source file does not exist."); | |||
| }); | |||
| }); | |||
| it("should return invalid extesion", function () { | |||
| options.sourceFile = "C:\\convert-pdf-img\\source\\sample.txt"; | |||
| options.sourceFile = "C:\\document-convert\\source\\sample.txt"; | |||
| var result = doc.convert(options, function (err) { | |||
| expect(err.message).to.equal("Invalid extension."); | |||
| }); | |||
| }); | |||
| it("should return error on image conversion process", function () { | |||
| options.sourceFile = "C:\\convert-pdf-img\\source\\metro_powerpoint.pptx"; | |||
| options.outputDir = "abc"; | |||
| var result = doc.convert(options, function (err) { | |||
| expect(err.message).to.equal("Error on image conversion process."); | |||
| it("should return success", function () { | |||
| options.sourceFile = "C:\\document-convert\\source\\metro_powerpoint.pptx"; | |||
| options.outputDir = "C:\\document-convert\\files\\"; | |||
| options.img = true; | |||
| var result = doc.convert(options, function (err, res) { | |||
| expect(res).to.equal("Success"); | |||
| }); | |||
| }); | |||
| }); | |||