Unable to get PDF with images from Prawn PDF in a Node.js webapp -


am using prawn pdf in node.js webapp generate pdf on fly , send user. works fine long there no images in pdf doc. moment include image (png or jpeg) in pdf, spawned node child process never gets 'exit' message.

the same ruby script outputs pdf images expected when run in shell. somehow image data seems messed when sent on stdout! have escape it?

thanks, mano

var spawn = require('child_process').spawn; var child = spawn('ruby', ['print_scripts/print.rb', doc_id]); var pdf = '';  child.stdout.on('data', function(data){     if(data.tostring() != 'error'){     pdf += data;     } }); child.on('exit', function(code){     res.setheader('content-type', 'application/pdf');     if(code == 0){     res.send(pdf);     } }); 

in simple test did, exit called before data called. that's related notice: "note child process stdio streams might still open." (which mean there's still data left in internal buffers needs read).

when you're not using images, output might small enough fit in single buffer problem doesn't appear. instead of exit should catch close event instead.

there's issue of implicit conversion string in code (pdf += data), cause problems well.

i think work:

var chunks = [];  child.stdout.on('data', function(data) {   // insert error check here...   chunks.push(data); }); child.on('close', function() {   var pdf = buffer.concat(chunks);   res.send(pdf); }); 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -