Search code examples
node.jspdfsvgwkhtmltopdfnode-webkit

Wkhtmltopdf-node open and render a local file


I've walked through the examples, where the main method takes url or html directly:

// URL
wkhtmltopdf('http://google.com/', { pageSize: 'letter' })
.pipe(fs.createWriteStream('out.pdf'));

// HTML
wkhtmltopdf('<h1>Test</h1><p>Hello world</p>')
.pipe(res);

// output to a file directly
wkhtmltopdf('http://apple.com/', { output: 'out.pdf' });

But suppose I have an svg file locally, is there a way to call wkhtmltopdf with the file? Something like:

wkhtmltopdf({input: "path/to/file.svg"}, { output: "~/output.pdf" })

Solution

  • I suggest that you try it without using an SVG first to rule out that. Rather use a simple HTML file at first and when that works, try the SVG.

    It's very likely that you have to provide the protocol as well, so try something like this:

    wkhtmltopdf({input: "file://path/to/file.html"}, { output: "~/output.pdf" })