如何使用 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/A-3b 和 PDF/A-4 标准导出 PDF。 PDF/A-3B 是一种严格的 ISO PDF 规范子集,用于创建文档的存档版本,旨在使其始终如保存时那样精确呈现。 PDF/A-4 是最新的合规标准,提供了对数字签名的增强支持。

第 508 节合规性

IronPDF 遵循谷歌的倡议,提高 PDF 的归档和可访问性,以符合第 508 条的规定。 在使用 HTML 转换为 PDF 时,我们的渲染引擎会保留所有无障碍功能。

2021 年,我们转而使用 Google Chromium 的 HTML 渲染引擎从 HTML 渲染 PDF。这使得我们的软件可以继承谷歌已经实现的可访问性工作

为什么符合第 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 标准。 以下信息来自 Adobe 的 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: 包括所有 2 级要求。 允许将其他文件格式--XML、CSV 和文字处理格式--嵌入到符合 PDF/A 标准的文档中。

PDF/A-4: PDF/A 合规性标准的最新版本,于 2020 年发布。它以 PDF 2.0 为基础,引入了改进的功能,包括与 PDF/A-3 相比增强了对数字签名的支持。该版本最适合涉及三维模型和其他复杂元素的工程文档和技术工作流程。

特征 PDF/A-3 PDF/A-4
基础 PDF 版本 PDF 1.7 PDF 2.0
嵌入式文件附件 支持 不支持
数字签名 支持 增强支持
最佳使用案例 发票、XML 数据嵌入 工程、3D 模型、技术工作流程

[{i:(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);
Imports IronPdf

' Load an existing PDF
Dim pdf As PdfDocument = PdfDocument.FromFile("input.pdf")

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

From an Existing PDF File (PDF/A-3B)

本示例使用了 wikipedia.pdf 文件,这是一个使用 IronPDF 生成的 PDF 文件。 为获得最佳效果,请确保您在开始转换之前已正确配置了许可证密钥

下面的代码以 PDF/A-3B 和 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);
Imports IronPdf

' Create a PdfDocument object or open any PDF File
Private pdf As PdfDocument = 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)

本示例使用 design.html 这个 HTML 设计文件,使用 IronPDF 从 HTML 渲染成 PDF,并导出为符合 PDF/A 标准的文件。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);
Imports IronPdf

' Use the Chrome Renderer to make beautiful HTML designs
Private chromeRenderer = New ChromePdfRenderer()

' Render an HTML design as a PdfDocument object using Chrome
Private pdf As PdfDocument = 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 标准的文件。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);
Imports IronPdf

' Use the Chrome Renderer to make beautiful HTML designs from URLs
Private chromeRenderer = New ChromePdfRenderer()

' Render a Website as a PdfDocument object using Chrome
Private pdf As PdfDocument = 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/A 转换过程中使用文件路径、字节数组或流将文件嵌入 PDF 文档。 该功能可创建包含所有必要辅助材料的独立存档文件。 有关更多高级 PDF 操作功能,请查看我们的 PDF 编辑教程

