| @@ -1,6 +1,6 @@ | |||
| # convert-pdf-img | |||
| Converts `.ppt,` `.pptx`, `.odp` and `.key` file to `pdf or/and image(png, jpg, jpeg, etc)` | |||
| Converts `.ppt` `.pptx` `.odp` and `.key` file to `pdf or/and image(png, jpg, jpeg and etc..)` | |||
| ## Dependencies | |||
| @@ -15,8 +15,8 @@ const document = require("./convert"); | |||
| const options = { | |||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", // Optional | |||
| sourceFile: "C:\\convert-pdf-img\\sample.pptx", // `.ppt,` `.pptx`, `.odp`, `.key` and `.pdf` | |||
| outputDir: "C:\\convert-pdf-img\\sample", | |||
| sourceFile: "C:\\convert-pdf-img\\sample.pptx", // .ppt, .pptx, .odp, .key and .pdf | |||
| outputDir: "C:\\convert-pdf-img\\output", | |||
| img: false, | |||
| imgExt: "jpg", // Default value png | |||
| reSize: 800, // Default Resize is 1200 | |||
| @@ -33,7 +33,9 @@ function libreOffice(libreofficeBin, callback) { | |||
| break; | |||
| default: | |||
| return callback( | |||
| new Error(`Operating system not yet supported: ${process.platform}`) | |||
| new Error( | |||
| `Operating system not yet supported to convert process: ${process.platform}` | |||
| ) | |||
| ); | |||
| } | |||
| @@ -97,6 +99,14 @@ function run(librePath, cmd, convert) { | |||
| }); | |||
| } | |||
| function pathExist(outputPath, callback) { | |||
| fs.access(outputPath, fs.constants.F_OK, (err) => { | |||
| if (err) { | |||
| return callback(new Error("Source file does not exist.")); | |||
| } | |||
| }); | |||
| } | |||
| exports.convert = ( | |||
| { libreofficeBin, sourceFile, outputDir, img, imgExt, reSize, density }, | |||
| callback | |||
| @@ -1,10 +1,10 @@ | |||
| { | |||
| "name": "slide-pdf-image", | |||
| "name": "document-convert", | |||
| "version": "1.0.0", | |||
| "description": "The package export ppt, pptx, odp and key to pdf and/or img[png, jpg, jpeg].", | |||
| "description": "The package export ppt, pptx, odp and key files to pdf and/or img(png, jpg, jpeg and etc...).", | |||
| "main": "index.js", | |||
| "scripts": { | |||
| "test": "echo \"Error: no test specified\" && exit 1" | |||
| "test": "mocha --reporter spec" | |||
| }, | |||
| "keywords": [ | |||
| "ppt to pdf and/or image", | |||
| @@ -12,18 +12,25 @@ | |||
| "keynote to pdf and/or image", | |||
| "odp to pdf and/or image", | |||
| "ppt convert to pdf", | |||
| "pdf to image", | |||
| "imagemagick", | |||
| "ghostscript" | |||
| "ghostscript", | |||
| "libreoffice" | |||
| ], | |||
| "author": "Kalimuthu Selvaraj", | |||
| "author": { | |||
| "name": "Kalimuthu Selvaraj", | |||
| "email": "kaalee6@gmail.com", | |||
| "url": "https://github.com/kalimuthu-selvaraj" | |||
| }, | |||
| "license": "ISC", | |||
| "dependencies": { | |||
| "async": "^3.2.0", | |||
| "office-to-pdf": "^4.0.0", | |||
| "pptx2pdf": "^1.0.10" | |||
| "async": "^3.2.0" | |||
| }, | |||
| "devDependencies": { | |||
| "chai": "^4.2.0", | |||
| "mocha": "^7.2.0" | |||
| }, | |||
| "engines": { | |||
| "node": ">=6" | |||
| } | |||
| } | |||
| @@ -2,8 +2,8 @@ const document = require("./convert"); | |||
| const options = { | |||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", | |||
| sourceFile: "C:\\convert-pdf-img\\metro_powerpoint.pptx", | |||
| outputDir: "abc", | |||
| sourceFile: "/home/convert/source/metro_powerpoint.pptx", | |||
| outputDir: "C:\\convert-pdf-img\\files\\", | |||
| img: true, | |||
| imgExt: "jpg", | |||
| reSize: 800, | |||
| @@ -13,21 +13,21 @@ describe("Convert files to pdf or/and image", function () { | |||
| density: 120, | |||
| }; | |||
| it("should return source file not exist", function () { | |||
| options.sourceFile = "C:\\convert-pdf-img\\metro_powerpoint.pptex"; | |||
| options.sourceFile = "C:\\convert-pdf-img\\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\\sample.txt"; | |||
| options.sourceFile = "C:\\convert-pdf-img\\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\\metro_powerpoint.pptx"; | |||
| 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."); | |||