更改itextsharp的字体大小

时间:2012-08-03 01:27:31

标签: c# itextsharp

我可以更改表格标题的颜色,但我无法更改字体大小

StyleSheet css = new StyleSheet();
css.LoadTagStyle(HtmlTags.TH, HtmlTags.FONTSIZE, "5");
css.LoadTagStyle(HtmlTags.TH, HtmlTags.COLOR, "Red");
var response = context.HttpContext.Response;

using (var pdfStream = new MemoryStream()) 
using (var pdfDoc = new Document()) 
using (var pdfWriter = PdfWriter.GetInstance(pdfDoc, pdfStream)) { 

pdfDoc.Open();

using (var htmlRdr = new StringReader(writer.ToString())) {

   var parsed = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(htmlRdr, css);
   foreach (var parsedElement in parsed) {
     pdfDoc.Add(parsedElement);
   }
}

pdfDoc.Close();

1 个答案:

答案 0 :(得分:3)

您还可以使用文档标题加载CSS

StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
styles.LoadTagStyle("th", "color", "red");
styles.LoadTagStyle("th", "frontsize", "5");
pdfDoc.Add(new Header(iTextSharp.text.html.Markup.HTML_ATTR_STYLESHEET, "Style.css"));

这里有更多内容 http://hspinfo.wordpress.com/2008/01/12/how-to-convert-html-content-to-pdf-file/