不能将其包装在flyingsaucer和itext中 [英] number cannot be wrapped in flyingsaucer and itext

查看:120
本文介绍了不能将其包装在flyingsaucer和itext中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境是:flyingsaucer r8和itext 2.0.8

environment is : flyingsaucer r8 and itext 2.0.8

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

I'm going to create pdf file with flyingsaucer and itext, I added

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

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

包装单元格内容.但是,生成的pdf文件如下所示:

to wrap the cell content. However, the generated pdf file looks like next :

从上图可以看出,"Description"列的超长英语句子可以正确包装,但是"Account Code"和"Description"中的超长数字不能包装.

from the above diagram, we can see that over long English sentence of column 'Description' can be wrapped correctly, but the over long number in 'Account Code' and 'Description' cannot be wrapped.

我还尝试了断字:全部中断",但仍然无法正常工作.

I also tried "word-break: break-all;", but it still doesn't work.

我的xhtml文件是:

my xhtml file is :

<!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. 为什么英文/中文百分号可以正确包装,而数字却不能?
  3. 如何在我的情况下包装数字?

提前谢谢!

使用itext 5.5.9后,可以正确包装数字,但是现在css:-fs-table-paginate:paginate; #pagenumber:before {content:counter(page); } #pagecount:之前{内容:计数器(页); }在itext 5.5.9中不起作用

推荐答案

正如@Lonzak所说,我只是用flying-saucer-core.9.0.9.jar和flying-saucer-pdf替换了core-renderer-r8.jar .9.0.9.jar,使用itext 2.1.7,然后与css一起使用:

as @Lonzak said, I just replaced core-renderer-r8.jar with flying-saucer-core.9.0.9.jar and flying-saucer-pdf.9.0.9.jar, use itext 2.1.7, then it works with css :

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

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

,可以正确包装长的非空白字符串或数字.

, the long non-blank string or number can be wrapped correctly.

这篇关于不能将其包装在flyingsaucer和itext中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