Html iText 7 PDF可访问性:“;表格标题单元格没有关联的子单元格“;
我正在使用iText 7将HTML转换为PDF。我需要PDF是可访问的(508符合适当的标记等),但是,无论我在表上放置什么标记,可访问性检查器都会给出相同的错误:“表头单元格没有关联的子单元格”。我试过设置范围、标题等。。。似乎什么都不管用。以下是其中一个表的示例,但它们都有相同的问题:Html iText 7 PDF可访问性:“;表格标题单元格没有关联的子单元格“;,html,pdf-generation,accessibility,itext7,section508,Html,Pdf Generation,Accessibility,Itext7,Section508,我正在使用iText 7将HTML转换为PDF。我需要PDF是可访问的(508符合适当的标记等),但是,无论我在表上放置什么标记,可访问性检查器都会给出相同的错误:“表头单元格没有关联的子单元格”。我试过设置范围、标题等。。。似乎什么都不管用。以下是其中一个表的示例,但它们都有相同的问题: <table class="problems" summary="Patient's diagnosed problems and associated ICD codes.">
<table class="problems" summary="Patient's diagnosed problems and associated ICD codes.">
<thead>
<tr>
<th scope="col" id="problem-header">
Problem
</th>
<th scope="col" id="icd-code-header">
Code
</th>
</tr>
</thead>
<tbody>
<tr>
<td headers="problem-header">Some Problem</td>
<td headers="icd-code-header">Some ICD Code</td>
</tr>
</tbody>
</table>
编辑3:
以下是AccessibilityTagWorkerFactory(请记住,我想要表现为表的表没有用类“make table div”标记,并且不应该受到此类中自定义设置的影响:
public class AccessibilityTagWorkerFactory : DefaultTagWorkerFactory
{
public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context)
{
bool hasClass = false;
foreach (var attribute in tag.GetAttributes())
{
if (attribute.GetKey() == "class")
{
hasClass = true;
}
}
if (hasClass && tag.GetAttribute(AttributeConstants.CLASS).Contains("make-h1"))
{
return new HRoleSpanTagWorker(tag, context, StandardRoles.H1);
}
if (hasClass && tag.GetAttribute(AttributeConstants.CLASS).Contains("make-h2"))
{
return new HRoleSpanTagWorker(tag, context, StandardRoles.H2);
}
if (hasClass && tag.GetAttribute(AttributeConstants.CLASS).Contains("make-table-div"))
{
return new DivRoleTableTagWorker(tag, context);
}
return base.GetCustomTagWorker(tag, context);
}
}
在与iText团队的Jon Reilly合作后,这是对我有效的最终解决方案(不需要列ID和相关的标题…只需要范围) 这是:
public class AccessibilityTagWorkerFactory : DefaultTagWorkerFactory
{
public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context)
{
//...
if (tag.Name() == "th")
{
return new ThWithScopeTagWorker(tag, context);
}
return base.GetCustomTagWorker(tag, context);
}
}
AcessibilityTagWorkerFactory是否来自?我不确定您使用哪个符合性检查器查看错误,但Acrobat的符合性检查器simplay表示,如果使用
TableHeaderTagWorker
,则“Headers”将失败(上面使用的类中的链接)而不是默认的ThTagWorker
Hi@JonReilly,谢谢你的回答。我用AccessibilityTagWorkerFactory编辑了这个问题。简短的回答是,它是根据该示例建模的,但它不使用TH标记进行任何自定义工作。如果默认情况下使用ThTagWorker,那么我应该没有问题,对吗?我是使用PAC 3检查可访问性:但使用了其他具有相同结果的测试,包括在Acrobat Pro中亲自检查标签。TH标签没有ID,TD标签与TH ID不关联。如下一版本pdfHtml(2.0.2)所述将支持PDF/UA标准要求的标记范围属性。如果有人在2.0.2正式发布之前看到此内容,我们将在此处提供快照构建:
public class ThWithScopeTagWorker : ThTagWorker
{
public ThWithScopeTagWorker(IElementNode element, ProcessorContext context) : base(element, context)
{
}
public override void ProcessEnd(IElementNode element, ProcessorContext context)
{
base.ProcessEnd(element, context);
IPropertyContainer elementResult = base.GetElementResult();
if (elementResult is IAccessibleElement)
{
((IAccessibleElement)elementResult).GetAccessibilityProperties().SetRole(StandardRoles.TH);
//Can use this in the future in case we have th elements with different scope than "col"
string htmlScope = element.GetAttribute("scope"); //This is the scope="XXX" in your HTML
AccessibilityProperties properties = ((IAccessibleElement)elementResult).GetAccessibilityProperties();
//Could add "Row" if needed based on htmlScope string above.
//For my purposes, all th elements were scope="col"
properties.AddAttributes(new PdfStructureAttributes("Table").AddEnumAttribute("Scope", "Column"));
}
}
}
public class AccessibilityTagWorkerFactory : DefaultTagWorkerFactory
{
public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context)
{
//...
if (tag.Name() == "th")
{
return new ThWithScopeTagWorker(tag, context);
}
return base.GetCustomTagWorker(tag, context);
}
}