dan_vitch
dan_vitch

Reputation: 4559

change font size of itextsharp

I am able to change the color of my table header, but I cant change the font size

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

Upvotes: 2

Views: 7751

Answers (1)

COLD TOLD
COLD TOLD

Reputation: 13579

you can also use the header of your document to load the 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"));

here more in this article http://hspinfo.wordpress.com/2008/01/12/how-to-convert-html-content-to-pdf-file/

Upvotes: 3

Related Questions