Comments (8)
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.
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.
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.
Cool! I'll fork it and play with and see if I can get it working...
from node-wkhtml.
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.
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.
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.
I pushed a major refactor and provided examples on piping the pdf directly to the response.
from node-wkhtml.
Related Issues (12)
- pdf generation via html string doesn't work HOT 5
- Example using CLI Options HOT 4
- How to generate png using node-wkhtml. HOT 2
- Take on node-wkhtml for legacy maintenance HOT 3
- Error: write EPIPE HOT 1
- Wrong command for spawn('png') HOT 1
- Specify a License
- [feature demand]"add" function works on html type HOT 1
- object.file but not object.filename in util.js HOT 1
- Generating image through URL then capturing stdout through convert() not working HOT 3
- Return the generated pdf as buffer HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-wkhtml.