0

I am trying to convert some html to a png using wkhtmltoimage via nodejs and the node-wkhtml package.

I am able to a pdf without and problem. However, when I try to make a png instead of a pdf, the png is just band of colors instead of what it should be. This reported bug on the project site is very similar to what I am seeing (except I am trying to write a png and the bug is reported for a png).

It seems that the problem should only be present when using stdout on windows. Is there a work around? Is there any way to save the file without using stdout?

var fs = require('fs');
var wkhtml = require('node-wkhtml'),
    createWriteStream = require('fs').createWriteStream;

var MyClass = module.exports = function()
    {
    var png = wkhtml.spawn('png');
    png.stdout.pipe(createWriteStream('node_doc.png'));
    png.stdin.end('<h1>Hello World</h1>');
    }

new MyClass();
Chad DeShon
  • 4,732
  • 6
  • 28
  • 29

1 Answers1

1

I ended up abandoning streams and node-wkhtml in general. I am now just writing a temp html file and calling wkhtmltoimage using spawn. Not ideal to have to make the temp file, but it is working.

child_process.spawn( 'wkhtmltoimage', [ 'temp.html', 'output.png' ] );
Chad DeShon
  • 4,732
  • 6
  • 28
  • 29