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

后端 未结 5 853
栀梦
栀梦 2021-02-19 09:47

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) woul

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 10:17

    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 ^magical ponies^ | "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 ^magical ponies^ > 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.)

提交回复
热议问题