Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-source input #135

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 20 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,25 @@ function wkhtmltopdf(input, options, callback) {
}
});

var isUrl = /^(https?|file):\/\//.test(input);

if (input) {
args.push(isUrl ? quote(input) : '-'); // stdin if HTML given directly
// Input
var isArray = Array.isArray(input);
if (isArray) {
input.forEach(function(element) {
var isUrl = /^(https?|file):\/\//.test(element);
if (element && isUrl) {
args.push(quote(element));
} else {
console.log('[node-wkhtmltopdf] [warn] Multi PDF only supported for URL files (http[s]:// or file://)')
}
})
} else {
var isUrl = /^(https?|file):\/\//.test(input);
if (input) {
args.push(isUrl ? quote(input) : '-'); // stdin if HTML given directly
}
}

// Output
args.push(output ? quote(output) : '-'); // stdout if no output file

// show the command that is being run if debug opion is passed
Expand Down Expand Up @@ -191,9 +204,9 @@ function wkhtmltopdf(input, options, callback) {
}

// write input to stdin if it isn't a url
if (!isUrl) {
// Handle errors on the input stream (happens when command cannot run)
child.stdin.on('error', handleError);
if (!isUrl && !isArray) {
// Handle errors on the input stream (happens when command cannot run)
child.stdin.on('error', handleError);
if (isStream(input)) {
input.pipe(child.stdin);
} else {
Expand Down