我遇到了wicked_pdf的问题。它没有考虑我的任何JavaScript。正在生成报告,并且呈现的文本是“未定义的页面未定义”。任何有关将javascript链接到wicked_pdf的帮助都将非常感谢!
标记:
<html>
<head>
<script>
function number_pages() {
console.log('hi');
var vars={};
var x=document.location.search.substring(1).split('&');
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
for(var i in x) {
var y = document.getElementsByClassName(x[i]);
for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script>
</head>
<body onload="number_pages()">
Page <span class="page"></span> of <span class="topage"></span>
</body>
</html>
控制器操作:
def generate_report
respond_to do |format|
format.html
format.pdf do
render :pdf => "hello.pdf", :template => "reports/templates/#{params[:report]}.pdf.erb", :disable_javascript => false
end
end
end
答案 0 :(得分:1)
该代码在wkhtmltopdf文档中作为示例提供,仅在头文件或页脚文件中提供时才有效:
format.pdf do
render :pdf => "hello.pdf",
:template => "reports/templates/#{params[:report]}.pdf.erb",
:footer => {
:html => {
:template => "reports/templates/#{params[:report]}.pdf.erb"
}
}
end
运行此功能时,内部模板会显示page undefined of undefined
,但页脚会显示page 1 of 1
。我认为这与wkhtmltopdf中的页面拆分内部有关。