I have an HTML table in a view. I use ITextSharp to convert HTML to PDF. I want to use external CSS and repeat the table title for each page. How can I show the title on each page using CSS and the page title?
This means the page title
str.Append("<table class='text-center'>");
str.Append("<tr class='h4'><td> " + companyName + " </ td ></ tr >");
str.Append("</table>");
And this is to show my HTML
TextReader xmlString = new StringReader(str.Append(html).ToString());
And to add my CSS
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCssFile(HttpContext.Current.Server.MapPath(@"~/Content/Print.css"), true);
IPipeline pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
var worker = new XMLWorker(pipeline, true);
var xmlParse = new XMLParser(true, worker);
xmlParse.Parse(xmlString);
xmlParse.Flush();
This code works fine, but I use 1 table to display the data, and the table title is not repeated for every page. If I use this code to repeat table headings, CSS doesn't Work. How can I solve this problem using both CSS and a repeating header.
using (TextReader sr = new StringReader(html))
{
List<IElement> elements =
iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, null);
foreach (IElement el in elements)
{
if (el is PdfPTable)
{
((PdfPTable)el).HeaderRows = 2;
}
document.Add(el);
xmlParse.Parse(sr);
}
}