如何使用 IronPDF 在 C# 中將 PDF 轉換為 PDF/A

如何在 C# 中匯出 PDF/A、PDF/A-3 或 PDF/A-4 格式文檔

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF 支援將 PDF 匯出為 PDF/A-3b 和 PDF/A-4標準。 PDF/A-3B 是 ISO PDF 規範的一個嚴格子集,用於建立文件的存檔版本,目的是使它們始終與儲存時完全相同。 PDF/A-4 是最新的合規標準,為數位簽章提供了更強大的支援。

第 508 條合規性

IronPDF 回應了Google的倡議,旨在提高 PDF 歸檔和可訪問性,以符合第 508 條款的要求。 在進行HTML 轉換 PDF 轉換時,我們的渲染引擎會保留所有輔助功能。

2021年,我們改用Google Chromium 的 HTML 渲染引擎,從 HTML 渲染 PDF 檔案。這使得我們的軟體能夠繼承Google已實現的輔助功能

為什麼符合第 508 條對 PDF/A 文件很重要?

第 508 條合規性確保殘疾人士可以使用螢幕閱讀器等輔助技術存取 PDF 文件。 符合第 508 條款標準的 PDF/A 文件保證內容在整個存檔生命週期內均可存取。 對於政府機構、教育機構以及為所有使用者提供平等資訊取得途徑的組織而言,遵守這項規定至關重要。


IronPDF 支援哪些 PDF/A 版本?

IronPDF 支援 A 級和 B 級一致性。 "A"代表"可訪問","B"代表"基本"。這些等級適用於 PDF/A-1、PDF/A-2 和 PDF/A-3 標準。 以下資訊來自AdAdobe 關於 PDF/A 的文件。 預設情況下,透過 IronPDF 產生的 PDF 輸出為 PDF/A-3B (ISO 19005-3)。

  • A 級符合所有規範要求,使輔助軟體能夠提高身體障礙使用者的可訪問性。
  • B 級符合性較低,合規性要求最低,專注於長期保持視覺外觀。

PDF/A-1、PDF/A-2 和 PDF/A-3 之間有什麼區別?

PDF/A-1 :基於原始 PDF 1.4 版本。

PDF/A-2 :於 2011 年 7 月以 ISO 32001-1 發布,包含 PDF 版本 1.7 之前的所有功能以及新功能。 支援掃描文件的 JPEG2000 格式,並滿足對自訂 XMP 元資料的特定要求。 在處理PDF 元資料時,IronPDF 可確保正確處理 XMP 元資料。

PDF/A-3 :包含所有二級要求。 允許將其他文件格式(XML、CSV 和文字處理格式)嵌入到符合 PDF/A 標準的文件中。

PDF/A-4 :PDF/A 合規標準的最新版本,於 2020 年發布。它基於 PDF 2.0,並引入了改進的功能,包括相比 PDF/A-3 更強大的數位簽章支援。此版本最適合涉及 3D 模型和其他複雜元素的工程文件和技術工作流程。

特徵PDF/A-3PDF/A-4
基礎 PDF 版本PDF 1.7PDF 2.0
嵌入式檔案附件支援不支援。
數位簽名支援增強支持
最佳用例發票,XML資料嵌入工程、3D模型、技術工作流程

IronPdf 目前尚不支援將帶有附件檔案的 PDF 檔案轉換為 PDF/A-3B 格式。

轉換為最新的 PDF/A-4 標準

PDF/A-4 是 PDF/A 系列中的最新合規標準。 它被認為是各種文件類型的最佳存檔格式,尤其適用於涉及數位簽章的文件。 此格式不允許加密和多媒體元素,確保每個檔案都是完全獨立的。

將現有文件轉換為符合 PDF/A-4 標準的文件非常簡單。

:path=/static-assets/pdf/content-code-examples/how-to/sample-pdfa4.cs
using IronPdf;

// Load an existing PDF
PdfDocument pdf = PdfDocument.FromFile("input.pdf");

