繁体   English   中英

td border,使用itext库无法在pdf中打印border-bottom

[英]td border , border-bottom is not printing in pdf by using itext library

<tr><td style='border-bottom:1px solid #333;'><p style='font-family:arial; font-size:8px; margin:0px 0px 10px 0px;  line-height:10px;'><strong>Customer Details </strong><br>Lawakush Kurmi<br>8285998390<br>lkurmi@craterzone.com<br> </p></td><td valign='top' style='font-family:arial; font-size:8px;  text-align:right; border-bottom:1px solid #333;'>&nbsp;</td></tr>

我正在尝试使用i-text库将这些html代码转换为pdf。但是border-bottom:1px没有在pdf中绘制任何边框。 请建议使用html在pdf中绘制水平线边框的最佳选择是什么。
注意 :我正在使用HTMLWorker将HTML转换为PDF页面。

请允许我重复使用iTextSharp add(css样式或css文件)中的代码并下载pdf文件,并稍微更改一些值:

public static final String CSS = "th { border-top: 5px solid green; } "
    + "td { font-size: 10pt; border-color: gray; border: 3px}";
public static final String HTML = "<html><body><table  class='table-bordered'>"
    + "<thead><tr><th>Customer Name</th><th>Customer's Address</th> </tr></thead>"
    + "<tbody><tr><td> XYZ </td><td> Bhubaneswar </td></tr>"
    + "<tr><td> MNP </td><td> Cuttack </td></tr></tbody>"
    + "</table></body></html>";

/**
 * @param file
 * @throws IOException
 * @throws DocumentException
 */
public void createPdf(String file) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();


    CSSResolver cssResolver = new StyleAttrCSSResolver();
    CssFile cssFile = XMLWorkerHelper.getCSS(new ByteArrayInputStream(CSS.getBytes()));
    cssResolver.addCss(cssFile);

    // HTML
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());

    // Pipelines
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
    CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

    // XML Worker
    XMLWorker worker = new XMLWorker(css, true);
    XMLParser p = new XMLParser(worker);
    p.parse(new ByteArrayInputStream(HTML.getBytes()));
    document.close();
}

生成的PDF如下所示:

在此处输入图片说明

如果查看CSS ,则会看到我们将<th>标记的边框定义为border-top: 5px solid green; <td>标签的边框为font-size: 10pt; border-color: gray; border: 3px font-size: 10pt; border-color: gray; border: 3px font-size: 10pt; border-color: gray; border: 3px 这证明iText支持CSS用于表格边框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM