环境是:flyingsaucer r8 和 itext 2.0.8
我将使用飞碟和 itext 创建 pdf 文件,我添加了
表格布局:固定;自动换行:断字;
从上图中可以看出,“Description”栏的超长英文句子可以正确换行,但“Account Code”和“Description”中的超长数字无法换行。
我也试过“word-break: break-all;”,但还是不行。
我的 xhtml 文件是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
@page {-fs-flow-top: 'header';-fs-flow-bottom: 'footer';size:210mm 297mm;margin-top:40pt;@top-center {content: element(header)}
@bottom-center {content: element(footer)}page-break-before:always}#pagenumber:before { content: counter(page); }
#pagecount:before { content: counter(pages); }.pageNext{page-break-before: always;}
#header {position: running(header);font-style: italic;font-family: Arial Unicode MS;
-fs-move-to-flow: 'header';width: 100px; padding-top:10pt;}#footer {position: running(footer);font-style: italic;
font-family: Arial Unicode MS;-fs-move-to-flow: 'footer';color: #6c6ce8;}
body{font-size:13px;font-family:Arial Unicode MS;white-space:inherit;}b{font-size:13px;font-weight:bold;font-family:Arial;}
#dt th{text-align: center;font-family:Arial;font-weight:bold;}#title {font-size:15px;font-weight:bold;}#lab {font-size:15px;font-weight:bold;}
table.data{ border-top: 1px solid #333;border-bottom: 1px solid #333;width:100%;border:1px solid #333;}table{ border-collapse:collapse;}
table td{ padding:0 0 0 0; vertical-align:top;white-space:inherit;}
table.uReportStandard > thead > tr > th{ border:0.5pt #333 solid; background:#d5d0c3;color:#000;text-align:center;font-size:15px;
font-family:Arial,sans-serif;font-weight:bold;}
table.uReportStandard > tbody > tr > td{ padding:1px 1px; font-size:13px;}.data td.left_text{ font-size:13px;
font-family:Arial Unicode MS,sans-serif;width:300px;}.data td.right_text{ text-align:right;font-size:13px;
font-family:Arial Unicode MS,sans-serif;width:120px;}table#uPageCols td#uRightCol,table#uPageCols td#uRightCol aside{width:0;}
table.uReportStandard{border:0.5px #333 solid;}
</style>
<meta http-equiv='content-type' content='text/html; charset=UTF-8' />
<title></title>
</head>
<body>
<div id='footer' style='text-align:center;margin-top:0;'>
Page <span id='pagenumber' /> of <span id='pagecount' /><span style='margin-left:150px;'>2016-05-23 16:03:07</span>
</div>
<div>
<table border='0' id='dt' style='width:100%;table-layout:fixed;word-wrap:break-word;'>
<thead>
<tr style='background-color: gainsboro;border:solid 1px #333;'>
<th style='border:solid 1px #333;width:10%;'>Account Code</th>
<th style='border:solid 1px #333;width:29%;'>Bank Name</th>
<th style='border:solid 1px #333;width:35%;'>Description</th>
<th style='border:solid 1px #333;width:13%;'>Load(CNY)</th>
<th style='border:solid 1px #333;width:13%;'>Borrow(CNY)</th>
</tr>
</thead>
<tr>
<td style='border:solid 1px #333;'>66020901039</td>
<td style='border:solid 1px #333;'>ABC DEF<br />
-Global Logistics LTD</td>
<td style='border:solid 1px #333;white-space:inherit;'>break-all Behaves the same as normal for Asian text, yet allows the line to break arbitrarily for non-Asian text. This value is suited to Asian text that contains some excerpts of non-Asian text. Debit: EUR 50.00</td>
<td style='text-align: right;border:solid 1px #333;'>367.47</td>
<td style='text-align: right;border:solid 1px #333;'>
</td>
</tr>
<tr>
<td style='border:solid 1px #333;'>220201</td>
<td style='border:solid 1px #333;'>ACCOUNT PAYABLE<br />
-Global Logistics LTD</td>
<td style='border:solid 1px #333;white-space:inherit;'>88888888888888888889999999999999999997777777777777 Credit: EUR 284.36</td>
<td style='text-align: right;border:solid 1px #333;'>
</td>
<td style='text-align: right;border:solid 1px #333;'>2,089.85</td>
</tr>
</table>
</div>
</body>
</html>
我的代码是:
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(new File("test.xhtml"));;
renderer.layout();
FileOutputStream fos = new FileOutputStream("a.pdf");
renderer.createPDF(fos);
fos.close();
我的问题是:
- 如何表格布局:固定;自动换行:断字;包装内容?它基于什么包装?
- 为什么英文/中文centense可以正确包装,而number不能?
- 如何在我的情况下包装号码?
提前致谢!
使用 itext 5.5.9 后,数字可以正确包装,但现在 css : -fs-table-paginate: paginate; #pagenumber:之前 { 内容:计数器(页面);}#pagecount:before { 内容:计数器(页数);} 在 itext 5.5.9 中不起作用