I am converting HTML to PDF using iTextSharp but am having problems with styling.
I am using iTextSharp version 5 and am able to style the 开发者_运维知识库tags using the following code:
StyleSheet styles = new StyleSheet();
styles.LoadTagStyle(HtmlTags.H1, HtmlTags.FONTSIZE, "16");
styles.LoadTagStyle(HtmlTags.P, HtmlTags.FONTSIZE, "10");
I then parse the HTML and style sheet using this:
List<IElement> objects = HTMLWorker.ParseToList(new StringReader(htmlText), styles);
My question is can i import an external stylesheet in instead of having to specify each one of the tags individually?
I have found this code on earlier posts:
builder.ImportStylesheet(Request.PhysicalApplicationPath + "CSS\\Stylesheet.css");
but i cannot seem to get this to work, is this from an older version of iTextSharp which has been taken out of the latest version?
That looks like its using HtmlToPdfBuilder which is not from the makers of iText or iTextSharp but might still work for you.
[EDIT]
Dead link removed, used to be http://somewebguy.wordpress.com/tag/itextsharp/
精彩评论