htmlpdfwkhtmltopdf

Is there any wkhtmltopdf option to convert html text rather than file?


I recently stumbled on wkhtmltopdf and have found it to be an excellent tool for on-the-fly conversion from html to pdf in the browser.

A typical usage (in Windows) would go:

wkhtmltopdf.exe --some-option "<div>Some html <b>formatted</b> text</div>" www.host.com/page_to_print.html file.pdf

My question is: Is there an option to use <html><head></head><body><h1>This is a header</h1></body></html> in place of www.host.com/page_to_print.html?

Thanks for any help.


Solution

  • You can pipe content into wkhtmltopdf using the command line. For Windows, try this:

    echo "<h3>blep</h3>" | wkhtmltopdf.exe - test.pdf
    

    This reads like "echo <h3>blep</h3>, output it's stdout (standard out stream) to wkhtmltopdf stdin (standard in stream)".

    The dash - in the wkhtmltopdf command means that it takes it's input from stdin and not a file.

    You could also echo HTML into a file, feed that file to wkhtmltopdf and delete that file inside a script.