I am working on an ASP.NET MVC project which converts a view to a PDF. Previously, Rotavia was used, but then a new client requirement is that the PDF be accessible/508-compliant. For layout purposes, the previous developer had a whole header section (logo, title, disclaimer, etc) as a table without th elements (just td). I needed to convert them to divs but keep the look the same. So, what I did was made them divs and then used the CSS properties, display: table, display: table-row-group, display: table-row, and display: table-cell where appropriate. It ended up looking pretty much exactly the same.
The issue is, even though they are now divs, using iText DefaultTagWorkerFactory like this:
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 the Div tags to table, tr, and td tags. Obviously, the whole purpose of using display: table on a div is to avoid using a table but get the same layout effect.
Why does iText implement this behavior and is there any way around it? If not, can anyone provide any precise CSS equivalents of display: table, display: table-row-group, display: table-row, and display: table-cell because it appears that iText just sees the property, "display: table" and uses the table-tag. I have tried the following in a custom tag worker factory that inherits the DefaultTagWorkerFactory by adding a class to my divs, "make-div", like this:
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;
}
}
However, it throws an exception like "Cannot implicitly convert DivTagWorker to DisplayTableRowTagWorker".
I'm at my wits end with all of this. Any help would be appreciated. Thank you.