From 547a8407c0fe32eac412b618034f0e9234282b7c Mon Sep 17 00:00:00 2001 From: chdanielmueller Date: Thu, 16 Jan 2020 15:01:06 +0100 Subject: [PATCH 1/2] Multi source --- index.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 1ed9371..0c75d7b 100644 --- a/index.js +++ b/index.js @@ -85,8 +85,23 @@ function wkhtmltopdf(input, options, callback) { } }); - var isUrl = /^(https?|file):\/\//.test(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 (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); + 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 @@ -185,9 +200,7 @@ 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) { if (isStream(input)) { input.pipe(child.stdin); } else { From 101214eb80dd631c963f9d22b562bff7382e8e91 Mon Sep 17 00:00:00 2001 From: chdanielmueller Date: Tue, 11 May 2021 14:55:11 +0200 Subject: [PATCH 2/2] Add error handling --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 39b6cba..da7a125 100644 --- a/index.js +++ b/index.js @@ -205,6 +205,8 @@ function wkhtmltopdf(input, options, callback) { // write input to stdin if it isn't a url 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 {