Giter VIP home page Giter VIP logo

Comments (8)

mhemesath avatar mhemesath commented on August 11, 2024

I'll take a look at this tonight. Sorry, this project has been a bit neglected. There are a number of improvements I need to make to it.

from node-wkhtml.

bencpeters avatar bencpeters commented on August 11, 2024

Did you ever discover anything wrt this issue? I'm playing with this plugin right now and having a similar problem when trying to serve up an image via http without saving it serverside first.

var http = require('http');
var Image = require("node-wkhtml").image();

http.createServer(function (request, response) {
    new Image({ url: "www.google.com" }).convert (function (err, stdout) {
      //var theImage = new Buffer (stdout, 'binary');
      response.writeHead(200, {'Content-Type' : 'image/png',
                               'Content-Length' : stdout.length
      });
      response.write (stdout, 'binary');
      response.end ();
      //write out an error, if there is one
      if (err)
        console.log (err);
    });
}).listen(8124);

So far doing a little digging I've confirmed that the command is being generated correctly (wkhtmltoimage www.google.com -), and when I pipe the output of that straight into a file (in the command line) it works fine. So there's some problem with how this function is handling that output...

I also tried the fix #4, but it didn't fix anything

from node-wkhtml.

mhemesath avatar mhemesath commented on August 11, 2024

Yeah, I'm using the wrong API. It needs to be switched to use spawn instead of exec. This will resolve the maxBuffer problems and will make it easier to pipe the output.

from node-wkhtml.

bencpeters avatar bencpeters commented on August 11, 2024

Cool! I'll fork it and play with and see if I can get it working...

from node-wkhtml.

mhemesath avatar mhemesath commented on August 11, 2024

Yeah, this whole project could be greatly simplified. I'm thinking of doing away with "convert" and "convertAs" and rather just making a convenience wrapper around spawn and returning the child process.

This will empower anyone using this module to do whatever they want with the streamed output (save as file, or pipe to response).

e.g.

img = Image({ url: "www.google.com" })

img.stdout.on('data', function (data) {
   console.log('stdout: ' + data);
});

img.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

img.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});

from node-wkhtml.

bencpeters avatar bencpeters commented on August 11, 2024

Played with it a bit more and got it working with spawn. I'll clean it up a bit and post it up for you to look at tonight sometime probably.

from node-wkhtml.

mhemesath avatar mhemesath commented on August 11, 2024

Cool, if you get that done I'll merge it in. Otherwise I'll probably go ahead and make the changes I outlined above. My end-goal for this is to make it easy to plug into Express 3, so that any view can effortlessly be returned as a PDF or Image instead of HTML. Using spawn and returning the child process should make that much easier.

from node-wkhtml.

mhemesath avatar mhemesath commented on August 11, 2024

I pushed a major refactor and provided examples on piping the pdf directly to the response.

from node-wkhtml.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.