Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating image through URL then capturing stdout through convert() not working #4

Closed
wallslide opened this issue Aug 5, 2011 · 3 comments

Comments

@wallslide
Copy link

As seen at this URL:

http://nodejs.org/docs/v0.4.9/api/child_processes.html#child_process.exec

There are options that can be passed in to the exec() command to increase the maximum buffer size, and to force binary encoding. I was getting this error:

"exec error: Error: maxBuffer exceeded."

with this command:

var Image = require("node-wkhtml").image();
var url = "http://jqueryui.com/";
new Image({ url: url }).convert(function(error, stdout){
  console.log("done");
});

To solve the error I edited the PDF.prototype.convert function found in "node-wkhtml/lib/image.js" to pass in a larger maxBuffer argument like this:

PDF.prototype.convert = function(callback) {
    exec(   util.buildCommand(this),
            {maxBuffer: 10*1024*1024},
            callback);
  }

Although this got rid of the error message, when I saved the resultant data into a database and tried to read it out, it was not parsable as an image file (although there was definitely the correct amount of data saved). To solve this final problem, I told exec to use binary encoding like this:

PDF.prototype.convert = function(callback) {
    exec(   util.buildCommand(this),
            {encoding: 'binary', maxBuffer: 10*1024*1024},
            callback);
  }

I think it makes sense that the encoding should always be set to binary in this case. As for the maxBuffer, I'm not sure if setting a large number has any effect beyond the potential for an extremely large image to hurt the system. It might be good if this was an argument a user could pass in through the convert() function since they should have a better idea of their size requirements.

@mhemesath
Copy link
Collaborator

Doh, youre right.. the buffer size does need to be configurable. Feel free to fork and create a pull request and illl merge those changes in.

@mhemesath
Copy link
Collaborator

I think the ideal solution is to create js bindings to wkhtml, but this will work for now.

@mhemesath
Copy link
Collaborator

I pushed a major refactor that uses spawn. You can listen to the data event directly on the stream or just pipe it to the response or filesystem. Check out the examples and let me know if you have any questions.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants