call java command from cloud foundry node app

In my app, I want to convert PDF file to images, but it looks like there is not a module in node.js. So i want to use the java application do the work.

Can we call java command in the cloud foundry node app?

Thanks.

Hong

OK, so I have built an express app that does the job;

app.js looks like this;

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , util = require('util')
  , fs = require('fs')
  , exec = require('child_process').execFile
  , http = require('http');

process.env.MAGICK_TMPDIR = __dirname + '/tmp'

var app = express();

app.configure(function(){
  app.set('port', process.env.VCAP_APP_PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser({uploadDir:__dirname + "/uploads"}));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);

app.post('/convert', function(req, res) {

  var pdf_file = req.files.pdf.path;
  var uploadsPath = __dirname + "/uploads"

  var filename = pdf_file.split("/")[pdf_file.split('/').length - 1]
  var out =  __dirname + '/public/images/' + filename + '.png';

  exec('convert', [pdf_file, '-append', out], function(err, stdout, stderr) {  

    res.redirect('/images/' + filename + '.png');

  });

});

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

The index view looks like this (just a simple multipart form);

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1><%= title %></h1>
    <form action="/convert" method="post" enctype="multipart/form-data">
      <label>PDF File</label>
      <input type="file" name="pdf" />
      <input type="submit" />
    </form>
  </body>
</html>

This all works fine on my private instance of Cloud Foundry (VCAP) but not on CloudFoundry.com, I think this is due to permissions issues. I will chase this up with the engineering team and find out if it is possible to call ImageMagick with the correct permissions.

=========

UPDATE

I have fixed the problem for CloudFoundry.com, it appears to stop ImageMagick from using /tmp as a temp dir the env var MAGICK_TMPDIR has to be set, you can see this in the top of app.js file now.

Am also redirecting to the image now rather then reading it in, works like a charm! - http://pdf2png.cloudfoundry.com

====