Skip to content

Commit 7fbb3f5

Browse files
authored
Merge pull request #136 from chdanielmueller/multi-source
Multi-source input
2 parents 68dcdbb + 3a237b7 commit 7fbb3f5

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,25 @@ function wkhtmltopdf(input, options, callback) {
8787
}
8888
});
8989

90-
var isUrl = /^(https?|file):\/\//.test(input);
91-
92-
if (input) {
93-
args.push(isUrl ? quote(input) : '-'); // stdin if HTML given directly
90+
// Input
91+
var isArray = Array.isArray(input);
92+
if (isArray) {
93+
input.forEach(function(element) {
94+
var isUrl = /^(https?|file):\/\//.test(element);
95+
if (isUrl) {
96+
args.push(quote(element));
97+
} else {
98+
console.log('[node-wkhtmltopdf] [warn] Multi PDF only supported for URL files (http[s]:// or file://)')
99+
}
100+
})
101+
} else {
102+
var isUrl = /^(https?|file):\/\//.test(input);
103+
if (input) {
104+
args.push(isUrl ? quote(input) : '-'); // stdin if HTML given directly
105+
}
94106
}
95107

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

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

193206
// write input to stdin if it isn't a url
194-
if (!isUrl) {
195-
// Handle errors on the input stream (happens when command cannot run)
196-
child.stdin.on('error', handleError);
207+
if (!isUrl && !isArray) {
208+
// Handle errors on the input stream (happens when command cannot run)
209+
child.stdin.on('error', handleError);
197210
if (isStream(input)) {
198211
input.pipe(child.stdin);
199212
} else {

0 commit comments

Comments
 (0)