WKHTMLTOPDF — Is possible to display dynamic headers?

淺唱寂寞╮ 提交于 2019-12-20 04:19:00

问题


Im using wkhtmltopdf --header-html option, but it seems, that it really works only with html code. Is there any way I can add some PHP and force it to working somehow? I need to display Date and user´s e-mail on every page... Thanks for any advice ;)


回答1:


You can feed --header-html almost anything :) Try the following to see my point:

wkhtmltopdf.exe --margin-top 30mm --header-html isitchristmas.com google.fi x.pdf

So isitchristmas.com could be www.yoursite.com/magical/ponies.php

Just to add, you cant run the php files locally so you need a webserver to serve them. If you need 100% local dynamic headers you could try some fake dynamic with javascript; use --header-html myheader.html?date=12345&usermail=derp and then process the URL with javacript (I havent tried it).




回答2:


To add extra query string parameters for your header/footer html you need to use the command line switch 'replace'.

The wording of the help/manual is a little misleading (i.e. better wording would have cleared up the issue), as it lead me on the wrong path (tried using the 'post' switch). I found the solution after digging through the code on github.



来源:https://stackoverflow.com/questions/11981853/wkhtmltopdf-is-possible-to-display-dynamic-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!