I am working on an ASP.NET MVC project that converts a view to PDF. Previously, Rotavia was used, but then the requirement of the new client was for the PDF to be available / 508-compatible. For layout purposes, the previous developer had an entire header section (logo, title, disclaimer, etc.) in the form of a table without th elements (only td). I needed to convert them to divs, but keep the same. So, I made them divs and then used the CSS properties, display: table, display: table-row-group, display: table-row and display: table-cell, where necessary. In the end, it looked exactly the same.
The problem is that they are now divs using iText DefaultTagWorkerFactory as follows:
ConverterProperties props = new ConverterProperties();
FontProvider fp = new FontProvider();
fp.AddStandardPdfFonts();
props.SetFontProvider(fp);
var tagWorkerFactory = new DefaultTagWorkerFactory();
props.SetTagWorkerFactory(tagWorkerFactory);
HtmlConverter.ConvertToPdf(html, pdfDoc, props);
It still converts Div tags to table, tr and td tags. Obviously, the whole purpose of using display: table in a div is to avoid using a table, but to get the same layout effect.
Why does iText implement this behavior and is there any way to fix it? If not, can anyone provide any exact CSS equivalents for the display: table, display: table-row-group, display: table-row and display: table-cell, because it seems that iText just sees the property " display: table ", and uses a table tag. I tried the following in a custom factory tag that inherits DefaultTagWorkerFactory by adding a class to my divs, make-div, as follows:
public class AccessibilityTagWorkerFactory : DefaultTagWorkerFactory
{
public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context)
{
var attributes = tag.GetAttributes();
var cssClass = attributes.GetAttribute("class");
if (!string.IsNullOrWhiteSpace(cssClass) && cssClass.Contains("make-div"))
{
return new DivTagWorker(tag, context);
}
return null;
}
}
" DivTagWorker DisplayTableRowTagWorker".
. . .