如何使用IronPDF在C#中創建符合508規範和可訪問的PDF
使用 IronPDF 在C# .NET中產生可存取的 PDF,可產生符合 PDF/UA 標準的文檔,開箱即用,滿足Section 508和WCAG 2.0 AA要求。 IronPDF 的 RenderHtmlAsPdfUA 方法自動將標記的內容結構、閱讀順序、替代文字處理以及可及性中繼資料添加至由 HTML 生成的 PDF,讓 .NET 開發者能夠為政府機構、醫療保健提供者及所有處理聯邦合約的組織構建支援螢幕閱讀器的文件。
本教學涵蓋了在 C# .NET 中建立符合 Section 508 標準和 PDF/UA 可存取文檔,從標記結構產生到表單可存取性和合規性驗證。
- 適合對象:需進行政府合約、聯邦專案或醫療/教育系統上的 .NET 開發者,這些系統法律上要求 PDF 可及性。
- 您將構建的內容:從 HTML 生成 PDF/UA、將舊版 PDF 轉換為 PDF/UA、語言標記、從語意 HTML 標記結構、圖像替代文字、可及性表格、書籤導航和標記的表單欄位。
- 運行環境: .NET 10、.NET 8 LTS、.NET Framework 4.6.2+ 和 .NET Standard 2.0。
- 應用此方法的時機:當您的 PDF 必須通過 Section 508 稽核、PDF/UA(ISO 14289)驗證或 WCAG 2.0 級別 AA 要求時。
- 技術層面的重要性:標準 PDF 缺乏語意結構。 IronPDF 可以根據格式良好的 HTML 自動建立螢幕閱讀器所需的標籤的內容樹。
只需幾行程式碼即可建立符合第 508 條款的 PDF/UA 文件:
-
1使用 IronPDF 安裝 NuGet Package Manager
-
2複製並運行這段程式碼。
using IronPdf; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdfUA("<html lang='en'><body><h1>Accessible PDF</h1></body></html>"); pdf.SaveAs("accessible-document.pdf");Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA("<html lang='en'><body><h1>Accessible PDF</h1></body></html>") pdf.SaveAs("accessible-document.pdf")Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA("<html lang='en'><body><h1>Accessible PDF</h1></body></html>") pdf.SaveAs("accessible-document.pdf") -
3部署到您的生產環境進行測試
立即在您的項目中開始使用 IronPDF,並使用 免費試用
購買或註冊 IronPDF 的 30 天試用版後,請在應用程式開始時新增您的授權金鑰。
IronPdf.License.LicenseKey = "KEY";IronPdf.License.LicenseKey = "KEY";Imports IronPdf
IronPdf.License.LicenseKey = "KEY"Imports IronPdf
IronPdf.License.LicenseKey = "KEY"立即在您的項目中開始使用 IronPDF,免費試用。
- TL;DR:快速入門指南
- 理解可及性標準
- 創建可及性 PDF
- 高級可及性功能
- 驗證和最佳實踐
什麼是第 508 條款合規性?為什麼它對 PDF 文件很重要?
第 508 條指的是 1998 年對 1973 年《康復法》的一項修正案。這項聯邦法律要求聯邦機構開發、採購、維護或使用的所有電子和資訊科技都必須對殘疾人無障礙。 其範圍不僅限於政府機關本身。 任何接受聯邦政府資助、與聯邦政府機構簽訂合約或向政府實體提供技術服務的組織也必須遵守規定。
其實際意義重大。 為聯邦醫療保健專案開發軟體的承包商不能僅僅交付螢幕上看起來正確的 PDF 報告。 這些文件必須能夠被螢幕閱讀器讀取,能夠透過鍵盤導航,其結構方式必須能夠被輔助技術解讀。 未能滿足這些要求可能會導致交付物被拒收、合約遺失,甚至可能面臨法律訴訟。
PDF文件在可訪問性方面面臨著獨特的挑戰。 與瀏覽器內建輔助功能渲染的 HTML 網頁不同,PDF 文件是獨立的文檔,必須包含自己的結構資訊。 如果 PDF 文件在視覺上看起來完美無瑕,但缺少正確的標籤、邏輯閱讀順序或圖像的替代文字,那麼對於依賴螢幕閱讀器的人來說,它可能完全無法使用。
不遵守規定的後果不僅限於法律風險。 製作難以取得文件的機構實際上排除了很大一部分受眾。 世界衛生組織統計,全球約有16%的人口患有某種形式的殘疾。 對於政府服務和聯邦資助計畫而言,將這些人排除在外不僅是糟糕的做法,而且是對公民權利保護的侵犯。
什麼是 PDF/UA 和 WCAG?它們與第 508 條有何關係?
了解不同無障礙標準之間的關係有助於明確開發人員實際需要實現的內容。 在討論無障礙 PDF 時,有三個關鍵標準相互交織:第 508 節、WCAG 和 PDF/UA。
Web 內容無障礙指南(通常稱為 WCAG)起源於萬維網聯盟。 這些指南確立了使數位內容可感知、可操作、可理解且穩健的原則。雖然 WCAG 主要針對網頁內容而設計,但其原則同樣適用於 PDF 文件。 2017 年更新的修訂版第 508 條標準直接將 WCAG 2.0 AA 等級作為合規性的技術基準。 這意味著滿足 WCAG 2.0 AA 要求實際上與滿足電子文件的第 508 條款要求相同。
PDF/UA,即 PDF/一般無障礙標準,是專為無障礙 PDF 文件設計的 ISO 標準(ISO 14289)。 WCAG 描述了無障礙內容應該達到的目標,而 PDF/UA 則規定了 PDF 檔案內部必須如何結構化才能實現這些目標。 該標準定義了標記內容、元資料、語言規範、替代文字和數十個其他技術要素的要求。
可以將這些標準視為互補的層次。 WCAG 規定了使用者所需的無障礙存取結果。 PDF/UA 提供了以 PDF 格式實現這些結果的技術規格。 第 508 條規定了遵守 WCAG 的法律要求,而 WCAG 又指出 PDF/UA 是 PDF 文件的實現途徑。
對開發者而言,實際意義顯而易見。 建置符合 PDF/UA 標準的文件符合第 508 節合規性的技術要求。 IronPDF 透過其內建的輔助功能處理了大部分此類複雜性,使您能夠專注於內容,而庫則管理底層 PDF 結構。
如何在C#中將現有的PDF轉換為PDF/UA格式?
許多組織都有大量現有的 PDF 文件庫,這些文件是在無障礙設計成為優先事項之前建立的。 與其重新創建這些文件,IronPDF 讓您能夠 將標準 PDF 轉換為 PDF/UA 格式。 此轉換過程會新增必要的標籤結構和元資料,以相容輔助技術。
轉換使用 SaveAsPdfUA 方法,它採用現有的 PdfDocument 物件並以 PDF/UA 格式匯出。 以下是一個完整的運行範例。
輸入 PDF
在此範例中,我們使用 sample-document.pdf,這是一個不具可及性功能的標準 PDF,代表需要轉換的典型舊文件。
以下代碼加載了一個現有的 PDF 文件,使用 PdfDocument.FromFile(),然後調用 SaveAsPdfUA() 以匯出具有 PDF/UA-1 合規性的新版本。 IronPDF 會自動分析文件結構,並新增所需的標記內容、元資料和輔助功能標記。
using IronPdf;
using System;
string inputPath = "document.pdf";
string outputPath = "document-accessible.pdf";
// Load the existing PDF document
PdfDocument pdf = PdfDocument.FromFile(inputPath);
// Export as PDF/UA compliant document
// The method automatically adds required accessibility structure
pdf.SaveAsPdfUA(outputPath);
Console.WriteLine($"Successfully converted {inputPath} to PDF/UA format.");using IronPdf;
using System;
string inputPath = "document.pdf";
string outputPath = "document-accessible.pdf";
// Load the existing PDF document
PdfDocument pdf = PdfDocument.FromFile(inputPath);
// Export as PDF/UA compliant document
// The method automatically adds required accessibility structure
pdf.SaveAsPdfUA(outputPath);
Console.WriteLine($"Successfully converted {inputPath} to PDF/UA format.");Imports IronPdf
Imports System
Dim inputPath As String = "document.pdf"
Dim outputPath As String = "document-accessible.pdf"
' Load the existing PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile(inputPath)
' Export as PDF/UA compliant document
' The method automatically adds required accessibility structure
pdf.SaveAsPdfUA(outputPath)
Console.WriteLine($"Successfully converted {inputPath} to PDF/UA format.")Imports IronPdf
Imports System
Dim inputPath As String = "document.pdf"
Dim outputPath As String = "document-accessible.pdf"
' Load the existing PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile(inputPath)
' Export as PDF/UA compliant document
' The method automatically adds required accessibility structure
pdf.SaveAsPdfUA(outputPath)
Console.WriteLine($"Successfully converted {inputPath} to PDF/UA format.")對於最初使用 lang 屬性從 HTML 呈現的文件,語言規範會保留在 PDF/UA 結構中。 以下範例展示語言標籤如何從 HTML 原始碼中保留下來。
輸入 PDF
此範例使用了 benefits-summary.pdf,需要進行可及性轉換的福利文件,並從其原有 HTML 來源保留了語言。
代碼加載了該 PDF,並調用了 SaveAsPdfUA() 進行轉換。 原始 HTML 的 lang 屬性中的語言規範保留在 PDF/UA 結構中,確保螢幕閱讀器使用正確的發音規則。
using IronPdf;
using System;
string inputPath = "document.pdf";
string outputPath = "document-accessible.pdf";
PdfDocument pdf = PdfDocument.FromFile(inputPath);
// Language is specified via the lang attribute in the HTML source.
// The PDF/UA structure preserves the language for screen readers.
pdf.SaveAsPdfUA(outputPath);
Console.WriteLine("Conversion complete with language specification.");using IronPdf;
using System;
string inputPath = "document.pdf";
string outputPath = "document-accessible.pdf";
PdfDocument pdf = PdfDocument.FromFile(inputPath);
// Language is specified via the lang attribute in the HTML source.
// The PDF/UA structure preserves the language for screen readers.
pdf.SaveAsPdfUA(outputPath);
Console.WriteLine("Conversion complete with language specification.");Imports IronPdf
Imports System
Module Program
Sub Main()
Dim inputPath As String = "document.pdf"
Dim outputPath As String = "document-accessible.pdf"
Dim pdf As PdfDocument = PdfDocument.FromFile(inputPath)
' Language is specified via the lang attribute in the HTML source.
' The PDF/UA structure preserves the language for screen readers.
pdf.SaveAsPdfUA(outputPath)
Console.WriteLine("Conversion complete with language specification.")
End Sub
End ModuleImports IronPdf
Imports System
Module Program
Sub Main()
Dim inputPath As String = "document.pdf"
Dim outputPath As String = "document-accessible.pdf"
Dim pdf As PdfDocument = PdfDocument.FromFile(inputPath)
' Language is specified via the lang attribute in the HTML source.
' The PDF/UA structure preserves the language for screen readers.
pdf.SaveAsPdfUA(outputPath)
Console.WriteLine("Conversion complete with language specification.")
End Sub
End ModuleIronPDF 預設產生 PDF/UA-1 輸出,這是該標準廣泛採用的版本。 轉換過程會分析現有的 PDF 結構,並添加適當的標籤,用於標題、段落、清單和其他內容元素。 雖然自動轉換對於許多文件來說效果很好,但複雜的佈局或掃描影像可能需要額外的人工幹預才能完全符合規範。
如何將 HTML 直接渲染到可存取的 PDF/UA 文件中?
轉換現有 PDF 文件可以解決歷史遺留內容的問題,但新文件如果從一開始就考慮到可訪問性,將會受益匪淺。 IronPDF 的 RenderHtmlAsPdfUA 方法直接從HTML 輸入生成符合標準的輸出。 這種方法利用格式良好的 HTML 中已有的語意結構來建立結構良好的 PDF。
以下範例示範如何將 HTML 字串渲染為可存取的 PDF。
代碼創建一個 ChromePdfRenderer 實例,並帶有包含標題和段落等語意元素的 HTML 字符串,調用 RenderHtmlAsPdfUA()。渲染器保留 HTML 結構為 PDF 標記,通過 MetaData.Title 設置文檔標題,並保存符合標準的輸出。 HTML 元素的 lang='en' 屬性在 PDF 中傳遞,以進行螢幕閱讀器語言檢測。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Quarterly Financial Report</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
h1 { color: #333; }
h2 { color: #555; margin-top: 20px; }
p { margin-bottom: 15px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
th { background-color: #f4f4f4; }
</style>
</head>
<body>
<h1>Q4 2024 Financial Summary</h1>
<p>This report provides an overview of financial performance for the fourth quarter.</p>
<h2>Revenue Highlights</h2>
<p>Total revenue increased by 12% compared to the previous quarter, driven primarily by expansion in the enterprise segment.</p>
<h2>Expense Analysis</h2>
<p>Operating expenses remained stable, with a slight reduction in administrative costs offset by increased investment in research and development.</p>
</body>
</html>";
// Render directly to PDF/UA format
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Set additional metadata for accessibility
pdf.MetaData.Title = "Q4 2024 Financial Summary";
pdf.SaveAs("financial-report-accessible.pdf");
Console.WriteLine("Accessible PDF created successfully.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Quarterly Financial Report</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
h1 { color: #333; }
h2 { color: #555; margin-top: 20px; }
p { margin-bottom: 15px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
th { background-color: #f4f4f4; }
</style>
</head>
<body>
<h1>Q4 2024 Financial Summary</h1>
<p>This report provides an overview of financial performance for the fourth quarter.</p>
<h2>Revenue Highlights</h2>
<p>Total revenue increased by 12% compared to the previous quarter, driven primarily by expansion in the enterprise segment.</p>
<h2>Expense Analysis</h2>
<p>Operating expenses remained stable, with a slight reduction in administrative costs offset by increased investment in research and development.</p>
</body>
</html>";
// Render directly to PDF/UA format
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Set additional metadata for accessibility
pdf.MetaData.Title = "Q4 2024 Financial Summary";
pdf.SaveAs("financial-report-accessible.pdf");
Console.WriteLine("Accessible PDF created successfully.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Quarterly Financial Report</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
h1 { color: #333; }
h2 { color: #555; margin-top: 20px; }
p { margin-bottom: 15px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
th { background-color: #f4f4f4; }
</style>
</head>
<body>
<h1>Q4 2024 Financial Summary</h1>
<p>This report provides an overview of financial performance for the fourth quarter.</p>
<h2>Revenue Highlights</h2>
<p>Total revenue increased by 12% compared to the previous quarter, driven primarily by expansion in the enterprise segment.</p>
<h2>Expense Analysis</h2>
<p>Operating expenses remained stable, with a slight reduction in administrative costs offset by increased investment in research and development.</p>
</body>
</html>"
' Render directly to PDF/UA format
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Set additional metadata for accessibility
pdf.MetaData.Title = "Q4 2024 Financial Summary"
pdf.SaveAs("financial-report-accessible.pdf")
Console.WriteLine("Accessible PDF created successfully.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Quarterly Financial Report</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
h1 { color: #333; }
h2 { color: #555; margin-top: 20px; }
p { margin-bottom: 15px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
th { background-color: #f4f4f4; }
</style>
</head>
<body>
<h1>Q4 2024 Financial Summary</h1>
<p>This report provides an overview of financial performance for the fourth quarter.</p>
<h2>Revenue Highlights</h2>
<p>Total revenue increased by 12% compared to the previous quarter, driven primarily by expansion in the enterprise segment.</p>
<h2>Expense Analysis</h2>
<p>Operating expenses remained stable, with a slight reduction in administrative costs offset by increased investment in research and development.</p>
</body>
</html>"
' Render directly to PDF/UA format
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Set additional metadata for accessibility
pdf.MetaData.Title = "Q4 2024 Financial Summary"
pdf.SaveAs("financial-report-accessible.pdf")
Console.WriteLine("Accessible PDF created successfully.")輸出 PDF
以上程式碼產生語意結構化的PDF/UA文件:
請注意,HTML 程式碼中包含 html 元素的 lang 屬性。 此屬性會傳遞到 PDF 檔案中,幫助螢幕閱讀器辨識文件語言。 語意 HTML 元素如 h1、h2 和 p 直接轉換為相應的 PDF 標記,創建協助技術可導航的邏輯文件結構。
為了 渲染 HTML 文件或 URLs 而非字串,IronPDF 提供了相應的方法。
以下代碼顯示了兩種方法:RenderHtmlFileAsPdf() 從本地文件路徑加載 HTML,而 RenderUrlAsPdf() 則從網頁 URL 獲取並渲染內容。 這兩種方法都會生成標準 PDF,然後使用 SaveAsPdfUA() 轉換為 PDF/UA 格式。 當您需要在進行輔助使用轉換之前套用額外的處理時,這種兩步驟法非常有效。
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render from an HTML file on disk
PdfDocument pdfFromFile = renderer.RenderHtmlFileAsPdf("report.html");
// Convert the rendered PDF to PDF/UA format
pdfFromFile.SaveAsPdfUA("report-accessible.pdf");
// Render from a web URL
PdfDocument pdfFromUrl = renderer.RenderUrlAsPdf("https://example.com");
// Convert to accessible format
pdfFromUrl.SaveAsPdfUA("webpage-accessible.pdf");using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render from an HTML file on disk
PdfDocument pdfFromFile = renderer.RenderHtmlFileAsPdf("report.html");
// Convert the rendered PDF to PDF/UA format
pdfFromFile.SaveAsPdfUA("report-accessible.pdf");
// Render from a web URL
PdfDocument pdfFromUrl = renderer.RenderUrlAsPdf("https://example.com");
// Convert to accessible format
pdfFromUrl.SaveAsPdfUA("webpage-accessible.pdf");Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Render from an HTML file on disk
Dim pdfFromFile As PdfDocument = renderer.RenderHtmlFileAsPdf("report.html")
' Convert the rendered PDF to PDF/UA format
pdfFromFile.SaveAsPdfUA("report-accessible.pdf")
' Render from a web URL
Dim pdfFromUrl As PdfDocument = renderer.RenderUrlAsPdf("https://example.com")
' Convert to accessible format
pdfFromUrl.SaveAsPdfUA("webpage-accessible.pdf")Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Render from an HTML file on disk
Dim pdfFromFile As PdfDocument = renderer.RenderHtmlFileAsPdf("report.html")
' Convert the rendered PDF to PDF/UA format
pdfFromFile.SaveAsPdfUA("report-accessible.pdf")
' Render from a web URL
Dim pdfFromUrl As PdfDocument = renderer.RenderUrlAsPdf("https://example.com")
' Convert to accessible format
pdfFromUrl.SaveAsPdfUA("webpage-accessible.pdf")如何設定文件元資料以符合無障礙存取要求?
PDF元資料在無障礙存取方面有多種用途。 輔助技術會播報文件屬性,例如標題和作者,以幫助使用者識別他們正在閱讀的內容。 搜尋引擎和文件管理系統使用元資料進行索引和檢索。 合規性驗證器會檢查所需的元資料欄位是否已填寫。
IronPDF 通過 PdfDocument 物件的MetaData 屬性公開中繼資料。 以下屬性與可訪問性最為相關。
輸入 PDF
此範例使用 enrollment-guide-draft.pdf,這是一個需要完整中繼資料以符合法規和管理的草案福利入職指南。
該代碼載入現有的PDF並配置所有關鍵元數據屬性:Title(由螢幕閱讀器宣布),Author(識別來源),Subject(簡介),Keywords(可搜索性),Creator(源應用程式),和日期戳記。 最後,SaveAsPdfUA() 匯出文檔,具有中繼資料和 PDF/UA 可及性結構。
using IronPdf;
using System;
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
// Set the document title - critical for accessibility
// Screen readers announce this when opening the document
pdf.MetaData.Title = "Employee Benefits Enrollment Guide 2024";
// Author information helps identify document source
pdf.MetaData.Author = "Human Resources Department";
// Subject provides a brief description
pdf.MetaData.Subject = "Guide to selecting and enrolling in employee benefit programs";
// Keywords improve searchability
pdf.MetaData.Keywords = "benefits, enrollment, health insurance, retirement, HR";
// Creator identifies the originating application
pdf.MetaData.Creator = "Benefits Portal v3.2";
// Set document dates
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
// Save as PDF/UA with complete metadata
pdf.SaveAsPdfUA("document-accessible.pdf");
Console.WriteLine("Document metadata configured for accessibility.");using IronPdf;
using System;
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
// Set the document title - critical for accessibility
// Screen readers announce this when opening the document
pdf.MetaData.Title = "Employee Benefits Enrollment Guide 2024";
// Author information helps identify document source
pdf.MetaData.Author = "Human Resources Department";
// Subject provides a brief description
pdf.MetaData.Subject = "Guide to selecting and enrolling in employee benefit programs";
// Keywords improve searchability
pdf.MetaData.Keywords = "benefits, enrollment, health insurance, retirement, HR";
// Creator identifies the originating application
pdf.MetaData.Creator = "Benefits Portal v3.2";
// Set document dates
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
// Save as PDF/UA with complete metadata
pdf.SaveAsPdfUA("document-accessible.pdf");
Console.WriteLine("Document metadata configured for accessibility.");Imports IronPdf
Imports System
Dim pdf As PdfDocument = PdfDocument.FromFile("document.pdf")
' Set the document title - critical for accessibility
' Screen readers announce this when opening the document
pdf.MetaData.Title = "Employee Benefits Enrollment Guide 2024"
' Author information helps identify document source
pdf.MetaData.Author = "Human Resources Department"
' Subject provides a brief description
pdf.MetaData.Subject = "Guide to selecting and enrolling in employee benefit programs"
' Keywords improve searchability
pdf.MetaData.Keywords = "benefits, enrollment, health insurance, retirement, HR"
' Creator identifies the originating application
pdf.MetaData.Creator = "Benefits Portal v3.2"
' Set document dates
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
' Save as PDF/UA with complete metadata
pdf.SaveAsPdfUA("document-accessible.pdf")
Console.WriteLine("Document metadata configured for accessibility.")Imports IronPdf
Imports System
Dim pdf As PdfDocument = PdfDocument.FromFile("document.pdf")
' Set the document title - critical for accessibility
' Screen readers announce this when opening the document
pdf.MetaData.Title = "Employee Benefits Enrollment Guide 2024"
' Author information helps identify document source
pdf.MetaData.Author = "Human Resources Department"
' Subject provides a brief description
pdf.MetaData.Subject = "Guide to selecting and enrolling in employee benefit programs"
' Keywords improve searchability
pdf.MetaData.Keywords = "benefits, enrollment, health insurance, retirement, HR"
' Creator identifies the originating application
pdf.MetaData.Creator = "Benefits Portal v3.2"
' Set document dates
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
' Save as PDF/UA with complete metadata
pdf.SaveAsPdfUA("document-accessible.pdf")
Console.WriteLine("Document metadata configured for accessibility.")注重 Title 屬性。 PDF 閱讀器可以在標題列和標籤頁中顯示檔案名稱或文件標題。 為了便於閱讀,應該顯示文件標題,因為它提供了有意義的上下文。 像「2024 年員工福利登記指南」這樣的標題遠比像「doc_final_v3_revised.pdf」這樣的檔案名稱更有用。
從 HTML 建立新的 PDF 時,可以在儲存之前設定元資料。
代碼使用 RenderHtmlAsPdfUA() 直接渲染 HTML 到 PDF/UA 格式,然後在結果的 PdfDocument 物件上配置完整的中繼資料屬性集,最後調用 SaveAs()。 這種方法將輔助功能結構和元資料嵌入到單一工作流程中,非常適合產生新的合規文件。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string html = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Policy Document</title></head>
<body>
<h1>Information Security Policy</h1>
<p>This document outlines security requirements for all employees.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(html);
// Configure comprehensive metadata
pdf.MetaData.Title = "Information Security Policy";
pdf.MetaData.Author = "IT Security Team";
pdf.MetaData.Subject = "Corporate security requirements and guidelines";
pdf.MetaData.Keywords = "security, policy, compliance, data protection";
pdf.MetaData.Creator = "Policy Management System";
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.SaveAs("security-policy-accessible.pdf");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string html = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Policy Document</title></head>
<body>
<h1>Information Security Policy</h1>
<p>This document outlines security requirements for all employees.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(html);
// Configure comprehensive metadata
pdf.MetaData.Title = "Information Security Policy";
pdf.MetaData.Author = "IT Security Team";
pdf.MetaData.Subject = "Corporate security requirements and guidelines";
pdf.MetaData.Keywords = "security, policy, compliance, data protection";
pdf.MetaData.Creator = "Policy Management System";
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.SaveAs("security-policy-accessible.pdf");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim html As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Policy Document</title></head>
<body>
<h1>Information Security Policy</h1>
<p>This document outlines security requirements for all employees.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(html)
' Configure comprehensive metadata
pdf.MetaData.Title = "Information Security Policy"
pdf.MetaData.Author = "IT Security Team"
pdf.MetaData.Subject = "Corporate security requirements and guidelines"
pdf.MetaData.Keywords = "security, policy, compliance, data protection"
pdf.MetaData.Creator = "Policy Management System"
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
pdf.SaveAs("security-policy-accessible.pdf")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim html As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Policy Document</title></head>
<body>
<h1>Information Security Policy</h1>
<p>This document outlines security requirements for all employees.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(html)
' Configure comprehensive metadata
pdf.MetaData.Title = "Information Security Policy"
pdf.MetaData.Author = "IT Security Team"
pdf.MetaData.Subject = "Corporate security requirements and guidelines"
pdf.MetaData.Keywords = "security, policy, compliance, data protection"
pdf.MetaData.Creator = "Policy Management System"
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
pdf.SaveAs("security-policy-accessible.pdf")如何為螢幕閱讀器指定文檔語言?
語言規範是一項基本的無障礙要求,它直接影響內容的語音表達方式。 當輔助科技遇到文字時,它會使用指定的語言來選擇合適的發音規則、語音和朗讀模式。 缺少語言規範的文檔會迫使軟體進行猜測,這通常會導致音訊輸出混亂或難以理解。
為了符合 PDF/UA 標準,文件必須聲明其主要語言。 IronPDF 處理 HTML 原來源的 lang 屬性,並在 PDF/UA 輸出中保留。
該程式碼演示了兩種語言使用場景。 首先渲染帶有 lang='en' 的英語 HTML 內容在 html 元素上,然後處理含 lang='es' 的西語內容。 RenderHtmlAsPdfUA() 方法保留了 HTML 的語言屬性,而 SaveAsPdfUA() 則在輸出中維持它。 這可確保螢幕閱讀器能針對文件的主要語言套用正確的發音規則。
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Annual Report</title></head>
<body>
<h1>Annual Report 2024</h1>
<p>This report summarizes organizational activities and financial performance.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Language is set via lang='en' in the HTML; SaveAsPdfUA preserves it
pdf.SaveAsPdfUA("annual-report.pdf");
string htmlContentEs = @"
<!DOCTYPE html>
<html lang='es'>
<head><title>Informe Anual</title></head>
<body>
<h1>Informe Anual 2024</h1>
<p>Este informe resume las actividades organizacionales y el desempeño financiero.</p>
</body>
</html>";
PdfDocument pdfEs = renderer.RenderHtmlAsPdfUA(htmlContentEs);
// Language is set via lang='es' in the HTML; SaveAsPdfUA preserves it
pdfEs.SaveAsPdfUA("informe-anual.pdf");using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Annual Report</title></head>
<body>
<h1>Annual Report 2024</h1>
<p>This report summarizes organizational activities and financial performance.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Language is set via lang='en' in the HTML; SaveAsPdfUA preserves it
pdf.SaveAsPdfUA("annual-report.pdf");
string htmlContentEs = @"
<!DOCTYPE html>
<html lang='es'>
<head><title>Informe Anual</title></head>
<body>
<h1>Informe Anual 2024</h1>
<p>Este informe resume las actividades organizacionales y el desempeño financiero.</p>
</body>
</html>";
PdfDocument pdfEs = renderer.RenderHtmlAsPdfUA(htmlContentEs);
// Language is set via lang='es' in the HTML; SaveAsPdfUA preserves it
pdfEs.SaveAsPdfUA("informe-anual.pdf");Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Annual Report</title></head>
<body>
<h1>Annual Report 2024</h1>
<p>This report summarizes organizational activities and financial performance.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Language is set via lang='en' in the HTML; SaveAsPdfUA preserves it
pdf.SaveAsPdfUA("annual-report.pdf")
Dim htmlContentEs As String = "
<!DOCTYPE html>
<html lang='es'>
<head><title>Informe Anual</title></head>
<body>
<h1>Informe Anual 2024</h1>
<p>Este informe resume las actividades organizacionales y el desempeño financiero.</p>
</body>
</html>"
Dim pdfEs As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContentEs)
' Language is set via lang='es' in the HTML; SaveAsPdfUA preserves it
pdfEs.SaveAsPdfUA("informe-anual.pdf")Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Annual Report</title></head>
<body>
<h1>Annual Report 2024</h1>
<p>This report summarizes organizational activities and financial performance.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Language is set via lang='en' in the HTML; SaveAsPdfUA preserves it
pdf.SaveAsPdfUA("annual-report.pdf")
Dim htmlContentEs As String = "
<!DOCTYPE html>
<html lang='es'>
<head><title>Informe Anual</title></head>
<body>
<h1>Informe Anual 2024</h1>
<p>Este informe resume las actividades organizacionales y el desempeño financiero.</p>
</body>
</html>"
Dim pdfEs As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContentEs)
' Language is set via lang='es' in the HTML; SaveAsPdfUA preserves it
pdfEs.SaveAsPdfUA("informe-anual.pdf")IronPDF 支持通過標準 HTML lang 屬性進行語言規範。 常見的語言代碼包括en(英文)、es(西班牙文)、fr(法文)、de(德文)、pt(葡萄牙文)、zh(中文)、ja(日文)、ko(韓文),和ar(阿拉伯文),以及許多其他語言。
對於包含多種語言的文檔,主要文檔語言應反映主要內容。 輔助技術可以較好地處理偶爾出現的外語短語,但對於包含多種語言的大量內容的文檔,則會帶來更複雜的挑戰,可能需要專門的方法。
如何從HTML建立可存取的標籤的PDF結構?
帶標籤的PDF結構是可訪問性的基礎。 標籤定義了內容的邏輯組織,區分標題和段落,識別清單和清單項,標記表格,並確定閱讀順序。 如果沒有正確的標籤,輔助技術就無法向使用者傳達文件結構。
使用 IronPDF 建立具有良好標籤的 PDF 的最有效方法是從語義化的 HTML 開始。 Chromium 渲染引擎在轉換為 PDF 時保留 HTML 結構,將 HTML 元素翻譯為相應的 PDF 標記。 編寫良好的HTML程式碼會自動產生結構良好的PDF檔案。
請看下面的範例,它演示了正確的語義標記。
該代碼建立了一個HTML文件,擁有清晰的標題層次結構(h1作為主標題,h2作為章節,h3作為小節),使用無序清單(ul/li)來顯示項目符號,並使用有序清單(ol/li)來顯示編號序列。 RenderHtmlAsPdfUA() 方法將這些語意元素轉換為可由協助技術導航的相應 PDF 標記。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Project Proposal</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { font-size: 28px; border-bottom: 2px solid #333; padding-bottom: 10px; }
h2 { font-size: 22px; color: #444; margin-top: 30px; }
h3 { font-size: 18px; color: #666; }
ul, ol { margin-left: 20px; }
li { margin-bottom: 8px; }
</style>
</head>
<body>
<h1>Website Redesign Proposal</h1>
<h2>Executive Summary</h2>
<p>This proposal outlines a comprehensive redesign of the corporate website to improve user experience, accessibility, and conversion rates.</p>
<h2>Project Objectives</h2>
<p>The redesign aims to achieve several key goals:</p>
<ul>
<li>Improve mobile responsiveness across all device types</li>
<li>Achieve WCAG 2.1 Level AA compliance for accessibility</li>
<li>Reduce page load times by 40 percent</li>
<li>Increase conversion rates through improved user flows</li>
</ul>
<h2>Implementation Timeline</h2>
<p>The project will proceed in three phases:</p>
<ol>
<li>Discovery and planning: weeks one through four</li>
<li>Design and development: weeks five through twelve</li>
<li>Testing and launch: weeks thirteen through sixteen</li>
</ol>
<h3>Phase One Details</h3>
<p>The discovery phase includes stakeholder interviews, competitive analysis, and technical assessment of the current platform.</p>
<h3>Phase Two Details</h3>
<p>Design and development will follow an agile methodology with two-week sprints and regular stakeholder reviews.</p>
<h2>Budget Considerations</h2>
<p>The proposed budget covers all aspects of the redesign including design, development, content migration, and quality assurance testing.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Website Redesign Proposal";
pdf.MetaData.Author = "Digital Strategy Team";
pdf.SaveAs("proposal-accessible.pdf");
Console.WriteLine("Structured document created with proper heading hierarchy.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Project Proposal</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { font-size: 28px; border-bottom: 2px solid #333; padding-bottom: 10px; }
h2 { font-size: 22px; color: #444; margin-top: 30px; }
h3 { font-size: 18px; color: #666; }
ul, ol { margin-left: 20px; }
li { margin-bottom: 8px; }
</style>
</head>
<body>
<h1>Website Redesign Proposal</h1>
<h2>Executive Summary</h2>
<p>This proposal outlines a comprehensive redesign of the corporate website to improve user experience, accessibility, and conversion rates.</p>
<h2>Project Objectives</h2>
<p>The redesign aims to achieve several key goals:</p>
<ul>
<li>Improve mobile responsiveness across all device types</li>
<li>Achieve WCAG 2.1 Level AA compliance for accessibility</li>
<li>Reduce page load times by 40 percent</li>
<li>Increase conversion rates through improved user flows</li>
</ul>
<h2>Implementation Timeline</h2>
<p>The project will proceed in three phases:</p>
<ol>
<li>Discovery and planning: weeks one through four</li>
<li>Design and development: weeks five through twelve</li>
<li>Testing and launch: weeks thirteen through sixteen</li>
</ol>
<h3>Phase One Details</h3>
<p>The discovery phase includes stakeholder interviews, competitive analysis, and technical assessment of the current platform.</p>
<h3>Phase Two Details</h3>
<p>Design and development will follow an agile methodology with two-week sprints and regular stakeholder reviews.</p>
<h2>Budget Considerations</h2>
<p>The proposed budget covers all aspects of the redesign including design, development, content migration, and quality assurance testing.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Website Redesign Proposal";
pdf.MetaData.Author = "Digital Strategy Team";
pdf.SaveAs("proposal-accessible.pdf");
Console.WriteLine("Structured document created with proper heading hierarchy.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Project Proposal</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { font-size: 28px; border-bottom: 2px solid #333; padding-bottom: 10px; }
h2 { font-size: 22px; color: #444; margin-top: 30px; }
h3 { font-size: 18px; color: #666; }
ul, ol { margin-left: 20px; }
li { margin-bottom: 8px; }
</style>
</head>
<body>
<h1>Website Redesign Proposal</h1>
<h2>Executive Summary</h2>
<p>This proposal outlines a comprehensive redesign of the corporate website to improve user experience, accessibility, and conversion rates.</p>
<h2>Project Objectives</h2>
<p>The redesign aims to achieve several key goals:</p>
<ul>
<li>Improve mobile responsiveness across all device types</li>
<li>Achieve WCAG 2.1 Level AA compliance for accessibility</li>
<li>Reduce page load times by 40 percent</li>
<li>Increase conversion rates through improved user flows</li>
</ul>
<h2>Implementation Timeline</h2>
<p>The project will proceed in three phases:</p>
<ol>
<li>Discovery and planning: weeks one through four</li>
<li>Design and development: weeks five through twelve</li>
<li>Testing and launch: weeks thirteen through sixteen</li>
</ol>
<h3>Phase One Details</h3>
<p>The discovery phase includes stakeholder interviews, competitive analysis, and technical assessment of the current platform.</p>
<h3>Phase Two Details</h3>
<p>Design and development will follow an agile methodology with two-week sprints and regular stakeholder reviews.</p>
<h2>Budget Considerations</h2>
<p>The proposed budget covers all aspects of the redesign including design, development, content migration, and quality assurance testing.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Website Redesign Proposal"
pdf.MetaData.Author = "Digital Strategy Team"
pdf.SaveAs("proposal-accessible.pdf")
Console.WriteLine("Structured document created with proper heading hierarchy.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Project Proposal</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { font-size: 28px; border-bottom: 2px solid #333; padding-bottom: 10px; }
h2 { font-size: 22px; color: #444; margin-top: 30px; }
h3 { font-size: 18px; color: #666; }
ul, ol { margin-left: 20px; }
li { margin-bottom: 8px; }
</style>
</head>
<body>
<h1>Website Redesign Proposal</h1>
<h2>Executive Summary</h2>
<p>This proposal outlines a comprehensive redesign of the corporate website to improve user experience, accessibility, and conversion rates.</p>
<h2>Project Objectives</h2>
<p>The redesign aims to achieve several key goals:</p>
<ul>
<li>Improve mobile responsiveness across all device types</li>
<li>Achieve WCAG 2.1 Level AA compliance for accessibility</li>
<li>Reduce page load times by 40 percent</li>
<li>Increase conversion rates through improved user flows</li>
</ul>
<h2>Implementation Timeline</h2>
<p>The project will proceed in three phases:</p>
<ol>
<li>Discovery and planning: weeks one through four</li>
<li>Design and development: weeks five through twelve</li>
<li>Testing and launch: weeks thirteen through sixteen</li>
</ol>
<h3>Phase One Details</h3>
<p>The discovery phase includes stakeholder interviews, competitive analysis, and technical assessment of the current platform.</p>
<h3>Phase Two Details</h3>
<p>Design and development will follow an agile methodology with two-week sprints and regular stakeholder reviews.</p>
<h2>Budget Considerations</h2>
<p>The proposed budget covers all aspects of the redesign including design, development, content migration, and quality assurance testing.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Website Redesign Proposal"
pdf.MetaData.Author = "Digital Strategy Team"
pdf.SaveAs("proposal-accessible.pdf")
Console.WriteLine("Structured document created with proper heading hierarchy.")輸出 PDF
此PDF檔案保留了用於導航的標題層級和清單結構:
請注意本例中的標題層級結構。 該文件只有一個 h1 標題,其後是 h2 元素(主要章節),以及 h3 元素(子章節)。 這種層級結構對於無障礙存取至關重要。 輔助技術使用者通常會透過在標題之間跳轉來瀏覽文檔,因此邏輯結構能夠讓他們快速找到所需的內容。
列表採用語意處理,其中 ul 表示無序列表,ol 表示有序列表。 PDF 中的每個 li 元素都會變成一個標籤的列表項目。 輔助技術透過顯示清單包含的項目數量,然後依序朗讀每個項目來播報清單。
如何為圖片添加替代文字以使其與螢幕閱讀器相容?
圖片在可訪問性方面存在根本性的挑戰。 視覺內容無法被盲人或低視力使用者感知。 替代文字(通常稱為 alt 文字)提供可以取代圖像顯示的文字描述。
從 HTML 產生 PDF 時,img 元素的 alt 屬性會作為替代文字傳遞到 PDF 中。
此程式碼產生一份包含兩張圖表的銷售報告。 每個 img 元素包含的 alt 屬性詳細描述了圖表的數據,而不僅僅是其類型。 例如,替代文字會具體說明實際銷售資料和區域比較。 RenderHtmlAsPdfUA() 方法將這些描述嵌入為 PDF 的替代文字,使屏幕閱讀器能夠傳達視覺用戶從觀察圖表中獲得的相同見解。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Sales Performance Report</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.chart-container { margin: 20px 0; text-align: center; }
img { max-width: 100%; height: auto; }
.caption { font-style: italic; color: #666; margin-top: 10px; }
</style>
</head>
<body>
<h1>Q3 Sales Performance Report</h1>
<h2>Regional Sales Comparison</h2>
<p>The following chart illustrates sales performance across regions for the third quarter.</p>
<div class='chart-container'>
<img src='https://example.com/charts/regional-sales-q3.png'
alt='Bar chart comparing Q3 sales across four regions: Northeast at 2.4 million dollars, Southeast at 1.8 million dollars, Midwest at 2.1 million dollars, and West at 3.2 million dollars. The West region shows the highest performance with a 15 percent increase from Q2.'
width='600' height='400'>
<p class='caption'>Figure 1: Regional Sales Comparison Q3 2024</p>
</div>
<h2>Monthly Trend Analysis</h2>
<p>Sales showed consistent growth throughout the quarter with acceleration in September.</p>
<div class='chart-container'>
<img src='https://example.com/charts/monthly-trend.png'
alt='Line graph showing monthly sales from July through September. July sales were 2.1 million dollars, August increased to 2.4 million dollars, and September reached 2.9 million dollars, representing a 38 percent total increase over the quarter.'
width='600' height='300'>
<p class='caption'>Figure 2: Monthly Sales Trend Q3 2024</p>
</div>
<h2>Key Findings</h2>
<p>Analysis indicates strong momentum heading into Q4, particularly in the Western region where new product launches drove significant customer acquisition.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Q3 Sales Performance Report";
pdf.MetaData.Author = "Sales Analytics Team";
pdf.SaveAs("sales-report-accessible.pdf");
Console.WriteLine("Report created with accessible image descriptions.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Sales Performance Report</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.chart-container { margin: 20px 0; text-align: center; }
img { max-width: 100%; height: auto; }
.caption { font-style: italic; color: #666; margin-top: 10px; }
</style>
</head>
<body>
<h1>Q3 Sales Performance Report</h1>
<h2>Regional Sales Comparison</h2>
<p>The following chart illustrates sales performance across regions for the third quarter.</p>
<div class='chart-container'>
<img src='https://example.com/charts/regional-sales-q3.png'
alt='Bar chart comparing Q3 sales across four regions: Northeast at 2.4 million dollars, Southeast at 1.8 million dollars, Midwest at 2.1 million dollars, and West at 3.2 million dollars. The West region shows the highest performance with a 15 percent increase from Q2.'
width='600' height='400'>
<p class='caption'>Figure 1: Regional Sales Comparison Q3 2024</p>
</div>
<h2>Monthly Trend Analysis</h2>
<p>Sales showed consistent growth throughout the quarter with acceleration in September.</p>
<div class='chart-container'>
<img src='https://example.com/charts/monthly-trend.png'
alt='Line graph showing monthly sales from July through September. July sales were 2.1 million dollars, August increased to 2.4 million dollars, and September reached 2.9 million dollars, representing a 38 percent total increase over the quarter.'
width='600' height='300'>
<p class='caption'>Figure 2: Monthly Sales Trend Q3 2024</p>
</div>
<h2>Key Findings</h2>
<p>Analysis indicates strong momentum heading into Q4, particularly in the Western region where new product launches drove significant customer acquisition.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Q3 Sales Performance Report";
pdf.MetaData.Author = "Sales Analytics Team";
pdf.SaveAs("sales-report-accessible.pdf");
Console.WriteLine("Report created with accessible image descriptions.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Sales Performance Report</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.chart-container { margin: 20px 0; text-align: center; }
img { max-width: 100%; height: auto; }
.caption { font-style: italic; color: #666; margin-top: 10px; }
</style>
</head>
<body>
<h1>Q3 Sales Performance Report</h1>
<h2>Regional Sales Comparison</h2>
<p>The following chart illustrates sales performance across regions for the third quarter.</p>
<div class='chart-container'>
<img src='https://example.com/charts/regional-sales-q3.png'
alt='Bar chart comparing Q3 sales across four regions: Northeast at 2.4 million dollars, Southeast at 1.8 million dollars, Midwest at 2.1 million dollars, and West at 3.2 million dollars. The West region shows the highest performance with a 15 percent increase from Q2.'
width='600' height='400'>
<p class='caption'>Figure 1: Regional Sales Comparison Q3 2024</p>
</div>
<h2>Monthly Trend Analysis</h2>
<p>Sales showed consistent growth throughout the quarter with acceleration in September.</p>
<div class='chart-container'>
<img src='https://example.com/charts/monthly-trend.png'
alt='Line graph showing monthly sales from July through September. July sales were 2.1 million dollars, August increased to 2.4 million dollars, and September reached 2.9 million dollars, representing a 38 percent total increase over the quarter.'
width='600' height='300'>
<p class='caption'>Figure 2: Monthly Sales Trend Q3 2024</p>
</div>
<h2>Key Findings</h2>
<p>Analysis indicates strong momentum heading into Q4, particularly in the Western region where new product launches drove significant customer acquisition.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Q3 Sales Performance Report"
pdf.MetaData.Author = "Sales Analytics Team"
pdf.SaveAs("sales-report-accessible.pdf")
Console.WriteLine("Report created with accessible image descriptions.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Sales Performance Report</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.chart-container { margin: 20px 0; text-align: center; }
img { max-width: 100%; height: auto; }
.caption { font-style: italic; color: #666; margin-top: 10px; }
</style>
</head>
<body>
<h1>Q3 Sales Performance Report</h1>
<h2>Regional Sales Comparison</h2>
<p>The following chart illustrates sales performance across regions for the third quarter.</p>
<div class='chart-container'>
<img src='https://example.com/charts/regional-sales-q3.png'
alt='Bar chart comparing Q3 sales across four regions: Northeast at 2.4 million dollars, Southeast at 1.8 million dollars, Midwest at 2.1 million dollars, and West at 3.2 million dollars. The West region shows the highest performance with a 15 percent increase from Q2.'
width='600' height='400'>
<p class='caption'>Figure 1: Regional Sales Comparison Q3 2024</p>
</div>
<h2>Monthly Trend Analysis</h2>
<p>Sales showed consistent growth throughout the quarter with acceleration in September.</p>
<div class='chart-container'>
<img src='https://example.com/charts/monthly-trend.png'
alt='Line graph showing monthly sales from July through September. July sales were 2.1 million dollars, August increased to 2.4 million dollars, and September reached 2.9 million dollars, representing a 38 percent total increase over the quarter.'
width='600' height='300'>
<p class='caption'>Figure 2: Monthly Sales Trend Q3 2024</p>
</div>
<h2>Key Findings</h2>
<p>Analysis indicates strong momentum heading into Q4, particularly in the Western region where new product launches drove significant customer acquisition.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Q3 Sales Performance Report"
pdf.MetaData.Author = "Sales Analytics Team"
pdf.SaveAs("sales-report-accessible.pdf")
Console.WriteLine("Report created with accessible image descriptions.")撰寫有效的替代文字需要了解圖像所傳達的訊息。 對於圖表,替代文字應該描述所呈現的資料,而不僅僅是說明存在圖表。 僅僅說「柱狀圖」並不能提供任何有用的信息。 描述「第三季四個地區的銷售額對比長條圖,其中西部地區以 320 萬美元領先」可以讓視力障礙用戶獲得與視力正常用戶查看圖表時相同的洞察力。
不具備任何資訊功能的裝飾性圖片,其 alt 屬性應為空。 這會向螢幕閱讀器發出信號,表明可以跳過該圖像:
<img src="decorative-border.png" alt="">
上述方法依賴於控制 HTML。 舊版文件、已掃描報告和其他工具生成的文件作為包含圖像但無描述的 PDF。 SetImageAltText 處理該案例,獲得以零為基準的頁面索引、以零為基準的圖像索引和描述:
PdfDocument pdf = PdfDocument.FromFile("report.pdf");
pdf.SetImageAltText(0, 0, "Bar chart comparing Q3 sales across four regions, with West leading at 3.2 million dollars");
pdf.SaveAsPdfUA("report-accessible.pdf");PdfDocument pdf = PdfDocument.FromFile("report.pdf");
pdf.SetImageAltText(0, 0, "Bar chart comparing Q3 sales across four regions, with West leading at 3.2 million dollars");
pdf.SaveAsPdfUA("report-accessible.pdf");Dim pdf As PdfDocument = PdfDocument.FromFile("report.pdf")
pdf.SetImageAltText(0, 0, "Bar chart comparing Q3 sales across four regions, with West leading at 3.2 million dollars")
pdf.SaveAsPdfUA("report-accessible.pdf")Dim pdf As PdfDocument = PdfDocument.FromFile("report.pdf")
pdf.SetImageAltText(0, 0, "Bar chart comparing Q3 sales across four regions, with West leading at 3.2 million dollars")
pdf.SaveAsPdfUA("report-accessible.pdf")首相附加描述,然後再轉換,因為轉換會生產符合標準的文檔並保留您所附加的東西。 PDF/UA 指南涉及找到圖像索引、鏈接多個呼叫和參數規則。
對於 Section 508 目的而言,明確說明這能達到的限制:它描述圖像,而不是其周圍的頁面。 現有頁面文本未受影響,而已掃描的文件仍需 OCR 才能使其文本可供大聲閱讀。
如何在PDF文件中建立無障礙表格?
表格由於以二維方式編碼資料之間的關係,因此在可訪問性方面存在複雜的問題。 視力正常的使用者可以透過視覺掃描行和列來了解單元格與其標題之間的關係。 使用輔助技術的使用者需要透過正確的標記明確定義這種關係。
HTML 提供了實現無障礙表格所需的結構元素。 關鍵元素包括用於標題單元格的 th、用於資料單元格的 td,以及用於明確標題是套用於行還是列的範圍屬性。
代碼創建了一個包含正確可及性標記的員工目錄表。caption 元素提供在內容之前宣布的表標題。 標題單元使用 th 和 scope="col" 表示它們適用於欄位中的所有單元。 thead 和 tbody 元素分隔結構部分。 IronPDF 的 RenderHtmlAsPdfUA() 在 PDF 結構中保持了這些關係,使屏幕閱讀器能夠將數據單元與其列標頭關聯。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Directory</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ccc; padding: 12px; text-align: left; }
th { background-color: #f0f0f0; font-weight: bold; }
caption { font-size: 18px; font-weight: bold; margin-bottom: 10px; text-align: left; }
</style>
</head>
<body>
<h1>Department Staff Directory</h1>
<p>Contact information for all department personnel as of January 2024.</p>
<table>
<caption>Engineering Department Staff</caption>
<thead>
<tr>
<th scope='col'>Name</th>
<th scope='col'>Title</th>
<th scope='col'>Email</th>
<th scope='col'>Extension</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sarah Chen</td>
<td>Senior Software Engineer</td>
<td>schen@company.com</td>
<td>4521</td>
</tr>
<tr>
<td>Marcus Williams</td>
<td>DevOps Engineer</td>
<td>mwilliams@company.com</td>
<td>4522</td>
</tr>
<tr>
<td>Jennifer Park</td>
<td>QA Lead</td>
<td>jpark@company.com</td>
<td>4523</td>
</tr>
<tr>
<td>Robert Gonzalez</td>
<td>Technical Writer</td>
<td>rgonzalez@company.com</td>
<td>4524</td>
</tr>
</tbody>
</table>
<h2>Contact Guidelines</h2>
<p>Please use email for non-urgent matters. Phone extensions connect to voicemail outside business hours.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Department Staff Directory";
pdf.SaveAs("directory-accessible.pdf");
Console.WriteLine("Directory created with accessible table structure.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Directory</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ccc; padding: 12px; text-align: left; }
th { background-color: #f0f0f0; font-weight: bold; }
caption { font-size: 18px; font-weight: bold; margin-bottom: 10px; text-align: left; }
</style>
</head>
<body>
<h1>Department Staff Directory</h1>
<p>Contact information for all department personnel as of January 2024.</p>
<table>
<caption>Engineering Department Staff</caption>
<thead>
<tr>
<th scope='col'>Name</th>
<th scope='col'>Title</th>
<th scope='col'>Email</th>
<th scope='col'>Extension</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sarah Chen</td>
<td>Senior Software Engineer</td>
<td>schen@company.com</td>
<td>4521</td>
</tr>
<tr>
<td>Marcus Williams</td>
<td>DevOps Engineer</td>
<td>mwilliams@company.com</td>
<td>4522</td>
</tr>
<tr>
<td>Jennifer Park</td>
<td>QA Lead</td>
<td>jpark@company.com</td>
<td>4523</td>
</tr>
<tr>
<td>Robert Gonzalez</td>
<td>Technical Writer</td>
<td>rgonzalez@company.com</td>
<td>4524</td>
</tr>
</tbody>
</table>
<h2>Contact Guidelines</h2>
<p>Please use email for non-urgent matters. Phone extensions connect to voicemail outside business hours.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Department Staff Directory";
pdf.SaveAs("directory-accessible.pdf");
Console.WriteLine("Directory created with accessible table structure.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Directory</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ccc; padding: 12px; text-align: left; }
th { background-color: #f0f0f0; font-weight: bold; }
caption { font-size: 18px; font-weight: bold; margin-bottom: 10px; text-align: left; }
</style>
</head>
<body>
<h1>Department Staff Directory</h1>
<p>Contact information for all department personnel as of January 2024.</p>
<table>
<caption>Engineering Department Staff</caption>
<thead>
<tr>
<th scope='col'>Name</th>
<th scope='col'>Title</th>
<th scope='col'>Email</th>
<th scope='col'>Extension</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sarah Chen</td>
<td>Senior Software Engineer</td>
<td>schen@company.com</td>
<td>4521</td>
</tr>
<tr>
<td>Marcus Williams</td>
<td>DevOps Engineer</td>
<td>mwilliams@company.com</td>
<td>4522</td>
</tr>
<tr>
<td>Jennifer Park</td>
<td>QA Lead</td>
<td>jpark@company.com</td>
<td>4523</td>
</tr>
<tr>
<td>Robert Gonzalez</td>
<td>Technical Writer</td>
<td>rgonzalez@company.com</td>
<td>4524</td>
</tr>
</tbody>
</table>
<h2>Contact Guidelines</h2>
<p>Please use email for non-urgent matters. Phone extensions connect to voicemail outside business hours.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Department Staff Directory"
pdf.SaveAs("directory-accessible.pdf")
Console.WriteLine("Directory created with accessible table structure.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Directory</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; }
th, td { border: 1px solid #ccc; padding: 12px; text-align: left; }
th { background-color: #f0f0f0; font-weight: bold; }
caption { font-size: 18px; font-weight: bold; margin-bottom: 10px; text-align: left; }
</style>
</head>
<body>
<h1>Department Staff Directory</h1>
<p>Contact information for all department personnel as of January 2024.</p>
<table>
<caption>Engineering Department Staff</caption>
<thead>
<tr>
<th scope='col'>Name</th>
<th scope='col'>Title</th>
<th scope='col'>Email</th>
<th scope='col'>Extension</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sarah Chen</td>
<td>Senior Software Engineer</td>
<td>schen@company.com</td>
<td>4521</td>
</tr>
<tr>
<td>Marcus Williams</td>
<td>DevOps Engineer</td>
<td>mwilliams@company.com</td>
<td>4522</td>
</tr>
<tr>
<td>Jennifer Park</td>
<td>QA Lead</td>
<td>jpark@company.com</td>
<td>4523</td>
</tr>
<tr>
<td>Robert Gonzalez</td>
<td>Technical Writer</td>
<td>rgonzalez@company.com</td>
<td>4524</td>
</tr>
</tbody>
</table>
<h2>Contact Guidelines</h2>
<p>Please use email for non-urgent matters. Phone extensions connect to voicemail outside business hours.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Department Staff Directory"
pdf.SaveAs("directory-accessible.pdf")
Console.WriteLine("Directory created with accessible table structure.")輸出 PDF
輸出結果包含一個結構正確的表格,表格中包含表頭關聯資訊:
th 元素的 scope 屬性至關重要。 設定 scope="col" 表示標題套用於該列中的所有儲存格。 對於每行第一個儲存格用作行標題的表格,您應該使用 scope="row" 來代替。 包含行標題和列標題的複雜表格需要同時具有這兩個屬性。
caption 元素為表格提供標題,該標題會在閱讀表格內容之前顯示。 這能讓用戶了解他們即將聽到的資料的背景資訊。
對於合併儲存格或結構不規則的表格,可以使用標題和 ID 等附加屬性將資料儲存格與其對應的標題明確連接。 但是,從可訪問性的角度來看,具有一致行和列的簡單表格結構是更可取的。
如何為文件添加書籤和導航以增強其可訪問性?
書籤提供導航地標,幫助所有使用者瀏覽冗長的文檔,但對於輔助功能而言尤其有價值。 無法透過視覺瀏覽頁面的使用者依靠書籤來尋找感興趣的部分。這些結構化的概要可以讓使用者直接跳到特定內容。
IronPDF 支援以程式方式創建分層書籤結構。
代碼渲染了一本包含多章的員工手冊,然後使用 Bookmarks 集合程式添加書籤層次結構。 頂層書籤指向透過 AddBookMarkAtEnd() 的章節開始頁,使用頁面索引。 父層的 Children 屬性添加的小節書籤,創建了一個嵌套的導航樹。 頁面索引參數從零開始,因此第 0 頁是第一頁。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Handbook</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; padding: 40px; }
h1 { page-break-before: always; }
h1:first-of-type { page-break-before: avoid; }
h2 { margin-top: 30px; }
</style>
</head>
<body>
<h1>Employee Handbook</h1>
<p>Welcome to our organization. This handbook contains policies and procedures for all employees.</p>
<h1>Chapter 1: Employment Policies</h1>
<h2>Equal Opportunity</h2>
<p>Our organization is committed to providing equal employment opportunities to all applicants and employees.</p>
<h2>At-Will Employment</h2>
<p>Employment with the organization is at-will unless otherwise specified in a written agreement.</p>
<h1>Chapter 2: Compensation and Benefits</h1>
<h2>Pay Periods</h2>
<p>Employees are paid on a bi-weekly basis, with pay dates falling on alternating Fridays.</p>
<h2>Health Insurance</h2>
<p>Full-time employees are eligible for health insurance coverage beginning the first of the month following hire date.</p>
<h2>Retirement Plans</h2>
<p>The organization offers a 401(k) plan with employer matching contributions up to four percent of salary.</p>
<h1>Chapter 3: Time Off Policies</h1>
<h2>Vacation</h2>
<p>Employees accrue vacation time based on length of service, starting at two weeks annually.</p>
<h2>Sick Leave</h2>
<p>Employees receive five days of paid sick leave per calendar year.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Add top-level bookmarks for main sections
var introBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Introduction", 0);
var chapter1Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 1: Employment Policies", 1);
chapter1Bookmark.Children.AddBookMarkAtEnd("Equal Opportunity", 1);
chapter1Bookmark.Children.AddBookMarkAtEnd("At-Will Employment", 1);
var chapter2Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 2: Compensation and Benefits", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Pay Periods", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Health Insurance", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Retirement Plans", 2);
var chapter3Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 3: Time Off Policies", 3);
chapter3Bookmark.Children.AddBookMarkAtEnd("Vacation", 3);
chapter3Bookmark.Children.AddBookMarkAtEnd("Sick Leave", 3);
pdf.MetaData.Title = "Employee Handbook";
pdf.MetaData.Author = "Human Resources";
pdf.SaveAs("handbook-with-bookmarks.pdf");
Console.WriteLine("Handbook created with navigational bookmarks.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Handbook</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; padding: 40px; }
h1 { page-break-before: always; }
h1:first-of-type { page-break-before: avoid; }
h2 { margin-top: 30px; }
</style>
</head>
<body>
<h1>Employee Handbook</h1>
<p>Welcome to our organization. This handbook contains policies and procedures for all employees.</p>
<h1>Chapter 1: Employment Policies</h1>
<h2>Equal Opportunity</h2>
<p>Our organization is committed to providing equal employment opportunities to all applicants and employees.</p>
<h2>At-Will Employment</h2>
<p>Employment with the organization is at-will unless otherwise specified in a written agreement.</p>
<h1>Chapter 2: Compensation and Benefits</h1>
<h2>Pay Periods</h2>
<p>Employees are paid on a bi-weekly basis, with pay dates falling on alternating Fridays.</p>
<h2>Health Insurance</h2>
<p>Full-time employees are eligible for health insurance coverage beginning the first of the month following hire date.</p>
<h2>Retirement Plans</h2>
<p>The organization offers a 401(k) plan with employer matching contributions up to four percent of salary.</p>
<h1>Chapter 3: Time Off Policies</h1>
<h2>Vacation</h2>
<p>Employees accrue vacation time based on length of service, starting at two weeks annually.</p>
<h2>Sick Leave</h2>
<p>Employees receive five days of paid sick leave per calendar year.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
// Add top-level bookmarks for main sections
var introBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Introduction", 0);
var chapter1Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 1: Employment Policies", 1);
chapter1Bookmark.Children.AddBookMarkAtEnd("Equal Opportunity", 1);
chapter1Bookmark.Children.AddBookMarkAtEnd("At-Will Employment", 1);
var chapter2Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 2: Compensation and Benefits", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Pay Periods", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Health Insurance", 2);
chapter2Bookmark.Children.AddBookMarkAtEnd("Retirement Plans", 2);
var chapter3Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 3: Time Off Policies", 3);
chapter3Bookmark.Children.AddBookMarkAtEnd("Vacation", 3);
chapter3Bookmark.Children.AddBookMarkAtEnd("Sick Leave", 3);
pdf.MetaData.Title = "Employee Handbook";
pdf.MetaData.Author = "Human Resources";
pdf.SaveAs("handbook-with-bookmarks.pdf");
Console.WriteLine("Handbook created with navigational bookmarks.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Handbook</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; padding: 40px; }
h1 { page-break-before: always; }
h1:first-of-type { page-break-before: avoid; }
h2 { margin-top: 30px; }
</style>
</head>
<body>
<h1>Employee Handbook</h1>
<p>Welcome to our organization. This handbook contains policies and procedures for all employees.</p>
<h1>Chapter 1: Employment Policies</h1>
<h2>Equal Opportunity</h2>
<p>Our organization is committed to providing equal employment opportunities to all applicants and employees.</p>
<h2>At-Will Employment</h2>
<p>Employment with the organization is at-will unless otherwise specified in a written agreement.</p>
<h1>Chapter 2: Compensation and Benefits</h1>
<h2>Pay Periods</h2>
<p>Employees are paid on a bi-weekly basis, with pay dates falling on alternating Fridays.</p>
<h2>Health Insurance</h2>
<p>Full-time employees are eligible for health insurance coverage beginning the first of the month following hire date.</p>
<h2>Retirement Plans</h2>
<p>The organization offers a 401(k) plan with employer matching contributions up to four percent of salary.</p>
<h1>Chapter 3: Time Off Policies</h1>
<h2>Vacation</h2>
<p>Employees accrue vacation time based on length of service, starting at two weeks annually.</p>
<h2>Sick Leave</h2>
<p>Employees receive five days of paid sick leave per calendar year.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Add top-level bookmarks for main sections
Dim introBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Introduction", 0)
Dim chapter1Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 1: Employment Policies", 1)
chapter1Bookmark.Children.AddBookMarkAtEnd("Equal Opportunity", 1)
chapter1Bookmark.Children.AddBookMarkAtEnd("At-Will Employment", 1)
Dim chapter2Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 2: Compensation and Benefits", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Pay Periods", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Health Insurance", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Retirement Plans", 2)
Dim chapter3Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 3: Time Off Policies", 3)
chapter3Bookmark.Children.AddBookMarkAtEnd("Vacation", 3)
chapter3Bookmark.Children.AddBookMarkAtEnd("Sick Leave", 3)
pdf.MetaData.Title = "Employee Handbook"
pdf.MetaData.Author = "Human Resources"
pdf.SaveAs("handbook-with-bookmarks.pdf")
Console.WriteLine("Handbook created with navigational bookmarks.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Employee Handbook</title>
<style>
body { font-family: Georgia, serif; line-height: 1.8; padding: 40px; }
h1 { page-break-before: always; }
h1:first-of-type { page-break-before: avoid; }
h2 { margin-top: 30px; }
</style>
</head>
<body>
<h1>Employee Handbook</h1>
<p>Welcome to our organization. This handbook contains policies and procedures for all employees.</p>
<h1>Chapter 1: Employment Policies</h1>
<h2>Equal Opportunity</h2>
<p>Our organization is committed to providing equal employment opportunities to all applicants and employees.</p>
<h2>At-Will Employment</h2>
<p>Employment with the organization is at-will unless otherwise specified in a written agreement.</p>
<h1>Chapter 2: Compensation and Benefits</h1>
<h2>Pay Periods</h2>
<p>Employees are paid on a bi-weekly basis, with pay dates falling on alternating Fridays.</p>
<h2>Health Insurance</h2>
<p>Full-time employees are eligible for health insurance coverage beginning the first of the month following hire date.</p>
<h2>Retirement Plans</h2>
<p>The organization offers a 401(k) plan with employer matching contributions up to four percent of salary.</p>
<h1>Chapter 3: Time Off Policies</h1>
<h2>Vacation</h2>
<p>Employees accrue vacation time based on length of service, starting at two weeks annually.</p>
<h2>Sick Leave</h2>
<p>Employees receive five days of paid sick leave per calendar year.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
' Add top-level bookmarks for main sections
Dim introBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Introduction", 0)
Dim chapter1Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 1: Employment Policies", 1)
chapter1Bookmark.Children.AddBookMarkAtEnd("Equal Opportunity", 1)
chapter1Bookmark.Children.AddBookMarkAtEnd("At-Will Employment", 1)
Dim chapter2Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 2: Compensation and Benefits", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Pay Periods", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Health Insurance", 2)
chapter2Bookmark.Children.AddBookMarkAtEnd("Retirement Plans", 2)
Dim chapter3Bookmark = pdf.Bookmarks.AddBookMarkAtEnd("Chapter 3: Time Off Policies", 3)
chapter3Bookmark.Children.AddBookMarkAtEnd("Vacation", 3)
chapter3Bookmark.Children.AddBookMarkAtEnd("Sick Leave", 3)
pdf.MetaData.Title = "Employee Handbook"
pdf.MetaData.Author = "Human Resources"
pdf.SaveAs("handbook-with-bookmarks.pdf")
Console.WriteLine("Handbook created with navigational bookmarks.")輸出 PDF
產生的 PDF 檔案包含一個可導航的書籤面板,方便快速存取各個章節:
AddBookMarkAtEnd 中的頁面索引參數使用零為基的索引,其中頁面 0 是文檔的第一頁。 通過 Children 屬性創建的嵌套書籤建立了與文件結構相同的層次。
對於具有正確標題結構的 HTML 文件,IronPDF 可以自動生成目錄,包含鏈接的導航。
代碼通過將 RenderingOptions.TableOfContents 設置為 TableOfContentsTypes.WithPageNumbers 啟用自動 TOC 生成。 HTML 包含一個佔位符 div 和 id="ironpdf-toc",生成的目錄將插入於此。 IronPDF掃描標題元素(h1,h2等),構建帶有頁碼的層次目錄,並在佔位符位置插入。
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Enable automatic table of contents generation
renderer.RenderingOptions.TableOfContents = TableOfContentsTypes.WithPageNumbers;
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Technical Manual</title></head>
<body>
<div id='ironpdf-toc'></div>
<h1>System Administration Guide</h1>
<p>Comprehensive guide to system configuration and maintenance.</p>
<h2>Installation</h2>
<p>Step-by-step installation procedures for all supported platforms.</p>
<h2>Configuration</h2>
<p>Detailed configuration options and recommended settings.</p>
<h2>Troubleshooting</h2>
<p>Common issues and their resolutions.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "System Administration Guide";
pdf.SaveAs("manual-with-toc.pdf");using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Enable automatic table of contents generation
renderer.RenderingOptions.TableOfContents = TableOfContentsTypes.WithPageNumbers;
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Technical Manual</title></head>
<body>
<div id='ironpdf-toc'></div>
<h1>System Administration Guide</h1>
<p>Comprehensive guide to system configuration and maintenance.</p>
<h2>Installation</h2>
<p>Step-by-step installation procedures for all supported platforms.</p>
<h2>Configuration</h2>
<p>Detailed configuration options and recommended settings.</p>
<h2>Troubleshooting</h2>
<p>Common issues and their resolutions.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "System Administration Guide";
pdf.SaveAs("manual-with-toc.pdf");Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Enable automatic table of contents generation
renderer.RenderingOptions.TableOfContents = TableOfContentsTypes.WithPageNumbers
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Technical Manual</title></head>
<body>
<div id='ironpdf-toc'></div>
<h1>System Administration Guide</h1>
<p>Comprehensive guide to system configuration and maintenance.</p>
<h2>Installation</h2>
<p>Step-by-step installation procedures for all supported platforms.</p>
<h2>Configuration</h2>
<p>Detailed configuration options and recommended settings.</p>
<h2>Troubleshooting</h2>
<p>Common issues and their resolutions.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "System Administration Guide"
pdf.SaveAs("manual-with-toc.pdf")Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Enable automatic table of contents generation
renderer.RenderingOptions.TableOfContents = TableOfContentsTypes.WithPageNumbers
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Technical Manual</title></head>
<body>
<div id='ironpdf-toc'></div>
<h1>System Administration Guide</h1>
<p>Comprehensive guide to system configuration and maintenance.</p>
<h2>Installation</h2>
<p>Step-by-step installation procedures for all supported platforms.</p>
<h2>Configuration</h2>
<p>Detailed configuration options and recommended settings.</p>
<h2>Troubleshooting</h2>
<p>Common issues and their resolutions.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "System Administration Guide"
pdf.SaveAs("manual-with-toc.pdf")id="ironpdf-toc" 的 div 元素標示了產生的目錄將顯示的位置。 IronPDF 透過標題元素建立目錄,建立可點擊的連結跳到各個部分。
如何建立帶有正確標籤的無障礙PDF表單?
互動式表單需要特別注意其可訪問性。 每個輸入欄位都必須有一個程式關聯的標籤,以便能夠播報預期的輸入內容。 單靠視覺標籤是不夠的,因為它們缺乏輔助技術正確解讀表單所需的底層連結。
IronPDF 以互動式 PDF 表單欄位的形式呈現 HTML 表單元素。 正確的HTML表單標記可以轉換為易於存取的PDF表單。
代碼通過設置 RenderingOptions.CreatePdfFormsFromHtml = true 啟用表單欄位創建。 HTML 表單使用適當的可及性模式:每個輸入都有一個獨特的 id 與其標籤的 for 屬性匹配,單選按鈕在帶有描述性 legend 的 fieldset 中分組,方可選框則有相關聯的標籤。 RenderHtmlAsPdfUA() 方法將這些元素轉換為具有標籤關聯的互動式 PDF 表單欄位,供屏幕閱讀器使用。
using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Enable form field creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Contact Request Form</title>
<style>
body { font-family: Arial, sans-serif; padding: 30px; max-width: 600px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input[type='text'], input[type='email'], textarea {
width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px;
}
textarea { height: 120px; resize: vertical; }
.checkbox-group { margin: 15px 0; }
.checkbox-group label { display: inline; font-weight: normal; margin-left: 8px; }
fieldset { border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; }
legend { font-weight: bold; padding: 0 10px; }
</style>
</head>
<body>
<h1>Contact Request Form</h1>
<p>Please complete all required fields marked with an asterisk.</p>
<form>
<div class='form-group'>
<label for='fullname'>Full Name *</label>
<input type='text' id='fullname' name='fullname' required>
</div>
<div class='form-group'>
<label for='email'>Email Address *</label>
<input type='email' id='email' name='email' required>
</div>
<div class='form-group'>
<label for='phone'>Phone Number</label>
<input type='text' id='phone' name='phone'>
</div>
<fieldset>
<legend>Preferred Contact Method</legend>
<div class='checkbox-group'>
<input type='radio' id='contact-email' name='contact-method' value='email'>
<label for='contact-email'>Email</label>
</div>
<div class='checkbox-group'>
<input type='radio' id='contact-phone' name='contact-method' value='phone'>
<label for='contact-phone'>Phone</label>
</div>
</fieldset>
<div class='form-group'>
<label for='message'>Message *</label>
<textarea id='message' name='message' required></textarea>
</div>
<div class='checkbox-group'>
<input type='checkbox' id='newsletter' name='newsletter'>
<label for='newsletter'>Subscribe to our newsletter</label>
</div>
</form>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Contact Request Form";
pdf.SaveAs("contact-form-accessible.pdf");
Console.WriteLine("Accessible form created with proper field labels.");using IronPdf;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Enable form field creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Contact Request Form</title>
<style>
body { font-family: Arial, sans-serif; padding: 30px; max-width: 600px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input[type='text'], input[type='email'], textarea {
width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px;
}
textarea { height: 120px; resize: vertical; }
.checkbox-group { margin: 15px 0; }
.checkbox-group label { display: inline; font-weight: normal; margin-left: 8px; }
fieldset { border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; }
legend { font-weight: bold; padding: 0 10px; }
</style>
</head>
<body>
<h1>Contact Request Form</h1>
<p>Please complete all required fields marked with an asterisk.</p>
<form>
<div class='form-group'>
<label for='fullname'>Full Name *</label>
<input type='text' id='fullname' name='fullname' required>
</div>
<div class='form-group'>
<label for='email'>Email Address *</label>
<input type='email' id='email' name='email' required>
</div>
<div class='form-group'>
<label for='phone'>Phone Number</label>
<input type='text' id='phone' name='phone'>
</div>
<fieldset>
<legend>Preferred Contact Method</legend>
<div class='checkbox-group'>
<input type='radio' id='contact-email' name='contact-method' value='email'>
<label for='contact-email'>Email</label>
</div>
<div class='checkbox-group'>
<input type='radio' id='contact-phone' name='contact-method' value='phone'>
<label for='contact-phone'>Phone</label>
</div>
</fieldset>
<div class='form-group'>
<label for='message'>Message *</label>
<textarea id='message' name='message' required></textarea>
</div>
<div class='checkbox-group'>
<input type='checkbox' id='newsletter' name='newsletter'>
<label for='newsletter'>Subscribe to our newsletter</label>
</div>
</form>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Contact Request Form";
pdf.SaveAs("contact-form-accessible.pdf");
Console.WriteLine("Accessible form created with proper field labels.");Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
' Enable form field creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Contact Request Form</title>
<style>
body { font-family: Arial, sans-serif; padding: 30px; max-width: 600px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input[type='text'], input[type='email'], textarea {
width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px;
}
textarea { height: 120px; resize: vertical; }
.checkbox-group { margin: 15px 0; }
.checkbox-group label { display: inline; font-weight: normal; margin-left: 8px; }
fieldset { border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; }
legend { font-weight: bold; padding: 0 10px; }
</style>
</head>
<body>
<h1>Contact Request Form</h1>
<p>Please complete all required fields marked with an asterisk.</p>
<form>
<div class='form-group'>
<label for='fullname'>Full Name *</label>
<input type='text' id='fullname' name='fullname' required>
</div>
<div class='form-group'>
<label for='email'>Email Address *</label>
<input type='email' id='email' name='email' required>
</div>
<div class='form-group'>
<label for='phone'>Phone Number</label>
<input type='text' id='phone' name='phone'>
</div>
<fieldset>
<legend>Preferred Contact Method</legend>
<div class='checkbox-group'>
<input type='radio' id='contact-email' name='contact-method' value='email'>
<label for='contact-email'>Email</label>
</div>
<div class='checkbox-group'>
<input type='radio' id='contact-phone' name='contact-method' value='phone'>
<label for='contact-phone'>Phone</label>
</div>
</fieldset>
<div class='form-group'>
<label for='message'>Message *</label>
<textarea id='message' name='message' required></textarea>
</div>
<div class='checkbox-group'>
<input type='checkbox' id='newsletter' name='newsletter'>
<label for='newsletter'>Subscribe to our newsletter</label>
</div>
</form>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Contact Request Form"
pdf.SaveAs("contact-form-accessible.pdf")
Console.WriteLine("Accessible form created with proper field labels.")Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
' Enable form field creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Contact Request Form</title>
<style>
body { font-family: Arial, sans-serif; padding: 30px; max-width: 600px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input[type='text'], input[type='email'], textarea {
width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px;
}
textarea { height: 120px; resize: vertical; }
.checkbox-group { margin: 15px 0; }
.checkbox-group label { display: inline; font-weight: normal; margin-left: 8px; }
fieldset { border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; }
legend { font-weight: bold; padding: 0 10px; }
</style>
</head>
<body>
<h1>Contact Request Form</h1>
<p>Please complete all required fields marked with an asterisk.</p>
<form>
<div class='form-group'>
<label for='fullname'>Full Name *</label>
<input type='text' id='fullname' name='fullname' required>
</div>
<div class='form-group'>
<label for='email'>Email Address *</label>
<input type='email' id='email' name='email' required>
</div>
<div class='form-group'>
<label for='phone'>Phone Number</label>
<input type='text' id='phone' name='phone'>
</div>
<fieldset>
<legend>Preferred Contact Method</legend>
<div class='checkbox-group'>
<input type='radio' id='contact-email' name='contact-method' value='email'>
<label for='contact-email'>Email</label>
</div>
<div class='checkbox-group'>
<input type='radio' id='contact-phone' name='contact-method' value='phone'>
<label for='contact-phone'>Phone</label>
</div>
</fieldset>
<div class='form-group'>
<label for='message'>Message *</label>
<textarea id='message' name='message' required></textarea>
</div>
<div class='checkbox-group'>
<input type='checkbox' id='newsletter' name='newsletter'>
<label for='newsletter'>Subscribe to our newsletter</label>
</div>
</form>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Contact Request Form"
pdf.SaveAs("contact-form-accessible.pdf")
Console.WriteLine("Accessible form created with proper field labels.")輸出 PDF
產生的 PDF 檔案包含帶有正確標籤關聯的互動式表單欄位:
此表單範例中出現了幾種輔助使用模式。 每個輸入框都有一個唯一的 id 屬性,該屬性與其標籤的 for 屬性相符。 透過此連接,當使用者使用 Tab 鍵切換到「姓名,編輯文字」欄位時,可以播報該欄位內容。 單選按鈕被分組到一個欄位集中,該欄位集帶有圖例,用於描述該組的用途。 複選框的標籤位於輸入元素之後,遵循標準表單約定。
必須啟用 CreatePdfFormsFromHtml 渲染選項,IronPDF 才能創建互動表單欄位而非靜態的表單表示。
產生後如何驗證 PDF/UA 合規性?
建立具有輔助功能功能的 PDF 檔案只是整個過程的一部分。 驗證確認產生的文件確實符合 PDF/UA 標準的技術要求。 目前有多種工具可用於此目的,其中 veraPDF 是最廣為人知的開源驗證器。
雖然 IronPDF 沒有內建驗證功能,但您可以使用外部工具將驗證功能整合到您的工作流程中。 veraPDF 驗證器是一個命令列應用程式,可以從 C# 程式碼中呼叫。
此程式碼展示了一個完整的驗證工作流程。 首先,使用 RenderHtmlAsPdfUA() 生成一個測試 PDF 並配置好中繼資料。 然後使用 Process.Start() 從 C# 調用 veraPDF,配置流程,使之以 --flavour ua1 標記運行以驗證 PDF/UA-1。 系統會擷取輸出結果,並根據退出代碼判定文件是否通過驗證。
using IronPdf;
using System;
using System.Diagnostics;
// Create the accessible PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Test Document</title></head>
<body>
<h1>Validation Test</h1>
<p>This document will be validated for PDF/UA compliance.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Validation Test Document";
string outputPath = "test-document.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created at: {outputPath}");
Console.WriteLine("Run veraPDF validation with:");
Console.WriteLine($" verapdf --flavour ua1 {outputPath}");
// Validate using veraPDF
string verapdfPath = "verapdf";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = verapdfPath,
Arguments = $"--flavour ua1 \"{outputPath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(startInfo))
{
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// veraPDF returns 0 for valid documents
bool isValid = process.ExitCode == 0;
Console.WriteLine(isValid ? "Document passes PDF/UA validation." : "Document has validation issues.");
Console.WriteLine(output);
}using IronPdf;
using System;
using System.Diagnostics;
// Create the accessible PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html lang='en'>
<head><title>Test Document</title></head>
<body>
<h1>Validation Test</h1>
<p>This document will be validated for PDF/UA compliance.</p>
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(htmlContent);
pdf.MetaData.Title = "Validation Test Document";
string outputPath = "test-document.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created at: {outputPath}");
Console.WriteLine("Run veraPDF validation with:");
Console.WriteLine($" verapdf --flavour ua1 {outputPath}");
// Validate using veraPDF
string verapdfPath = "verapdf";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = verapdfPath,
Arguments = $"--flavour ua1 \"{outputPath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(startInfo))
{
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// veraPDF returns 0 for valid documents
bool isValid = process.ExitCode == 0;
Console.WriteLine(isValid ? "Document passes PDF/UA validation." : "Document has validation issues.");
Console.WriteLine(output);
}Imports IronPdf
Imports System
Imports System.Diagnostics
' Create the accessible PDF
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Test Document</title></head>
<body>
<h1>Validation Test</h1>
<p>This document will be validated for PDF/UA compliance.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Validation Test Document"
Dim outputPath As String = "test-document.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created at: {outputPath}")
Console.WriteLine("Run veraPDF validation with:")
Console.WriteLine($" verapdf --flavour ua1 {outputPath}")
' Validate using veraPDF
Dim verapdfPath As String = "verapdf"
Dim startInfo As New ProcessStartInfo With {
.FileName = verapdfPath,
.Arguments = $"--flavour ua1 ""{outputPath}""",
.RedirectStandardOutput = True,
.RedirectStandardError = True,
.UseShellExecute = False,
.CreateNoWindow = True
}
Using process As Process = Process.Start(startInfo)
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
' veraPDF returns 0 for valid documents
Dim isValid As Boolean = process.ExitCode = 0
Console.WriteLine(If(isValid, "Document passes PDF/UA validation.", "Document has validation issues."))
Console.WriteLine(output)
End UsingImports IronPdf
Imports System
Imports System.Diagnostics
' Create the accessible PDF
Dim renderer As New ChromePdfRenderer()
Dim htmlContent As String = "
<!DOCTYPE html>
<html lang='en'>
<head><title>Test Document</title></head>
<body>
<h1>Validation Test</h1>
<p>This document will be validated for PDF/UA compliance.</p>
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(htmlContent)
pdf.MetaData.Title = "Validation Test Document"
Dim outputPath As String = "test-document.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created at: {outputPath}")
Console.WriteLine("Run veraPDF validation with:")
Console.WriteLine($" verapdf --flavour ua1 {outputPath}")
' Validate using veraPDF
Dim verapdfPath As String = "verapdf"
Dim startInfo As New ProcessStartInfo With {
.FileName = verapdfPath,
.Arguments = $"--flavour ua1 ""{outputPath}""",
.RedirectStandardOutput = True,
.RedirectStandardError = True,
.UseShellExecute = False,
.CreateNoWindow = True
}
Using process As Process = Process.Start(startInfo)
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
' veraPDF returns 0 for valid documents
Dim isValid As Boolean = process.ExitCode = 0
Console.WriteLine(If(isValid, "Document passes PDF/UA validation.", "Document has validation issues."))
Console.WriteLine(output)
End UsingAdobe Acrobat Pro 還包含輔助使用檢查功能。 Acrobat Pro 中的輔助使用檢查器可執行全面的測試,包括閱讀順序驗證、替代文字驗證和表單欄位輔助功能。 雖然 Acrobat Pro 不是免費的,但它在企業環境中很常見,並且可以提供有關輔助功能問題的詳細報告。
對於自動化測試流程,PDF/UA 基金會的 PAC(PDF 可訪問性檢查器)工具提供了另一個驗證選項。 PAC 提供圖形介面和命令列功能,使其適合整合到持續整合工作流程中。
企業應用程式中維護可存取 PDF 的最佳實務是什麼?
一旦掌握了技巧,創建可存取的個人化文件就非常簡單。 在企業範圍內大規模保持可訪問性需要係統化的方法和組織紀律。
模板標準化可以減少差異並確保一致性。 創建一個獨特的HTML 模板庫,具備語意結構、可及性表單模式和一致的樣式,能為開發者提供一個生成符合規範輸出的基礎。
此程式碼展示了一種Enterprise級報表生成模式。 首先初始化一個啟用表單創建的 ChromePdfRenderer,然後使用 HttpUtility.HtmlEncode() 建立一個 HTML 報告以插入安全內容。 該報告的 HTML 檔案具備一致的樣式與語義結構。 在 RenderHtmlAsPdfUA() 渲染後,會配置標準中繼資料屬性(標題、作者、創建者和日期)後保存。 此模式可封裝為可重複使用的服務,以確保所有生成的文件皆符合無障礙規範。
using IronPdf;
using System;
using System.Web;
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
string title = "Quarterly Report";
string author = "Finance Team";
string content = "<p>Financial performance overview for Q4 2024.</p>";
// Build report HTML from template
string reportHtml = $@"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>{HttpUtility.HtmlEncode(title)}</title>
<style>
body {{
font-family: 'Segoe UI', Arial, sans-serif;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
padding: 40px;
color: #333;
}}
h1 {{ font-size: 28px; color: #1a1a1a; border-bottom: 2px solid #0066cc; padding-bottom: 10px; }}
h2 {{ font-size: 22px; color: #333; margin-top: 30px; }}
p {{ margin-bottom: 15px; }}
table {{ border-collapse: collapse; width: 100%; margin: 20px 0; }}
th, td {{ border: 1px solid #ddd; padding: 12px; text-align: left; }}
th {{ background-color: #f5f5f5; }}
</style>
</head>
<body>
<h1>{HttpUtility.HtmlEncode(title)}</h1>
{content}
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(reportHtml);
// Configure standard metadata
pdf.MetaData.Title = title;
pdf.MetaData.Author = author;
pdf.MetaData.Creator = "Enterprise Document System";
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.SaveAs("quarterly-report-accessible.pdf");using IronPdf;
using System;
using System.Web;
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
string title = "Quarterly Report";
string author = "Finance Team";
string content = "<p>Financial performance overview for Q4 2024.</p>";
// Build report HTML from template
string reportHtml = $@"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>{HttpUtility.HtmlEncode(title)}</title>
<style>
body {{
font-family: 'Segoe UI', Arial, sans-serif;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
padding: 40px;
color: #333;
}}
h1 {{ font-size: 28px; color: #1a1a1a; border-bottom: 2px solid #0066cc; padding-bottom: 10px; }}
h2 {{ font-size: 22px; color: #333; margin-top: 30px; }}
p {{ margin-bottom: 15px; }}
table {{ border-collapse: collapse; width: 100%; margin: 20px 0; }}
th, td {{ border: 1px solid #ddd; padding: 12px; text-align: left; }}
th {{ background-color: #f5f5f5; }}
</style>
</head>
<body>
<h1>{HttpUtility.HtmlEncode(title)}</h1>
{content}
</body>
</html>";
PdfDocument pdf = renderer.RenderHtmlAsPdfUA(reportHtml);
// Configure standard metadata
pdf.MetaData.Title = title;
pdf.MetaData.Author = author;
pdf.MetaData.Creator = "Enterprise Document System";
pdf.MetaData.CreationDate = DateTime.Now;
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.SaveAs("quarterly-report-accessible.pdf");Imports IronPdf
Imports System
Imports System.Web
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
Dim title As String = "Quarterly Report"
Dim author As String = "Finance Team"
Dim content As String = "<p>Financial performance overview for Q4 2024.</p>"
' Build report HTML from template
Dim reportHtml As String = $"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>{HttpUtility.HtmlEncode(title)}</title>
<style>
body {{
font-family: 'Segoe UI', Arial, sans-serif;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
padding: 40px;
color: #333;
}}
h1 {{ font-size: 28px; color: #1a1a1a; border-bottom: 2px solid #0066cc; padding-bottom: 10px; }}
h2 {{ font-size: 22px; color: #333; margin-top: 30px; }}
p {{ margin-bottom: 15px; }}
table {{ border-collapse: collapse; width: 100%; margin: 20px 0; }}
th, td {{ border: 1px solid #ddd; padding: 12px; text-align: left; }}
th {{ background-color: #f5f5f5; }}
</style>
</head>
<body>
<h1>{HttpUtility.HtmlEncode(title)}</h1>
{content}
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(reportHtml)
' Configure standard metadata
pdf.MetaData.Title = title
pdf.MetaData.Author = author
pdf.MetaData.Creator = "Enterprise Document System"
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
pdf.SaveAs("quarterly-report-accessible.pdf")Imports IronPdf
Imports System
Imports System.Web
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
Dim title As String = "Quarterly Report"
Dim author As String = "Finance Team"
Dim content As String = "<p>Financial performance overview for Q4 2024.</p>"
' Build report HTML from template
Dim reportHtml As String = $"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>{HttpUtility.HtmlEncode(title)}</title>
<style>
body {{
font-family: 'Segoe UI', Arial, sans-serif;
line-height: 1.6;
max-width: 800px;
margin: 0 auto;
padding: 40px;
color: #333;
}}
h1 {{ font-size: 28px; color: #1a1a1a; border-bottom: 2px solid #0066cc; padding-bottom: 10px; }}
h2 {{ font-size: 22px; color: #333; margin-top: 30px; }}
p {{ margin-bottom: 15px; }}
table {{ border-collapse: collapse; width: 100%; margin: 20px 0; }}
th, td {{ border: 1px solid #ddd; padding: 12px; text-align: left; }}
th {{ background-color: #f5f5f5; }}
</style>
</head>
<body>
<h1>{HttpUtility.HtmlEncode(title)}</h1>
{content}
</body>
</html>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdfUA(reportHtml)
' Configure standard metadata
pdf.MetaData.Title = title
pdf.MetaData.Author = author
pdf.MetaData.Creator = "Enterprise Document System"
pdf.MetaData.CreationDate = DateTime.Now
pdf.MetaData.ModifiedDate = DateTime.Now
pdf.SaveAs("quarterly-report-accessible.pdf")自動化測試應該成為持續整合流程的一部分。任何產生 PDF 檔案的流程都應該包含驗證步驟,如果未滿足無障礙存取要求,則建置應該失敗。 這樣可以防止無法存取的文件進入生產環境。
員工培訓與技術實施同等重要。 內容作者需要了解無障礙設計的重要性,以及他們的選擇如何影響最終成果。 教導作者正確使用標題等級、提供有意義的圖像描述以及建立良好的表格結構,可以產生更好的來源材料,從而轉換為符合規範的 PDF 文件。
模板的版本控制和定期的無障礙審核有助於長期保持合規性。隨著業務需求的演變和範本的修改,定期審查可以確保這些變更不會無意中引入無障礙障礙。
將您的無障礙措施記錄下來,就能形成一種機構知識,這種知識即使在人員更迭後也能保留下來。 記錄你遵循的標準、你使用的驗證工具以及針對已發現問題的補救程序,有助於在整個組織內保持一致的做法。
無障礙環境並非一蹴可幾,而是持續的承諾。 標準不斷發展,輔助技術不斷改進,使用者需求也不斷變化。 將無障礙設計融入標準工作流程,而不是將其視為事後考慮的組織,最能滿足當前的需求和未來的期望。
本指南中介紹的技術為使用 IronPDF 創建符合第 508 條款的 PDF 奠定了堅實的基礎。 透過結合正確的 HTML 結構、適當的元資料、導航輔助和驗證測試,.NET 開發人員可以產生符合法律要求的文檔,同時真正服務於依賴無障礙內容的使用者。
結論
IronPDF 簡化了 PDF 可及性標準的複雜性,允許 .NET 開發者專注於內容,而程式庫則負責處理基礎的PDF/UA 結構要求。 本教程介紹了將現有 PDF 轉換為 PDF/UA 格式,直接渲染 HTML 為可及性 PDF,設置文件中繼資料和語言規範以支持螢幕閱讀器,從語意 HTML建立標記文件結構,建立可及性表單並使用書籤建立導航,以及使用 veraPDF 等外部工具驗證合規性。
當可及性成為更廣泛的文件生命周期的一部分時,這些模式自然會與PDF/A 存檔合規性結合用於長期保存和批量處理,以便在政府或醫療保健系統中大規模生成可及性文件。
準備開始建造了嗎? 下載 IronPDF 並試用免費試用版。 同一個庫可以處理從單一可存取文件產生到企業級 PDF/UA 合規性流程的所有操作。 如果您對可及性實施或 Section 508 要求有任何疑問,請聯繫我們的工程支援團隊。
常見問題
什麼是Section 508合規以及它對PDF有什麼重要性?
Section 508合規是指電子信息和技術對殘疾人士的可訪問性之聯邦要求。對於PDF,這確保文件可被螢幕閱讀器閱讀、鍵盤操作,以及被輔助科技正確解讀。
如何使用IronPDF創建符合Section 508的PDF?
您可以使用IronPDF的RenderHtmlAsPdfUA方法創建符合Section 508的PDF,該方法將HTML文檔轉換為符合PDF/UA合規標準的PDF。
替代文本在PDF可訪問性中扮演什麼角色?
替代文本(alt text)描述圖像,使螢幕閱讀器能夠向視障用戶傳達這些信息,確保所有內容均可訪問。
IronPDF如何協助將現有PDF轉換為PDF/UA格式?
IronPDF允許您使用SaveAsPdfUA方法將現有PDF轉換為PDF/UA格式,該方法為合規性添加了標記結構和必要的元數據。
文件元數據在可訪問的PDF中有什麼重要性?
文件元數據,包括標題和語言設置,有助於輔助科技正確識別和對文件內容進行發音,從而增強可訪問性。
如何確保PDF中的表格是可訪問的?
要使PDF中的表格可訪問,使用語義HTML,其中包括用
什麼是標記的PDF結構,它為什麼重要?
標記的PDF結構定義了內容的邏輯組織,這對於螢幕閱讀器向有殘障的使用者有效傳達文件結構至關重要。
IronPDF能自動生成目錄以便於導航嗎?
是的,IronPDF能夠自動根據HTML標題元素生成目錄。此功能創建可點擊的鏈接,有助於文件導航。
我可以採取哪些步驟來驗證PDF/UA合規性?
使用veraPDF等工具來驗證PDF/UA合規性。它提供了一種開源方式來確保您的PDF符合必要的可訪問性標準。
為什麼指定可訪問PDF中的文件語言很重要?
指定文件語言可確保螢幕閱讀器使用正確的發音規則,為使用者提供準確的閱讀體驗。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。
準備好開始了嗎?
NuGet 下載次數 22,198,312|版本:2026.11剛剛發布