// Save as PDF/A-4 compliant document
pdf.SaveAsPdfA("pdfa4-output.pdf", PdfAVersions.PdfA4);
$vbLabelText   $csharpLabel

從現有 PDF 文件 (PDF/A-3B)

我有一個使用 IronPDF 生成並保存為 PDF 文件的範例 PDF 文件" wikipedia.pdf "。為了獲得最佳效果,請確保在開始轉換之前正確配置您的授權金鑰

在這個示範中,我將載入並重新儲存為符合 PDF/A-3B 標準的 PDF 文件,並儲存一份為 PDF/A-4 格式的文件(以顯示與最新合規標準的兼容性)。

轉換前的輸入PDF檔是什麼樣的?

什麼程式碼可以將現有的PDF檔案轉換為PDF/A格式?

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-fromfile.cs
using IronPdf;

// Create a PdfDocument object or open any PDF File
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");

// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3b);
$vbLabelText   $csharpLabel

如何確認PDF/A轉換是否成功?

輸出檔符合PDF/A-3b標準:

! veraPDF 一致性檢查器顯示 PDF/A-3B 驗證成功,並顯示綠色合規性訊息

從 HTML 設計或 URL(PDF/A-3B)

我有一個範例 HTML 設計檔案" design.html ",需要使用 IronPDF 將其從 HTML 渲染成 PDF,並將其匯出為符合 PDF/A 標準的 PDF 檔案。 HTML檔案到 PDF 的轉換過程會保留所有樣式和格式。

在這個示範中,我將把它儲存為符合 PDF/A-3B 標準的 PDF 檔案。

如何將HTML檔案轉換為PDF/A格式?

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-fromhtml.cs
using IronPdf;

// Use the Chrome Renderer to make beautiful HTML designs
var chromeRenderer = new ChromePdfRenderer();

// Render an HTML design as a PdfDocument object using Chrome
PdfDocument pdf = chromeRenderer.RenderHtmlAsPdf("design.html");

// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("design-accessible.pdf", PdfAVersions.PdfA3b);
$vbLabelText   $csharpLabel

輸出檔符合PDF/A-3B標準:

VeraPDF 一致性檢查器顯示 PDF 驗證成功,並附有綠色合規性訊息

如何將網頁轉換為PDF/A格式?

我需要使用 IronPDF 將網站" https://www.microsoft.com "的 URL 轉換為 PDF,並匯出為符合 PDF/A 標準的 PDF 檔案。 URL轉 PDF功能可確保所有網頁內容(包括 JavaScript 和 CSS)都能正確呈現。

在這個示範中,我將把它儲存為符合 PDF/A-3B 標準的 PDF 檔案。

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-fromurl.cs
using IronPdf;

// Use the Chrome Renderer to make beautiful HTML designs from URLs
var chromeRenderer = new ChromePdfRenderer();

// Render a Website as a PdfDocument object using Chrome
PdfDocument pdf = chromeRenderer.RenderUrlAsPdf("https://www.microsoft.com");

// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("website-accessible.pdf", PdfAVersions.PdfA3b);
$vbLabelText   $csharpLabel

輸出檔符合PDF/A-3B標準:

! veraPDF 一致性檢查器顯示 PDF/A-3B 驗證成功,並顯示綠色合規性訊息和報告選項


支援嵌入附件(PDF/A-3B)

IronPDF 提供將文件嵌入 PDF 文件並轉換為 PDF/A 格式的功能。 這可以透過使用檔案路徑、位元組數組或流來實現。 此功能可建立包含所有必要支援材料的獨立存檔文件。 如需了解更多進階 PDF 操作功能,請查看我們全面的 PDF 編輯教學

請注意注意:僅在 PDF/A-3B 中支援嵌入式檔案附件。 PDF/A-4 不支援嵌入式附件。

嵌入檔案路徑

