如何在 C# 中导出 PDF/A 或 PDF/A-3 格式文件;

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

IronPDF 支持将 PDF 导出到 PDF/A-3b 标准。 PDF/A-3B是ISO PDF规范的严格子集,用于创建文件的档案版本,目的是使文件始终与保存时完全相同地呈现。

Section 508 合规性

IronPDF 很高兴能跟随谷歌的倡议,提高 PDF 存档和可访问性以及 PDF 文档的 508 条款合规性。

2021 年,我们转而使用 Google Chromium HTML 渲染引擎从 HTML 渲染 PDF。这使我们的软件能够继承谷歌已经实施的无障碍工作:



开始使用IronPDF

立即在您的项目中开始使用IronPDF,并享受免费试用。

第一步:
green arrow pointer


PDF/A 版本

IronPDF 支持的两个符合性级别是 A 和 B。 “A”代表“可访问性”,“B”代表“基本”。这些等级适用于PDF/A-1、PDF/A-2和PDF/A-3标准。 以下信息取自Adobe 的 PDF/A 文档.

  • A级符合性满足其规范中的所有要求,使辅助软件能够提高身体残疾用户的可访问性。
  • 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 格式包括第 2 级的所有要求。它还允许在符合 PDF/A 的文档中嵌入其他文件格式,如 XML、CSV 和文字处理格式。

    请注意
    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)
VB   C#

输出

输出文件符合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)
VB   C#

输出文件符合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)
VB   C#

输出文件符合PDF/A-3B标准:

许可完成


支持嵌入附件

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)
VB   C#

嵌入字节数组

通过以字节数组的形式提供文件内容及其各自的文件类型,实现文件嵌入。这在文件已加载到内存中时非常有用。

: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")
VB   C#

使用流嵌入

提供了使用流嵌入文件内容及其文件类型的功能。这种方法非常适合以流的形式处理文件数据的场景。

: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")
VB   C#