[英]itextsharp html to pdf creates no borders
I use iTextSharp (on SharePoint but I hope this does not matter) to convert a HTML document to PDF. 我使用iTextSharp(在SharePoint上,但我希望这没有关系)将HTML文档转换为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.
我只是无法让iTextSharp创建任何边框。
Update : Also is it possible just to define a Border on only one specific side? 更新 :还有可能只在特定的一侧定义边框吗?
use this code. 使用此代码。
<table border="1">
sure its woirking. 肯定它正在徘徊。 but solid and px is not working in html to pdf.
但solid和px在html到pdf中不起作用。
you can play with table borders and have some examples here: http://demo.itextsupport.com/xmlworker/ 您可以使用桌子边框,并在此处提供一些示例: http : //demo.itextsupport.com/xmlworker/
XMLWorker CSS and HTMLsupport documentation http://demo.itextsupport.com/xmlworker/itextdoc/index.html XMLWorker CSS和HTMLsupport文档http://demo.itextsupport.com/xmlworker/itextdoc/index.html
If you want to set only the left border in a table using only css, use the code below: 如果要仅使用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;
}
you can also set the borders with different colors: 您还可以设置不同颜色的边框:
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;
}
Maybe the browser won't apply these styles but iTextSharp will. 也许浏览器不会应用这些样式,但iTextSharp会应用。 As you can see, you must be very specific in the css properties.
如您所见,您必须在css属性中非常明确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.