如何在 C# 中匯出 PDF/A 或 PDF/A-3 格式的文件
IronPDF 支援將 PDF 導出到 PDF/A-3b 標準。 PDF/A-3B 是 ISO PDF 規範的嚴格子集,用於創建文件的檔案版本,目的是使文件在保存時和以後的呈現始終完全相同。
第508節合規性
IronPDF 很高興能夠響應 Google 的倡議,以提高 PDF 典藏和可及性,以及 PDF 文件的第 508 條合規性。
在2021年,我們開始使用Google Chromium HTML渲染引擎從HTML生成PDF。這讓我們的軟體能夠繼承Google 已經實施的無障礙工作:
開始使用 IronPDF
立即在您的專案中使用IronPDF,並享受免費試用。
如何在C#中將PDF轉換成PDF/A

- 下載 C# 庫以創建 PDF/A 文件
- 從檔案、HTML 或 URL 載入現有 PDF 或建立新 PDF
- 從現有的 PDF 檔案匯出 PDF/A 文件
- 從 HTML 設計或 URL 匯出 PDF/A 文件
- 將符合 PDF/A 標準的文件儲存到所需位置
PDF/A 版本
IronPDF支持的兩個符合性等級為A和B。 「A」代表「可存取」,「B」代表「基本」。這些等級適用於PDF/A-1、PDF/A-2和PDF/A-3標準。 以下資訊來自Adobe 的 PDF/A 文檔資料.
- 等級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)
輸出
輸出文件符合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)
輸出文件符合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)
輸出文件符合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)
嵌入字節數組
透過將文件內容以位元組數組及其相應的文件類型提供來實現文件的嵌入。當文件已加載到記憶體中時,這非常有用。
: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")
嵌入流媒體
提供使用流嵌入文件的功能,包括文件的類型。此方法非常適合文件數據作為流進行處理的情境。
: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")