Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ function wkhtmltopdf(input, options, callback) {
})
} else {
var isUrl = /^(https?|file):\/\//.test(input);
if (input) {
if (input && !options.readArgsFromStdin) {
args.push(isUrl ? quote(input) : '-'); // stdin if HTML given directly
}
}

// Output
args.push(output ? quote(output) : '-'); // stdout if no output file
if (!options.readArgsFromStdin) {
args.push(output ? quote(output) : '-'); // stdout if no output file
}

// show the command that is being run if debug opion is passed
if (options.debug && !(options instanceof Function)) {
Expand Down
16 changes: 16 additions & 0 deletions spec/wkhtmltopdf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ describe('wkhtmltopdf', function() {
});
});

describe('when readArgsFromStdin is set', function() {
it('should treat input as arguments', function(done) {
var args = [
'page',
fixtureFileUri('validFile.html'),
'-'
];
var output = Fs.createWriteStream(resultPath('readArgsFromStdinSpec.pdf'));
Wkhtmltopdf(args.join(' '), { readArgsFromStdin: true }).pipe(output);
output.on('finish', function() {
checkResults('readArgsFromStdinSpec.pdf', 'validFile.pdf');
done();
});
});
});

describe('when callback is used', function() {
it('should return a readable stream', function(done) {
Wkhtmltopdf(Fs.createReadStream(fixturePath('validFile.html')), function(err, stream) {
Expand Down