Rails从html生成PDF
我在使用Rails从html生成PDF时遇到了一些问题。我试着使用和gems,这两个我都遇到了分页符问题,它们在Rails从html生成PDF,html,ruby-on-rails,pdf-generation,wicked-pdf,pdfkit,Html,Ruby On Rails,Pdf Generation,Wicked Pdf,Pdfkit,我在使用Rails从html生成PDF时遇到了一些问题。我试着使用和gems,这两个我都遇到了分页符问题,它们在中被破坏 让我向您展示我正在使用的Wicked\u PDF: 在我的控制器中: render pdf: "report", :template => "reports/index.html.erb", :layout => "pdf", :orientation => 'Landscape', footer:
中被破坏
让我向您展示我正在使用的Wicked\u PDF
:
在我的控制器中:
render pdf: "report",
:template => "reports/index.html.erb",
:layout => "pdf",
:orientation => 'Landscape',
footer: {
right: "Page [page] of [topage]",
font_size: 9
}
layouts/pdf.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.table {
border-bottom: 1px solid #ddd;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
width: 100%;
}
td,
th {
border-top: 1px solid #ddd;
padding: 2px;
text-align: left;
vertical-align: middle;
}
.table > thead th {
background: #f7f7f7;
}
</style>
</head>
<body>
<%= yield %>
</body>
</html>
<table class="table">
<thead>
<tr>Example of a text that breaks the tr</tr>
</thead>
<tbody>
<% 3.times do %>
<tr>
<td><%= "string " * 500 %></td>
</tr>
<% end %>
</tbody>
</table>
注意:我认为展示我对PDFKit
所做的事情是不相关的,因为html和css没有改变,只是呈现方式和问题完全相同
我错过了什么?
也欢迎使用其他gem的解决方案。对于PDFkit,您也可以使用此属性
.table{
tr{
前分页符:永远!重要;
}
}
@RuiSchnaiderJúnior您正在使用哪个版本的wkhtmltopdf库?已知旧版本存在分页符问题。该版本为wkhtmltopdf-0.12.2.1-1.fc20.x86_64。
tr, td, th, tbody, thead, tfoot {
page-break-inside: avoid !important;
}