Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Created December 4, 2014 01:06
Show Gist options
  • Save IgorDePaula/6ce642dcc9f1a6064b70 to your computer and use it in GitHub Desktop.
Save IgorDePaula/6ce642dcc9f1a6064b70 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* unoconv -f pdf -o ' + path1 + '.pdf ' + path1
*/
var kue = require('kue')
, jobs = kue.createQueue();
var exec = require('child_process').exec;
kue.app.listen(3000);
var job = jobs.create('create slide', {
file: 'lib/teste.ppt',
title: 'create slide'
}).priority('high').save(function (err) {
if (!err)
console.log(job.id);
});
job.on('complete', function (result) {
console.log("Job completed with data ", result);
}).on('failed', function () {
console.log("Job failed");
}).on('progress', function (progress) {
process.stdout.write('\r job #' + job.id + ' ' + progress + '% complete');
});
jobs.process('create slide', function (job, done) {
ppt2pdf(job.data.file, done);
console.log('Job', job.id, 'is process');
//done && done();
});
jobs.on('job enqueue', function (id, type) {
console.log('job %s got queued', id);
});
jobs.on('job complete', function (id, result) {
kue.Job.get(id, function (err, job) {
if (err)
return;
console.log(' completed job #%d', job.id);
});
});
function ppt2pdf(file, done) {
exec("unoconv -f pdf -o " + file + ".pdf " + file, function (err, done) {
if (err)
throw err;
//console.log('Job', job.id, 'is ppt2pdf');
job.log('Joblog' + job.id + 'is ppt2pdf');
exec("convert -resize 1200 -density 200 " + file + '.pdf ' + file + '.jpg', function (err, done) {
if (err)
throw err;
//console.log('Job', job.id, 'is ppt2pdf');
job.log('Joblog' + job.id + 'is ppt2pdf');
});
});
done && done(0);
}
function pdf2jpg(file, done) {
exec("convert -resize 1200 -density 200 " + file + ' ' + file + '.jpg', function (err, done) {
if (err)
throw err;
console.log('Job', job.id, 'is ppt2pdf');
job.log('Job' + job.id + 'is ppt2pdf');
done && done();
});
done && done(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment