Giter VIP home page Giter VIP logo

node-wkhtml's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-wkhtml's Issues

write pdf to http response

Hi. I'm attempting to write converted pdf from stdout to browser window with the following code. Should you be able to call
response.write(stdout) as I'm doing below, or could I be missing something? At the moment, this opens a blank pdf or occasionally the browser crashes when trying to load it


var url = require("url");

function pdfExport(response, request) {
var urlObj = url.parse(request.url, true);
var fileName = urlObj.query["filename"];
var gotoUrl = urlObj.query["url"];
console.log("Request handler 'pdfExport' was called.");

var PDF = require("node-wkhtml").pdf();
new PDF({url:'www.google.com'}).convert(function(err, stdout) {
    if (err) {
        console.log(err);
    } else {
        response.writeHead(200, {"Content-Type": "application/pdf"});
        response.write(stdout);
        console.log("PDF Complete!");
    }
});

}

exports.pdfExport = pdfExport;

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

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.

Error: write EPIPE

Hi, I'm trying to get the following sample code running

var http = require('http'),
  wkhtml = require('node-wkhtml');


http.createServer(function (request, response) {
  var pdf = wkhtml.spawn('pdf');
  pdf.stdout.pipe(response);
  pdf.stdin.end('<h1>Hello World</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>', 'utf-8');
}).listen(8000);

But I keep getting the following error:

Uncaught exception : Error: write EPIPE
    at errnoException (net.js:769:11)
    at Object.afterWrite (net.js:593:19)

I'm running it on Node v0.8.11.

Anyone else having troubles with piping to the response?

Tim.

[feature demand]"add" function works on html type

currently , PDF.add works only on url and file type, but it doesn't work on html type:

pdf = new PDF({
   html:"html content 1"
});
pdf.add({
   html:"html content 2"
});

it will generate:

echo 'html content 2' | wkhtmltopdf - -

then throw an error: Command failed: Loading pages (1/6).

I'm not very familiar on stdin :(

Return the generated pdf as buffer

It would be nice to get only the generated pdf back in a buffer. Currently you return the stdin which contains also the executed command which leads to unusable pdfs when storing the data direkt in a buffer.

Example using CLI Options

Could you provide an example that passes in some command-line options/arguments to wkhtml. Maybe I'm just dense, but I'm trying to set the page size (among other options) and this seems the obvious way to do so... but the result is nothing gets returned from wkhtml:

var pdf = wkhtml.spawn('pdf', undefined, {"page-size: "Letter"});
pdf.stdout.pipe(createWriteStream(__dirname + "/pdfFromString.pdf"));
pdf.stdin.end('<h1>Hello World</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>', 'utf-8');

(and yes, I'm using Streams)

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.