traviscooper / node-wkhtml

Convert html to PDF or PNG format using the webkit rendering engine, and qt.
104 stars 17 forks source link

Example using CLI Options #11

Open bensheldon opened 12 years ago

bensheldon commented 12 years ago

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)

mhemesath commented 12 years ago

Is this a typo:

{"page-size: "Letter"}

I'm assuming you meant

{ "page-size": "Letter" }

If that isn't the issue, I can take a look tonight. Otherwise, feel free to take a look at the code and make a pull request, it's a fairly simple wrapper. A few months ago I did a major rewrite of this module, and hadn't gotten around to validating the options worked correctly.

Thanks!

bensheldon commented 12 years ago

Whoops, that is just a type. I also tried a few other commands ({ orientation: "Landscape"} for example) and it didn't work either. I also wasn't sure how wkhtmltopdf expects arguments, so I tried {"page-size Letter": true} (so the argument stringifier outputs --page-size Letter rather than --page-size=Letter) and that didn't work either. I am kind've stabbing away in the dark (wkhtmltopdf's documentation wasn't so helpful either), but will keep trying unless you have an example you know that works.

mhemesath commented 12 years ago

No, unfortunately since the rewrite I don't. I'd suggest getting the wkhtmltopdf command working directly in a shell then verifying that spawn is using that same command.

If you don't figure it out I'll take a look tonight.

mhemesath commented 12 years ago

Ok, I started working on this last night. I'm going to clean up the options a bit and make the whole thing easier to use. Basically I'm thinking of the following:

pdf().input('http://www.google.com')
    .option('page-size', 'Letter')
    .option('page-width', 1000)
    .spawn();

I'm hoping to finish this up tonight and push a new module out to npm.