如何使用 IronPDF 在 C# 中转换 PDF 为 PDF/A

How to Export PDF/A or PDF/A-3 Format Documents in C#

This article was translated from English: Does it need improvement?
Translated
View the article in English
role="alert"> 您的企业在 PDF 安全和合规的年度订阅上花费过多。考虑使用IronSecureDoc,它提供了如数字签名、删减、加密和保护等 SaaS 服务管理解决方案,只需一次性付款。浏览 IronSecureDoc 的文档

作为PDF 协会的成员,Iron Software 积极支持 PDF/A 标准,并确保 IronPDF 符合存档合规性要求。

IronPDF 支持导出 PDF 为 PDF/A-3b 标准。 PDF/A-3B 是一种严格的 ISO PDF 规范子集,用于创建文档的存档版本,旨在使其始终如保存时那样精确呈现。

快速开始:在 C# 中将 PDF 转换为 PDF/A-3b

使用 IronPDF,只需几行 C# 代码即可轻松将标准 PDF 转换为存档的 PDF/A-3b 格式。 这确保了长期的文档保存和符合存档标准。 通过利用 IronPDF 的强大功能,您可以快速将现有文件转换为 PDF/A 格式,保证一致的呈现和可访问性。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    IronPdf.PdfDocument pdf = IronPdf.PdfDocument.FromFile("example.pdf");
    pdf.SaveAsPdfA("output.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

第 508 节合规性

IronPDF 很高兴遵循谷歌提高 PDF 存档和可访问性以及 PDF 文档第 508 节合规性的倡议。

在 2021 年,我们开始使用谷歌 Chromium HTML 渲染引擎从 HTML 渲染 PDF。这使我们的软件继承了谷歌已经实施的可访问性工作

开始使用 IronPDF

今天在您的项目中使用 IronPDF,免费试用。

第一步:
green arrow pointer

*

class="hsg-featured-snippet">

最小工作流(5 步)

How to Render HTML String to PDF in C#
  1. 下载用于创建 PDF/A 文档的 C# 库
  2. 加载现有文件或从文件、HTML 或 URL 创建 PDF
  3. 从现有 PDF 文件导出 PDF/A 文档
  4. 从 HTML 设计或 URL 导出 PDF/A 文档
  5. 将符合 PDF/A 的文档保存到所需位置

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)。

  • Level A 符合买到其规范中的所有要求,允许辅助软件提高身体残疾用户的可访问性。
  • Level B 的合规性级别较低,具有最低的合规性,重点在于长期保存文件的视觉外观。

PDF/A-1:PDF/A 格式是基于原始 PDF 1.4 版本。

PDF/A-2:于 2011 年 7 月发布,被称为 ISO 32001-1 新标准,该标准包括所有 PDF 版本至 1.7 的所有功能以及新功能。 其功能包括支持 JPEG2000,这对扫描文档很有用,以及特定的自定义 XMP 元数据要求。

PDF/A-3:该 PDF/A 格式包括 Level 2 的所有要求。它还允许将其他文件格式——如 XML、CSV 和文字处理格式——嵌入 PDF/A 合规文档中。

请注意IronPdf 尚不支持将带有附件的 PDF 转换为 PDF/A-3B。

从现有 PDF 文件

我有一个示例 PDF "wikipedia.pdf",它是使用 IronPDF 生成并保存为 PDF 文件的。

在本演示中,我将加载并重新保存为符合 PDF/A-3B 合规性的 PDF 文件。

输入文件:“wikipedia.pdf”

代码

: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-3b

许可完整

从 HTML 设计或 URL

我有一个示例 HTML 设计 "design.html",我希望通过 IronPDF 从 HTML 渲染为 PDF,然后导出为符合 PDF/A 的文件。

在本演示中,我将其保存为符合 PDF/A-3B 的 PDF 文件。

HTML 设计示例

: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

许可完整

URL 示例

我有以下网站 "https://www.microsoft.com",我希望通过 IronPDF 从 URL 渲染为 PDF,然后导出为符合 PDF/A 的文件。

在本演示中,我将其保存为符合 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

许可完整

<hr

支持嵌入附件

IronPdf 提供了在将 PDF 文档转换为 PDF/A 格式时嵌入文件的能力。 这可以通过多种输入类型实现,如文件路径、字节数组或流。

使用文件路径嵌入

