UNPKG

pdf-transform

Version:
55 lines (51 loc) 1.55 kB
const PDFConverter = require("./pdfConverter.js"); const fs = require("fs"); const convert = (options) => { if (options && options.fileName && options.fileName.length > 0) { if (options.convertTo === "png" || options.convertTo === "html") { PDFConverter.convert(options); } else { console.error( "Error:: Enter either png or html format in 'convertTo' key in options." ); } } else { console.error("Error:: No file name passed in options or arguments."); } }; if (process.argv[2]) { if (process.argv[2].includes("--file-path")) { const filePath = process.argv[2].split("=")[1]; const stats = fs.statSync(filePath); if (stats.isFile()) { try { if (fs.existsSync(filePath)) { convert({ fileName: filePath, convertTo: "html", compress: false, }); } else { console.log("Error:: PDF File does not exists at specified path."); } } catch (err) { console.error(err); } } else if (stats.isDirectory()) { console.log( "Error:: Please mention PDF file name instead of a directory." ); } else { console.log("Error:: Argument mentioned is not a PDF file."); } } else { console.log("Error:: Please specify valid argument --file-path=''"); } } else { console.log( "Error:: Please pass a PDF --file-path='' or --url='' as an argument." ); } module.exports = { convert, };