title: Convert pptx/ppt/docx/doc to Images
body: <p>I have searching for a way to convert pdf and ppt files to images. I have gone through a lot of websites and links. With the invent of NodeJS, I was hoping for something simple.</p>
  
  <p>I found this one: <a href="https://medium.com/@bgbhavesh/convert-pptx-ppt-docx-doc-to-images-4ec180d6d7fe#.atsop0j12" rel="nofollow noreferrer">convert pptx/ppt/docx/doc to images</a>. It promises a simpler solution to my problem. However, it is written in <strong>Meteor</strong>, and I think there might be more to it than meets the eye. I want a simple NodeJS way to do this, without the <strong>Meteor</strong> coating, as I have no previous knowledge of Metor.</p>
  
  <pre><code>meteorhacks:npm
  
  npm-container
  Meteor.startup(function () {
      var fs = Npm.require("fs");
      var path = Npm.require('path');
      var sys = Npm.require('sys');
      var exec = Npm.require('child_process').exec;
      var child;
  
      var dir = "/home/bhavesh";
  
      fs.watch(dir, {persistent: true}, function (event, fileName) {
          console.log("dfs");
          console.log("Event: " + event);
          console.log(fileName + "\n");
          var ext = path.extname(fileName);
          if ((ext.toString() == ".pptx" || ext.toString() == ".ppt" || ext.toString() == ".docx" || ext.toString() == ".doc") &amp;&amp; event == "change") {
              console.log("Powerpoint file");
              ppt_or_doc_to_pdf(dir,fileName);
          }
          if (ext.toString() == ".pdf" &amp;&amp; event == "change") {
              console.log("PDF file");
              pdf_to_ppm(dir,fileName);
          }
      });
      function pdf_to_ppm(dir, file) {
          var cmd = "cd " + dir + "; pdftoppm '" + file + "' slide";
          exec(cmd, function (error, stdout, stderr) {
              console.log('stdout: ' + stdout);
              console.log('stderr: ' + stderr);
              if (error !== null) {
                  console.log('exec error: ' + error);
              }
              ppm_to_jpg(dir);
          });
      }
  
      function ppt_or_doc_to_pdf(dir, file) {
          var fileName = file.substring(0, file.indexOf('.'));
          var cmd = "cd " + dir + "; unoconv -f pdf -o '" + fileName + ".pdf' '" + file + "'";
          exec(cmd, function (error, stdout, stderr) {
              console.log('stdout: ' + stdout);
              console.log('stderr: ' + stderr);
              if (error !== null) {
                  console.log('exec error: ' + error);
              }
              pdf_to_ppm(dir, fileName + '.pdf');
          });
      }
      function ppm_to_jpg(dir) {
          var cmd = "cd " + dir + "; mogrify -format jpg slide*.ppm";
          exec(cmd, function (error, stdout, stderr) {
              console.log('stdout: ' + stdout);
              console.log('stderr: ' + stderr);
              if (error !== null) {
                  console.log('exec error: ' + error);
              }
          });
      }
  });
  </code></pre>
  
  <p>Any help is appreciated...</p>
  
  <p>Thanks..</p>