[{i:(注:嵌入式文件附件仅支持 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);
Imports IronPdf
Imports System.Collections.Generic

Private pdf As New PdfDocument("Google.pdf")

' Initialize collection of embed file as string of path
Private embedPaths As IEnumerable(Of String) = { "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");
Imports IronPdf
Imports System.Collections.Generic
Imports System.IO


Private pdf As New PdfDocument("Google.pdf")

' Initialize collection of embed file as Bytes and their file type
Private fileData1() As Byte = File.ReadAllBytes("File1.png")
Private fileData2() As Byte = File.ReadAllBytes("File2.xml")

Private embedFileConfig1 = New EmbedFileConfiguration(EmbedFileType.png)
embedFileConfig1.EmbedFileName = "logo.png"

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

Dim embedBytes As IEnumerable(Of EmbedFileByte) = {
	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");
Imports IronPdf
Imports System.Collections.Generic
Imports System.IO

Private pdf As New PdfDocument("Google.pdf")

' Initialize collection of embed file as Stream and their file type
Private stream1 As Stream = New MemoryStream(File.ReadAllBytes("File1.png"))
Private stream2 As Stream = New MemoryStream(File.ReadAllBytes("File2.xml"))

Private embedFileConfig1 = New EmbedFileConfiguration(EmbedFileType.png)
embedFileConfig1.EmbedFileName = "logo.png"

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

Dim embedStreams As IEnumerable(Of EmbedFileStream) = {
	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, EmbedFileByteEmbedFileStream 以指定文件类型、名称和自定义 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");
Option Strict On



Dim config As New EmbedFileConfiguration With {
    .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
Dim 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:嵌入 XML 文件并应用于 PDF/A 文档 XMP 元数据的 PDF/A Schema NamespaceURI。 默认值为 SchemaNamespace.facturXSchemaNamespace 枚举中提供了各种选项。
  • SchemaPrefix:PDF/A 模式前缀,用于嵌入适用于 PDF/A 文档 XMP 元数据的 XML 文件。 默认值为 SchemaPrefix.fx,在 SchemaPrefix 枚举中有多个选项。
  • PropertyVersion:应用于 PDF/A 文档 XMP 元数据的嵌入 XML 文件的属性版本。 默认为 PropertyVersion.v1,在 PropertyVersion 枚举中有多个选项。
  • AFRelationship:关联文件(嵌入文件)与 PDF/A 文档的关系。 在 AFRelationship 枚举中有几个选项可用。

是什么导致了 PDF/A 中的字符显示问题?

PDF/A 要求将文档中的所有字符映射到视觉和语义正确的字体上。 虽然并非所有字体都必须嵌入,但所使用的字体必须支持所需的字形。如果使用了不正确或不完整的字体,某些字符可能会出现断裂、缺失或错误呈现的情况,尤其是在使用特殊脚本或符号的语言中。 关于文件大小优化的注意事项,请浏览我们的PDF压缩指南,以平衡字体嵌入与文件大小之间的关系。

为什么某些字符在 PDF/A 文档中出现断裂?

例如,在下面的问题中,上面的样本使用了正确的字体并能正确显示字符,而下面的样本由于字体不匹配而无法正确显示字符。

字符编码比较,显示从 DejaVuSans 和 Times New Roman 转换 PDF/A 时的字体损坏

From an Existing PDF File (PDF/A-4)

本示例使用 "ENV-2026-1847-Assessment-Report.pdf",这是一份 8 页的市政环境影响评估文件。 该报告证明了 PDF/A-4 适用于归档需要长期保存的政府官方文件--环境研究、监管文件和机构必须保留数十年的合规记录。

PDF/A-4 是这些文档的理想选择,因为它能保证长期的视觉保真度,嵌入所有字体和资源,并支持官方认证所需的增强型数字签名功能。

输入文件:"ENV-2026-1847-Assessment-Report.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);
Imports IronPdf

' Load the environmental impact assessment document
Dim pdf As PdfDocument = 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 标准:

!a href="/static-assets/pdf/how-to/pdfa/env-report-pdfa4-passed.webp">veraPDF Conformance Checker 显示环境评估报告的 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 转换是否支持第 508 条可访问性合规性?

是的,IronPDF 通过使用谷歌 Chromium 的渲染引擎,继承了谷歌的可访问性功能,从而确保符合第 508 条的规定。这意味着使用屏幕阅读器等辅助技术的残疾用户可以访问您的 PDF/A 文档。

我可以将 HTML 内容直接转换为 PDF/A 格式吗?

当然可以!IronPDF 允许您将 HTML 内容或 URL 直接转换为 PDF/A-3b 格式。在将 HTML 转换为 PDF 的过程中,Google Chromium 渲染引擎会保留所有可访问性功能,确保您生成的 PDF/A 文档完全合规。

与标准 PDF 格式相比,使用 PDF/A-3b 的主要好处是什么?

IronPDF 的 PDF/A-3b 导出可保证长期保存、在所有阅读器上呈现一致的效果、符合第 508 条可访问性规定并遵守 ISO 存档标准。这使其成为法律文件、政府记录和任何需要永久存档的内容的完美选择。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 17,386,124 | 版本: 2026.2 刚刚发布