我在使用Rails从html生成PDF时遇到了一些问题。我尝试使用PDFKit和Wicked_PDF宝石,我遇到了分页问题,它们在<tr>
内突破。
让我告诉你我正在用Wicked_PDF
做什么:
在我的控制器中:
render pdf: "report",
:template => "reports/index.html.erb",
:layout => "pdf",
:orientation => 'Landscape',
footer: {
right: "Page [page] of [topage]",
font_size: 9
}
布局/ 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>
报告/ index.html.erb:
<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>
还尝试使用此css属性:
tr, td, th, tbody, thead, tfoot {
page-break-inside: avoid !important;
}
注意:我认为用PDFKit
显示我做了什么并不重要,因为html和css没有改变,只有它的渲染方式和问题是完全一样的。
我错过了什么?
欢迎使用其他宝石的解决方案。
答案 0 :(得分:0)