在使用XMLWorker和itext解析html时,如何将cellspacing添加到pdftable [英] how can I add cellspacing to pdftable when parsing html using XMLWorker and itext

查看:189
本文介绍了在使用XMLWorker和itext解析html时,如何将cellspacing添加到pdftable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XMLWorker和itext将html转换为pdf。
我的html有一个表,我需要设置它的cellspacing = 0 cellpadding = 0。
有没有人知道怎么做?

I am using XMLWorker and itext to convert html to pdf . my html have a table and I need to set it's cellspacing =0 cellpadding=0 . does anyone know how to do it ?

在html中我看到我可以通过设置样式来替换它:

in html I saw I can replace it by setting the style :


border-collapse:collapse;
border-spacing:0px;
border:0;
填充:0;

谢谢
Tami

thanks Tami

推荐答案

我已经尝试使用你提出的CSS做了什么,它对我有用:

I've tried what you're doing using the CSS you propose and it works for me:

你可以在这里找到我的测试: ParseHtmlTable5

You can find my test here: ParseHtmlTable5

这是我的HTML(包括CSS): table3_css.html

This is my HTML (including the CSS): table3_css.html

<html>
<head>
<style>
    table, td {
        border: 1px solid green;
        border-spacing: 0px;
        padding: 0px;
    }
</style>
</head>
<body>
<table class='test'>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>Peter</td>
    <td>Griffin</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>Lois</td>
    <td>Griffin</td>
    <td>$150</td>
  </tr>
  <tr>
    <td>Joe</td>
    <td>Swanson</td>
    <td>$300</td>
  </tr>
  <tr>
    <td>Cleveland</td>
    <td>Brown</td>
    <td>$250</td>
</tr>
</table>
</body>
</html>

我建议你将我的HTML与我的HTML进行比较,找出你做错了什么。
您还应该使用最新版本的XML Worker和iText(夏普),因为我们在最新版本中对HTML解析进行了大量改进。

I suggest that you compare your HTML with mine to find out what you're doing wrong. You should also use the latest version of XML Worker and iText(Sharp) as we've improved HTML parsing significantly in the latest releases.

注意我已经定义了1px的实心绿色边框,以证明细胞之间没有填充物和间距。如果您更改这样的CSS:

Note that I've defined a solid, green border of 1px to prove that there is no padding and no spacing between the cells. If you change the CSS like this:

<style>
    table, td {
        border: 0px;
        border-spacing: 0px;
        padding: 0px;
    }
</style>

你会得到一个没有边框的表的(丑陋)版本,没有单元格和没有在细胞内填充。

You'll get the (ugly) version of a table without borders, without spacing between the cells and without padding inside the cells.

这篇关于在使用XMLWorker和itext解析html时,如何将cellspacing添加到pdftable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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