允许使用文件路径嵌入文件。 提供了一组文件路径,这些文件将在 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、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");
Dim config = 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:一个 string 属性,表示 PDF/A 文档中嵌入文件的名称。 默认情况下,此字符串为空。
  • AFDesc: A string property representing the associated file description for the embedded file. 默认情况下,此字符串为空。
  • ConformanceLevel:应用于 PDF/A 文档 XMP 元数据的 XML 文件嵌入合规性水平。 默认为 ConformanceLevel.EN16931。 IronPDF 通过 ConformanceLevel 枚举提供不同的值。
  • SchemaNamespace:PDF/A 模式 NamespaceURI 嵌入 XML 文件并将其应用于 PDF/A 文档的 XMP 元数据。 默认为 SchemaNamespace.facturX,开发人员可以在 SchemaNamespace 枚举中选择多种选项。
  • SchemaPrefix:PDF/A 模式前缀,嵌入 XML 文件并将其应用于 PDF/A 文档的 XMP 元数据。 默认为 SchemaPrefix.fx,在 SchemaPrefix 枚举中有几个选项可供选择。
  • PropertyVersion:适用于 PDF/A 文档 XMP 元数据的嵌入 XML 文件的属性版本。 默认为 PropertyVersion.v1,在 PropertyVersion 枚举中有多个选项。
  • AFRelationship:关联文件(嵌入文件)与 PDF/A 文档的关系。 在 AFRelationship 枚举中有几个选项可用。

字符显示问题

PDF/A 要求文档中的所有字符都映射到视觉和语义上正确的字体。 虽然不需要嵌入所有字体,但所使用的字体必须支持所需的字符。如果使用不正确或不完整的字体,则某些字符可能会出现崩溃、缺失或错误呈现——尤其是在具有特殊脚本或符号的语言中。

例如,在下面的问题中,顶部示例使用了正确的字体并正确显示了字符,而底部示例由于字体不匹配而未能正确呈现。

显示问题

准备好看看您还能做些什么吗? 在此查看我们的教程页面:创建 PDF

常见问题解答

如何在 C# 中将 PDF 转换为 PDF/A 格式?

您可以使用 IronPDF 的转换功能,在 C# 中将标准 PDF 转换为 PDF/A 格式。此操作通过加载 PDF 文档并以指定的 PDF/A 合规级别保存来完成。

PDF/A-3b 与其他 PDF/A 标准有什么区别?

PDF/A-3b 是 ISO PDF 规范的一个子集,专注于通过确保文档一致呈现来实现长期保存。与其他 PDF/A 标准不同,PDF/A-3b 允许在文档中嵌入其他文件,如 XML 或 CSV。

如何使用 C# 将文件嵌入到 PDF/A 文档中?

IronPDF 允许通过文件路径、字节数组或流将 XML 或 CSV 等文件嵌入到 PDF/A 文档中。这是通过使用 EmbedFileConfiguration 类配置参数(如文件名、描述和元数据)来完成的。

HTML 或 URL 内容可以转换为 PDF/A-3b 吗?

可以,IronPDF 可以将 HTML 内容或 URL 转换为 PDF/A-3b。此过程涉及将 HTML 或 URL 渲染为 PDF 格式,然后将文档以 PDF/A-3b 合规性保存。

PDF/A 文档支持哪些可访问性功能?

IronPDF 使用 Google 的 Chromium HTML 渲染引擎,该引擎继承了 Google 实施的可访问性功能,从而支持符合 Section 508 标准的 PDF/A 文档的可访问性。

如何确保我的 PDF/A 文档符合 Section 508?

IronPDF 可以确保您的 PDF/A 文档通过利用 Google Chromium HTML 渲染引擎的可访问性功能符合 Section 508,这有助于使 PDF 对辅助软件可访问。

EmbedFileConfiguration 类的目的是什么?

IronPDF 中的 EmbedFileConfiguration 类允许开发人员配置在 PDF/A 文档中嵌入文件的参数,如指定文件元数据并确保符合 PDF/A-3 标准。

我可以将带附件的 PDF 转换为 PDF/A-3b 格式吗?

IronPDF 可以将带附件的 PDF 转换为 PDF/A-3b,但需要使用 IronPDF 提供的适当方法专门配置和嵌入附件。

IronPDF 为 PDF/A 转换提供了哪些好处?

IronPDF 为 PDF/A 转换提供了多种好处,包括符合存档标准、支持多种输入格式、嵌入文件的能力以及全面的元数据自定义。

IronPDF 在转换为 PDF/A 格式时是否与 .NET 10 兼容?

是的。IronPDF 完全兼容 .NET 10,支持 PDF/A 转换功能(例如 SaveAsPdfA)以及通过 ChromePdfRenderer 进行渲染。您可以在 .NET 10 项目中直接使用它,无需任何特殊设置。它还支持在 Windows、Linux、macOS 和容器上部署,目标平台为 .NET 10。

Curtis Chau
技术作家

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

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

准备开始了吗?
Nuget 下载 16,133,208 | 版本: 2025.11 刚刚发布