gpt4 book ai didi

java - number 不能包裹在 flyingsaucer 和 itext 中

转载 作者:太空宇宙 更新时间:2023-11-04 10:13:38 24 4
gpt4 key购买 nike

环境是:flyingsaucer r8 和 itext 2.0.8

我要用 flyingsaucer 和 itext 创建 pdf 文件,我添加了

table-layout:fixed;word-wrap:break-word;

包裹单元格内容。但是,生成的 pdf 文件如下所示: enter image description here

从上图可以看出,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();

我的问题是:

  1. 表格布局如何:固定;自动换行:分词;包装内容?它基于包装什么?
  2. 为什么英文/中文centense可以正确换行,而数字不能?
  3. 如何在我的案例中包装号码?

提前致谢!

使用 itext 5.5.9 后,数字可以正确换行,但现在 css : -fs-table-paginate: paginate; #pagenumber:before { 内容:计数器(页); }#pagecount:before { 内容:计数器(页面); } 在 itext 5.5.9 中不起作用

最佳答案

正如@Lonzak 所说,我只是将 core-renderer-r8.jar 替换为 flying-saucer-core.9.0.9.jar 和 flying-saucer-pdf.9.0.9.jar,使用 itext 2.1.7,然后它适用于 CSS:

table-layout:fixed;word-wrap:break-word

,长的非空字符串或数字可以正确换行。

关于java - number 不能包裹在 flyingsaucer 和 itext 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com