我正在创建一个 web 表单,它将对 word 文档进行 508 合规性检查。我正在浏览 MSDN 和其他网站,以从用户选择的文件中获取我需要的信息。我找不到的一件事是如何查找图像,并检查它们是否有替代文本。任何帮助将不胜感激!
2 回答
插入 2007+ Word 文档的图像是Drawing
对象。因此,您可以遍历 XML 的w:drawing
成员。
http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.drawing.aspx
该w:drawing
成员将有一个称为孩子的孩子,该孩子w:inline
是Inline
班级的一部分。
http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.wordprocessing.inline.aspx
该w:inline
成员将有一个名为 的成员wd:docPr
。
该wd:docPr
成员可能有一个名为的字段title
,其中包含替代文本标题和一个字段,称为字段descr
,其中包含所有替代文本。
示例 XML:
<w:drawing xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="357A850A" wp14:editId="384E9053" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
<wp:extent cx="5943600" cy="4457700" />
<wp:effectExtent l="0" t="0" r="0" b="0" />
<wp:docPr id="1" name="Picture 1" descr="ALL TEXT HERE" title="ALT TEXT TITLE HERE"/>
...
我强烈建议您使用 OpenXML SDK 附带的 OpenXML Productivity Tool。
您可以使用 unzip 和 lxprintf 的副本(LTXML2 工具包的一部分)更轻松地执行相同的操作,方法是在循环中解压缩幻灯片并在每个幻灯片上运行 lxprintf 以定位 wp:docPr 元素并输出 @ 的值描述和@title,例如
for f in `unzip -l demo.pptx | grep ppt/slides/slide.*\.xml | awk '{print $NF}'`; do
unzip -p demo.pptx $f |\
lxprintf -e 'w:drawing/wp:inline/wp:docPr' "%s, %s\n" @descr @title -
done