借助 TX Text Control:在 .NET C# 中驗證 PDF/UA 文檔

創建易于訪問且符合規范的 PDF 文檔正成為各行各業日益重要的需求。在本篇博文中,我們將探討如何使用 Text Control 的 .NET 庫驗證 PDF/UA 文檔,輕松確保生成的 PDF 符合無障礙標準。TX Text Control 34.0 將允許開發人員直接生成 PDF/UA 和 PDF/A-3a 文檔,這對于長期、合規的文檔歸檔而言是一項重大進步。
TX Text Control 官方試用版最新下載,請聯系慧都科技
什么是 PDF/UA 和 PDF/A-3a?
PDF/UA(通用無障礙)制定了確保所有人都能訪問 PDF 文檔的標準,包括使用輔助技術(如屏幕閱讀器)的用戶。
PDF/UA 確保文檔的結構、閱讀順序和元素描述得到正確定義,以便所有內容都能在語義上被理解。
另一方面,PDF/A-3a 是 ISO 標準化的歸檔 PDF 格式系列的一部分。它保證文檔可以原封不動地復制,包括嵌入式附件和可訪問內容(“a”代表“可訪問性”)。
這兩個標準都要求文檔包含邏輯結構、語義標簽和準確描述內容的元數據。
為什么驗證至關重要
在生成 PDF/UA 文件或設計模板的過程中,一些標簽或描述性元素經常會丟失或應用錯誤。即使文檔在視覺上看起來沒有問題,但它可能不符合無障礙或存檔標準,因此無法通過合規性檢查。
例如:
- 某個圖表可能缺少描述性文字。
- 表格可能缺少正確的表頭定義。
- 閱讀順序或標簽層級結構可能被打亂了。
- 可能未設置語言或文檔標題等元數據。
如果沒有驗證,這些問題很容易被忽視。
PDF/UA驗證
在 34.0 版本中,我們將引入一個驗證庫,旨在幫助開發人員檢查生成的 PDF 文檔的合規性。
該庫分析:
- 文檔結構樹和標簽層次結構
- 元數據和語言設置
- 表格、圖表、表單字段和超鏈接的描述性文本
- 表頭和數據單元格的關系
- 以及 PDF/UA 規范要求的其他與輔助功能相關的屬性
它以結構化的 JSON 格式生成詳細報告,并為控制臺應用程序提供文本輸出。這使得開發人員能夠將驗證直接集成到自動化測試或質量保證 (QA) 流程中。
C# 中的示例用法
以下是一個如何在 C# 應用程序中使用驗證庫的簡單示例:
using TXTextControl.PDF.Validation;
var report = PdfUaValidator.Validate("documents/hyperlink.pdf");
report.PrintText();
在這個例子中,我們首先創建一個驗證器實例,然后驗證文檔。驗證結果會輸出到控制臺,并可以序列化為 JSON 格式以進行進一步分析。

