环境是:flyingsaucer r8和itext 2.0.8
我要用flyingsaucer和itext创建pdf文件,我添加了
表格的布局:固定的;自动换行:打破字;
从上图中,我们可以看到列中的长英文句子'描述'可以正确包装,但是“帐户代码”中包含过多的号码。和'描述'不能被包裹。
我也尝试过#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();
我的问题是:
提前致谢!
使用itext 5.5.9之后,数字可以正确包装,但现在css:-fs-table-paginate:paginate; #pagenumber:在{content:counter(page)之前; } #pagecount:before {content:counter(pages); }没有在itext 5.5.9
中工作答案 0 :(得分:1)
正如@Lonzak所说,我刚刚用flying-saucer-core.9.0.9.jar和flying-saucer-pdf.9.0.9.jar替换了core-renderer-r8.jar,使用了itext 2.1.7,然后它适用于css:
表格的布局:固定的;自动换行:打破字
,可以正确包装长的非空字符串或数字。
答案 1 :(得分:0)
我对此很不满意,建议您遵循此解决方案。 如果您使用百里香叶,请尝试使用.abbreviate方法:
${#strings.abbreviate( ${exampleOfText}, 10)}