使用檔案路徑嵌入檔案。 提供了一系列文件路徑,這些文件在 PDF/A 轉換過程中作為附件包含在內。

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-attachment-path.cs
using IronPdf;
using System.Collections.Generic;

PdfDocument pdf = new PdfDocument("Google.pdf");

// Initialize collection of embed file as string of path
IEnumerable<string> embedPaths = new[] { "File1.xml", "File2.png" };

// Convert to Pdf/A-3B with embeded files
pdf.ConvertToPdfA(embedPaths);
$vbLabelText   $csharpLabel

如何使用位元組數組嵌入文件?

透過將文件內容以位元組數組的形式提供並包含相應的文件類型來嵌入文件。當文件已載入到記憶體中時,此方法非常有用。

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-attachment-byte.cs
using IronPdf;
using System.Collections.Generic;
using System.IO;


PdfDocument pdf = new PdfDocument("Google.pdf");

// Initialize collection of embed file as Bytes and their file type
byte[] fileData1 = File.ReadAllBytes("File1.png");
byte[] fileData2 = File.ReadAllBytes("File2.xml");

var embedFileConfig1 = new EmbedFileConfiguration(EmbedFileType.png);
embedFileConfig1.EmbedFileName = "logo.png";

var embedFileConfig2 = new EmbedFileConfiguration(EmbedFileType.xml)
{
    EmbedFileName = "supportSystem.xml",
    AFDesc = "Internal system",
    ConformanceLevel = ConformanceLevel.XRECHNUNG,
    SchemaNamespace = SchemaNamespace.Zugferd1,
    SchemaPrefix = SchemaPrefix.rsm,
    PropertyVersion = PropertyVersion.v1p0,
    AFRelationship = AFRelationship.Supplement,
};

IEnumerable<EmbedFileByte> embedBytes = new[]
{
    new EmbedFileByte(fileData1, embedFileConfig1),
    new EmbedFileByte(fileData2, embedFileConfig2)
};

// Convert to Pdf/A-3B with embeded files
pdf.ConvertToPdfA(embedBytes).SaveAs("PdfACompliance.pdf");
$vbLabelText   $csharpLabel

如何使用流嵌入檔案?

使用流來嵌入文件,並包含文件類型資訊。當文件資料以流的形式處理時,這種方法非常理想。

:path=/static-assets/pdf/content-code-examples/how-to/pdfa-attachment-stream.cs
using IronPdf;
using System.Collections.Generic;
using System.IO;

PdfDocument pdf = new PdfDocument("Google.pdf");

// Initialize collection of embed file as Stream and their file type
Stream stream1 = new MemoryStream(File.ReadAllBytes("File1.png"));
Stream stream2 = new MemoryStream(File.ReadAllBytes("File2.xml"));

var embedFileConfig1 = new EmbedFileConfiguration(EmbedFileType.png);
embedFileConfig1.EmbedFileName = "logo.png";

var embedFileConfig2 = new EmbedFileConfiguration(EmbedFileType.xml)
{
    EmbedFileName = "supportSystem.xml",
    AFDesc = "Internal system",
    ConformanceLevel = ConformanceLevel.XRECHNUNG,
    SchemaNamespace = SchemaNamespace.Zugferd1,
    SchemaPrefix = SchemaPrefix.rsm,
    PropertyVersion = PropertyVersion.v1p0,
    AFRelationship = AFRelationship.Supplement,
};

IEnumerable<EmbedFileStream> embedStreams = new[]
{
    new EmbedFileStream(stream1, embedFileConfig1),
    new EmbedFileStream(stream2, embedFileConfig2)
};

// Convert to Pdf/A-3B with embeded files
pdf.ConvertToPdfA(embedStreams).SaveAs("PdfACompliance.pdf");
$vbLabelText   $csharpLabel

如何使用 EmbedFileConfiguration 設定嵌入式檔案屬性?

將 PdfDocument 轉換為包含嵌入檔案的 PDF/A-3 格式時,設定 EmbedFilePath、EmbedFileByte 或 EmbedFileStream 等參數非常重要。 這些設定可讓您指定要嵌入的檔案類型、檔案名稱以及您想要包含的任何自訂 XMP 元資料。

