2

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

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();
4

1 回答 1

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/

于 2012-08-03T02:58:46.417 回答