1

I use iTextSharp (on SharePoint but I hope this does not matter) to convert a HTML document to PDF. So far I was unable to get any borders around elements. How do I do this? Is this not supported?

Things I tried:

  // in c# code
StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
styles.LoadStyle("borderCls", "border-style", "solid"); // <td class="borderCls">
styles.LoadStyle("borderCls", "border-width", "1px");
styles.LoadStyle("borderCls", "border-color", "#000");
  //
styles.LoadStyle("borderCls", "border", "solid 1px #000");

  // in html
<td style="border:solid 1px #000">
  //
<td border="1">
  //
<td style="border-style:solid;border-width:1px">

But these did not work. I just can't get iTextSharp to create any borders.

Update: Also is it possible just to define a Border on only one specific side?

4

2 回答 2

5

使用此代码。

<table border="1">

确定它的工作。但solid 和 px 在 html 到 pdf 中不起作用。

于 2013-07-04T11:30:28.790 回答
1

您可以使用表格边框并在此处提供一些示例:http: //demo.itextsupport.com/xmlworker/

XMLWorker CSS 和 HTML 支持文档http://demo.itextsupport.com/xmlworker/itextdoc/index.html

如果您只想使用 css 在表格中设置左边框,请使用以下代码:

td.black-left-border {
    border: 0;    /*First set all the borders to 0, then set the desired borders width*/
    border-color: black;
    border-left-width: 1px; /*PDF*/
    border-left-style: solid;
}

您还可以设置不同颜色的边框:

td.black-left-border-blue-bottom-border {
    border: 0;    
    border-left-color: black;
    border-bottom-color: blue; 
    border-left-width: 1px; 
    border-bottom-width: 1px;
    border-left-style: solid;
    border-bottom-style: solid;
}

也许浏览器不会应用这些样式,但 iTextSharp 会。如您所见,您必须在 css 属性中非常具体。

于 2013-09-30T15:35:15.623 回答