| # convert-pdf-img | # 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 | ## Dependencies | ||||
| const options = { | const options = { | ||||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", // Optional | 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, | img: false, | ||||
| imgExt: "jpg", // Default value png | imgExt: "jpg", // Default value png | ||||
| reSize: 800, // Default Resize is 1200 | reSize: 800, // Default Resize is 1200 |
| break; | break; | ||||
| default: | default: | ||||
| return callback( | return callback( | ||||
| new Error(`Operating system not yet supported: ${process.platform}`) | |||||
| new Error( | |||||
| `Operating system not yet supported to convert process: ${process.platform}` | |||||
| ) | |||||
| ); | ); | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| 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 = ( | exports.convert = ( | ||||
| { libreofficeBin, sourceFile, outputDir, img, imgExt, reSize, density }, | { libreofficeBin, sourceFile, outputDir, img, imgExt, reSize, density }, | ||||
| callback | callback |
| { | { | ||||
| "name": "slide-pdf-image", | |||||
| "name": "document-convert", | |||||
| "version": "1.0.0", | "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", | "main": "index.js", | ||||
| "scripts": { | "scripts": { | ||||
| "test": "echo \"Error: no test specified\" && exit 1" | |||||
| "test": "mocha --reporter spec" | |||||
| }, | }, | ||||
| "keywords": [ | "keywords": [ | ||||
| "ppt to pdf and/or image", | "ppt to pdf and/or image", | ||||
| "keynote to pdf and/or image", | "keynote to pdf and/or image", | ||||
| "odp to pdf and/or image", | "odp to pdf and/or image", | ||||
| "ppt convert to pdf", | "ppt convert to pdf", | ||||
| "pdf to image", | |||||
| "imagemagick", | "imagemagick", | ||||
| "ghostscript" | |||||
| "ghostscript", | |||||
| "libreoffice" | |||||
| ], | ], | ||||
| "author": "Kalimuthu Selvaraj", | |||||
| "author": { | |||||
| "name": "Kalimuthu Selvaraj", | |||||
| "email": "kaalee6@gmail.com", | |||||
| "url": "https://github.com/kalimuthu-selvaraj" | |||||
| }, | |||||
| "license": "ISC", | "license": "ISC", | ||||
| "dependencies": { | "dependencies": { | ||||
| "async": "^3.2.0", | |||||
| "office-to-pdf": "^4.0.0", | |||||
| "pptx2pdf": "^1.0.10" | |||||
| "async": "^3.2.0" | |||||
| }, | }, | ||||
| "devDependencies": { | "devDependencies": { | ||||
| "chai": "^4.2.0", | "chai": "^4.2.0", | ||||
| "mocha": "^7.2.0" | "mocha": "^7.2.0" | ||||
| }, | |||||
| "engines": { | |||||
| "node": ">=6" | |||||
| } | } | ||||
| } | } |
| const options = { | const options = { | ||||
| libreofficeBin: "C:\\Program Files\\LibreOffice\\program\\soffice.exe", | 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, | img: true, | ||||
| imgExt: "jpg", | imgExt: "jpg", | ||||
| reSize: 800, | reSize: 800, |
| density: 120, | density: 120, | ||||
| }; | }; | ||||
| it("should return source file not exist", function () { | 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) { | var result = doc.convert(options, function (err) { | ||||
| expect(err.message).to.equal("Source file does not exist."); | expect(err.message).to.equal("Source file does not exist."); | ||||
| }); | }); | ||||
| }); | }); | ||||
| it("should return invalid extesion", function () { | 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) { | var result = doc.convert(options, function (err) { | ||||
| expect(err.message).to.equal("Invalid extension."); | expect(err.message).to.equal("Invalid extension."); | ||||
| }); | }); | ||||
| }); | }); | ||||
| it("should return error on image conversion process", function () { | 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"; | options.outputDir = "abc"; | ||||
| var result = doc.convert(options, function (err) { | var result = doc.convert(options, function (err) { | ||||
| expect(err.message).to.equal("Error on image conversion process."); | expect(err.message).to.equal("Error on image conversion process."); |