提问人:Andre Rubnikowich 提问时间:11/8/2023 更新时间:11/10/2023 访问量:42
ITEXT 7 辅助功能检查替代文本
ITEXT 7 Accessibility check Alternate Text
答:
1赞
Mytho
11/10/2023
#1
您可以通过标记树访问该信息。
正常设置 PDF 文档。您将需要一个新的标记树指针。
string input = "input.pdf";
PdfReader reader = new(input);
PdfDocument document = new(reader);
Document pdf = new(document);
// This code is usually in its own method so we can get as many as we need
// Get the tag pointer at the root tag
TagTreePointer original = pdf.GetPdfDocument().GetTagStructureContext().GetAutoTaggingPointer().MoveToRoot();
// Get the element for the pointer. We use this to make a new pointer
PdfStructElem elem = original.GetContext().GetPointerStructElem(original);
// Return a new pointer using the element
var pointer = original.GetContext().CreatePointerForStructElem(elem);
您可以重复使用指针,但我发现为每个操作获取一个新指针很有帮助。
接下来,移至要检查的代码。为简单起见,我们将使用第一个子项。
// Move to first child (assuming one exists)
pointer.MoveToKid(0);
现在我们可以查看标签的属性了。
// view data
pointer.GetProperties().GetActualText();
pointer.GetProperties().GetAlternateDescription();
pointer.GetProperties().GetStructureElementId();
// title is a bit more complicated. We have to use the low-level pdf struct and view the T (title) attribute
pointer.GetContext().GetPointerStructElem(pointer).GetPdfObject().GetAsString(PdfName.T);
您将需要编写代码来处理 null 值和标记。
评论