作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看到了所有内容,没有看到使用“--replace”的方式的内容。
如何在 wkhtmltopdf 中使用“--replace”。
请给我一个例子,谢谢。:)
最佳答案
假设您有一个页脚 my_footer.html,其中包含以下内容:
<!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>
wkhtmltopdf my_super_html.html --footer-html my_footer.html --replace "username" "Veaer"
关于replace - 如何在 wkhtmltopdf 中使用 "--replace",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26985285/
我是一名优秀的程序员,十分优秀!