正確的配置可確保嵌入內容得到有效組織,並符合 PDF/A-3 標準。 自訂 XMP 元資料可以提供有關嵌入文件的其他信息,從而增強文件的可用性和可訪問性。 使用EmbedFileConfiguration類,開發人員可以輕鬆自訂文件的值和格式。

var config = new EmbedFileConfiguration
{
    EmbedFileName = "Attachment.xml",
    AFDesc = "Associated File Description",
    ConformanceLevel = ConformanceLevel.EN16931,
    SchemaNamespace = SchemaNamespace.facturX,
    SchemaPrefix = SchemaPrefix.fx,
    PropertyVersion = PropertyVersion.v1,
    AFRelationship = AFRelationship.Alternative
};

 // Load a PDF document
 var document = PdfDocument.FromFile("wikipedia.pdf");

 // Configure embedded file parameters
 document.EmbedFileFromFilePath("path/to/attachment", config);

 // Save the document as PDF/A-3b
 document.SaveAsPdfA3B("output-with-configured-attachment.pdf");
var config = new EmbedFileConfiguration
{
    EmbedFileName = "Attachment.xml",
    AFDesc = "Associated File Description",
    ConformanceLevel = ConformanceLevel.EN16931,
    SchemaNamespace = SchemaNamespace.facturX,
    SchemaPrefix = SchemaPrefix.fx,
    PropertyVersion = PropertyVersion.v1,
    AFRelationship = AFRelationship.Alternative
};

 // Load a PDF document
 var document = PdfDocument.FromFile("wikipedia.pdf");

 // Configure embedded file parameters
 document.EmbedFileFromFilePath("path/to/attachment", config);

 // Save the document as PDF/A-3b
 document.SaveAsPdfA3B("output-with-configured-attachment.pdf");
$vbLabelText   $csharpLabel
  • EmbedFileName :表示 PDF/A 文件中嵌入檔案名稱的string屬性。 預設值為空字串。
  • AFDesc :表示嵌入檔案的關聯檔案所描述的string屬性。預設值為空字串。
  • ConformanceLevel :套用於 PDF/A 文件的 XMP 元資料的嵌入 XML 檔案的一致性等級。 預設值為ConformanceLevel.EN16931 。 IronPDF 透過ConformanceLevel枚舉提供不同的數值。
  • SchemaNamespace :PDF/A Schema NamespaceURI,用於嵌入 XML 檔案並套用至 PDF/A 文件的 XMP 元資料。 預設值為SchemaNamespace.facturXSchemaNamespace枚舉中提供了各種選項。
  • SchemaPrefix :PDF/A Schema Prefix,用於嵌入 XML 文件,套用於 PDF/A 文件的 XMP 元資料。 預設值為SchemaPrefix.fxSchemaPrefix枚舉中提供了幾個選項。
  • PropertyVersion :套用於 PDF/A 文件 XMP 元資料的嵌入 XML 檔案的屬性版本。 預設值為PropertyVersion.v1PropertyVersion列舉中有多個選項。
  • AFRelationship :關聯文件(嵌入文件)與 PDF/A 文件的關係。 AFRelationship列舉提供了多個選項。

什麼原因會導致 PDF/A 中的字元顯示問題?

PDF/A 要求文件中的所有字元都對應到視覺上和語義上正確的字體。 並非所有字體都必須嵌入,但所用字體必須支援所需的字形。如果使用錯誤或不完整的字體,某些字元可能會顯示不完整、缺失或渲染錯誤—尤其是在使用特殊文字或符號的語言中。 為了優化檔案大小,請參考我們的PDF 壓縮指南,以平衡字體嵌入和檔案大小。

為什麼PDF/A文件中有些字元顯示不完整?

例如,在下面的問題中,上面的範例使用了正確的字體並正確顯示了字符,而下面的範例由於字體不匹配而無法正確渲染字符。