生成的 JSON 報告詳細概述了文檔中發現的所有合規性問題:
{
"filePath": "documents/hyperlink.pdf",
"pdfVersion": "1.7",
"isPass": true,
"documentTitle": "This is a sample PDF/UA document",
"documentLanguage": "en-US",
"findings": [
{
"ruleId": "UA-CONFORMANCE",
"severity": "Info",
"passed": true,
"message": "PDF/UA-1 conformance declaration found in XMP."
},
{
"ruleId": "PDFA-CONFORMANCE",
"severity": "Info",
"passed": true,
"message": "PDF/A-3A declaration found in XMP."
},
{
"ruleId": "PDF-HEADER",
"severity": "Error",
"passed": true,
"message": "Found PDF header %PDF-1.7."
},
{
"ruleId": "PDF-XREF",
"severity": "Warning",
"passed": true,
"message": "Cross-reference table/stream appears present."
},
{
"ruleId": "UA-CATALOG",
"severity": "Error",
"passed": true,
"message": "Catalog dictionary present."
},
{
"ruleId": "UA-MARKED",
"severity": "Error",
"passed": true,
"message": "/MarkInfo \u003C\u003C /Marked true \u003E\u003E found (Tagged PDF)."
},
{
"ruleId": "UA-STRUCT",
"severity": "Error",
"passed": true,
"message": "/StructTreeRoot present."
},
{
"ruleId": "UA-MCID-ANCHOR",
"severity": "Info",
"passed": true,
"message": "Marked content (/MCID) present and at least one page has /StructParents anchors."
},
{
"ruleId": "UA-TEXT-MAPPING",
"severity": "Info",
"passed": true,
"message": "Font ToUnicode maps present (text is likely accessible)."
},
{
"ruleId": "UA-LANG",
"severity": "Error",
"passed": true,
"message": "/Lang present at document/page level."
},
{
"ruleId": "UA-METADATA",
"severity": "Warning",
"passed": true,
"message": "XMP metadata packet detected."
},
{
"ruleId": "UA-TITLE",
"severity": "Error",
"passed": true,
"message": "Document title found (Info or XMP dc:title)."
},
{
"ruleId": "UA-TABS",
"severity": "Warning",
"passed": true,
"message": "Page /Tabs setting present."
},
{
"ruleId": "UA-FIG-ALT",
"severity": "Info",
"passed": true,
"message": "Figures detected: 3; descriptive text tokens (/Alt or /ActualText): 3."
},
{
"ruleId": "UA-LINK-DESC",
"severity": "Info",
"passed": true,
"message": "Links: 2; all appear to have nearby tooltip/contents/ActualText."
},
{
"ruleId": "UA-FORMS-TU",
"severity": "Info",
"passed": true,
"message": "AcroForm detected; tooltips (/TU) count: 3."
},
{
"ruleId": "UA-TABLE-A-SUMMARY",
"severity": "Info",
"passed": true,
"message": "Tables: 3; all have /A with /Summary."
},
{
"ruleId": "UA-TABLE-HEADERS",
"severity": "Info",
"passed": true,
"message": "Tables with headers: OK=1, missing/invalid=0."
}
],
"tableSummaries": [
{
"index": 1,
"summaryText": "Table description",
"summaryRaw": "(\u00FE\u00FF\u0000T\u0000a\u0000b\u0000l\u0000e\u0000 \u0000d\u0000e\u0000s\u0000c\u0000r\u0000i\u0000p\u0000t\u0000i\u0000o\u0000n)",
"hasOTable": true,
"source": "Obj 58: A 74 0 R",
"thTotal": 3,
"thWithScope": 3,
"tdWithHeaders": 0,
"headersOk": true,
"headersApplicable": true
},
{
"index": 2,
"summaryText": "Inner table",
"summaryRaw": "(\u00FE\u00FF\u0000I\u0000n\u0000n\u0000e\u0000r\u0000 \u0000t\u0000a\u0000b\u0000l\u0000e)",
"hasOTable": true,
"source": "Obj 59: A 96 0 R",
"thTotal": 0,
"thWithScope": 0,
"tdWithHeaders": 0,
"headersOk": true,
"headersApplicable": false
},
{
"index": 3,
"summaryText": "Third table",
"summaryRaw": "(\u00FE\u00FF\u0000T\u0000h\u0000i\u0000r\u0000d\u0000 \u0000t\u0000a\u0000b\u0000l\u0000e)",
"hasOTable": true,
"source": "Obj 60: A 122 0 R",
"thTotal": 0,
"thWithScope": 0,
"tdWithHeaders": 0,
"headersOk": true,
"headersApplicable": false
}
],
"links": [
{
"index": 1,
"linkText": "Descriptive Text",
"linkTextRaw": "(\u00FE\u00FF\u0000D\u0000e\u0000s\u0000c\u0000r\u0000i\u0000p\u0000t\u0000i\u0000v\u0000e\u0000 \u0000T\u0000e\u0000x\u0000t)",
"targetType": "URI",
"targetValue": "http://www.textcontrol.com",
"targetRaw": "(http://www.textcontrol.com)",
"source": "Annot window"
},
{
"index": 2,
"linkText": "Descriptive Text",
"linkTextRaw": "(\u00FE\u00FF\u0000D\u0000e\u0000s\u0000c\u0000r\u0000i\u0000p\u0000t\u0000i\u0000v\u0000e\u0000 \u0000T\u0000e\u0000x\u0000t)",
"targetType": "URI",
"targetValue": "http://www.textcontrol.com",
"targetRaw": "(http://www.textcontrol.com)",
"source": "Annot window"
}
],
"figures": [
{
"index": 1,
"altText": "image in table",
"altRaw": "(\u00FE\u00FF\u0000i\u0000m\u0000a\u0000g\u0000e\u0000 \u0000i\u0000n\u0000 \u0000 \u0000t\u0000a\u0000b\u0000l\u0000e)",
"source": "Figure obj 55"
},
{
"index": 2,
"altText": "Barcode not in table",
"altRaw": "(\u00FE\u00FF\u0000B\u0000a\u0000r\u0000c\u0000o\u0000d\u0000e\u0000 \u0000n\u0000o\u0000t\u0000 \u0000i\u0000n\u0000 \u0000t\u0000a\u0000b\u0000l\u0000e)",
"source": "Figure obj 56"
},
{
"index": 3,
"altText": "Image description",
"altRaw": "(\u00FE\u00FF\u0000I\u0000m\u0000a\u0000g\u0000e\u0000 \u0000d\u0000e\u0000s\u0000c\u0000r\u0000i\u0000p\u0000t\u0000i\u0000o\u0000n)",
"source": "Figure obj 57"
}
],
"forms": [
{
"index": 1,
"fieldName": "list item",
"fieldNameRaw": "(list item)",
"fieldType": "Ch",
"tooltip": "list item",
"tooltipRaw": "(list item)",
"source": "Obj 10"
},
{
"index": 2,
"fieldName": "company_name",
"fieldNameRaw": "(company_name)",
"fieldType": "Tx",
"tooltip": "company_name",
"tooltipRaw": "(company_name)",
"source": "Obj 13"
},
{
"index": 3,
"fieldName": "is_client",
"fieldNameRaw": "(is_client)",
"fieldType": "Btn",
"tooltip": "is_client",
"tooltipRaw": "(is_client)",
"source": "Obj 15"
}
],
"standards": [
{
"standard": "PDF/UA",
"part": "1",
"conformance": null,
"source": "XMP"
},
{
"standard": "PDF/A",
"part": "3",
"conformance": "A",
"source": "XMP"
}
]
}
返回的Report對象提供了對驗證結果的結構化訪問,使得集成到現有工作流程中變得容易。
結論
即將發布的 TX Text Control 34.0 版本將為開發人員提供強大的工具,使他們能夠直接在 .NET 應用程序中創建和驗證符合 PDF/UA 和 PDF/A-3a 標準的文檔。該驗證庫簡化了確保可訪問性和合規性的流程,使開發人員能夠自信地滿足行業標準。
TX Text Control 官方試用版最新下載,請聯系慧都科技
創建易于訪問且符合規范的 PDF 文檔正成為各行各業日益重要的需求。在本篇bow中,我們將探討如何使用 Text Control 的 .NET 庫驗證 PDF/UA 文檔,輕松確保生成的 PDF 符合無障礙標準。
浙公網安備 33010602011771號