How to use "-replace" in wkhtmltopdf

I saw all this content, did not see how to use '-replace'. How to use "-replace" in wkhtmltopdf. Please give me an example, thanks. :)

+5
source share
1 answer

Suppose you have my_footer.html footer that contains the following:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function substitutePdfVariables() { function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); } function substitute(name) { var value = getParameterByName(name); var elements = document.getElementsByClassName(name); for (var i = 0; elements && i < elements.length; i++) { elements[i].textContent = value; } } ['username'/*, 'topage', 'page',.. etc and any variable you would want to replace */] .forEach(function(param) { substitute(param); }); } </script> </head> <body onload="substitutePdfVariables()"> <span class="username"></span> </body> </html> 

You can replace "username" with some value:

 wkhtmltopdf my_super_html.html --footer-html my_footer.html --replace "username" "Veaer" 

Note that I used javascript to replace the named variable with my value.

0
source

Source: https://habr.com/ru/post/1207086/


All Articles