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

Just a correction to the answer provided by Nenotlep. As Jigar noted (in a comment to Nenotlep's answer), Nenotlep's command results in quotation marks preceding and following the actual text. On my system (Windows 10) this command is the correct solution:

echo ^<h3^>magical ponies^</h3^> | "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" - test.pdf

The echo command needs no quotation marks - but, if you do not put the text between quotation marks, the < and > characters need to be escaped (by ^).

Another way to try out is writing the text into a temporary file, which - on Windows - might even be faster as some sources state:

echo ^<h3^>magical ponies^</h3^> > temp.txt
"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" - test.pdf < temp.txt

(This can also be written in one line: just put an & between the two commands.)


In addition to the answer provided by pp. If you prefer not to escape the < > characters, you can also do the following:

echo | set /p="<h3>Magical ponies</h3>" | wkhtmltopdf - test.pdf

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.