字元編碼比較顯示,從 DejaVuSans 和 Times New Roman 字體轉換為 PDF/A 字體時會出現字體損壞

從現有 PDF 文件 (PDF/A-4)

我有一個範例 PDF 檔案" who.pdf ",其中包含世界衛生組織 2025-2028 年全球衛生策略。該文件使用 IronPDF 產生並儲存為標準 PDF 文件。

在這個示範中,我將載入並重新儲存為符合 PDF/A-4 標準的 PDF 文件,以確保這份重要的全球衛生文件能夠長期符合存檔要求。

輸入檔:"who.pdf"

程式碼

:path=/static-assets/pdf/content-code-examples/how-to/save-as-pdfa4.cs
using IronPdf;

// Load the environmental impact assessment document
PdfDocument pdf = PdfDocument.FromFile("ENV-2026-1847-Assessment-Report.pdf");

// Save as PDF/A-4 compliant document for long-term archival
pdf.SaveAsPdfA("ENV-2026-1847-Report-PDFA4Compliant.pdf", PdfAVersions.PdfA4);
$vbLabelText   $csharpLabel

輸出

輸出檔符合PDF/A-4標準:

許可證已完成

準備好要看看你還能做什麼了嗎? 請造訪我們的教學頁面:建立 PDF

常見問題解答

如何使用 C# 將標準 PDF 轉換為 PDF/A-3b 格式?

使用 IronPDF,您只需使用兩行程式碼即可將任何標準 PDF 轉換為 PDF/A-3b 格式。只需使用 PdfDocument.FromFile() 載入您的 PDF,然後調用 SaveAsPdfA() 將其匯出為符合要求的 PDF/A-3b 文件,以便長期存檔。

什麼是 PDF/A-3b,為什麼它對文件歸檔很重要?

PDF/A-3b 是 ISO PDF 規格的嚴格子集,專為長期文件保存而設計。IronPdf 支援 PDF/A-3b 匯出,以確保您的文件永遠呈現與儲存時一模一樣的效果,因此非常適合對文件完整性要求極高的法律、政府和歸檔用途。

PDF/A 轉換是否支援 Section 508 可存取性規範?

是的,IronPdf 通過使用 Google Chromium 的渲染引擎來確保符合 Section 508 的規定,該引擎繼承了 Google 的無障礙功能。這意味著使用螢幕閱讀器等輔助技術的殘障使用者可以存取您的 PDF/A 文件。

我可以直接將 HTML 內容轉換成 PDF/A 格式嗎?

絕對可以IronPDF 可讓您直接將 HTML 內容或 URL 轉換為 PDF/A-3b 格式。Google Chromium 渲染引擎會在 HTML 轉換為 PDF 的過程中保留所有可存取性功能,確保您所產生的 PDF/A 文件完全符合規範。

與標準 PDF 格式相比,使用 PDF/A-3b 的主要優點是什麼?

IronPDF 的 PDF/A-3b 匯出功能可確保長期保存、在所有檢視器上提供一致的呈現、符合 Section 508 可訪問性規定,並遵守 ISO 存檔標準。這使得它非常適合法律文件、政府記錄以及任何需要永久存檔的內容。

柯蒂斯·週
技術撰稿人

Curtis Chau擁有卡爾頓大學電腦科學學士學位,專長於前端開發,精通Node.js、TypeScript、JavaScript和React。他熱衷於打造直覺美觀的使用者介面,喜歡使用現代框架,並擅長撰寫結構清晰、視覺效果出色的使用者手冊。

除了開發工作之外,柯蒂斯對物聯網 (IoT) 也抱有濃厚的興趣,致力於探索硬體和軟體整合的創新方法。閒暇時,他喜歡玩遊戲和製作 Discord 機器人,將他對科技的熱愛與創造力結合。

準備好開始了嗎?
Nuget 下載 17,012,929 | 版本: 2025.12 剛剛發布