Convert PDF to PDF/A using C# .NET
This guide uses the GdPicture.API package. For new projects, we recommend the Nutrient.SDK package. Refer to the PDF to PDF/A with Nutrient.SDK guide.
PDF/A conversion prepares PDF documents for long-term archiving. It enforces preservation rules so documents remain readable and self-contained over time. For background on the standard, refer to the complete guide to PDF/A.
Use this workflow when you need to:
- Meet archival or retention requirements
- Preserve document rendering for long-term storage
- Remove external dependencies from PDF files
Prepare the project
Register the SDK license before running conversion operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager licence = new LicenseManager();licence.RegisterKEY(""); // Set your license keyLoad the PDF document
Create a GdPicturePDF instance and load the source file:
using GdPicturePDF pdf = new GdPicturePDF();pdf.LoadFromFile(@"input.pdf");Convert to PDF/A
Convert the loaded document to PDF/A-2b:
pdf.ConvertToPDFA(@"output.pdf", PdfConversionConformance.PDF_A_2b, false, false);ConvertToPDFA takes the following parameters:
- The path to the output document. If the file already exists, the method overwrites it.
- A member of the
PdfConversionConformanceenumeration that sets the PDF/A conformance level of the output. - Whether to allow vectorization when a page can’t be converted directly.
- Whether to allow rasterization when a page can be neither converted directly nor vectorized.
With false, false, as in the example above, the SDK only uses direct conversion. If a page needs vectorization or rasterization, ConvertToPDFA stops and returns GdPictureStatus.PdfConversionFailed. To let the SDK fall back to these techniques, set the corresponding parameters to true. For their side effects, refer to the configuring PDF/A conversion section below.
PDF/A conformance levels
The SDK supports all PDF/A versions and conformance levels:
| Conformance level | PdfConversionConformance member |
|---|---|
| PDF/A-1a | PDF_A_1a |
| PDF/A-1b | PDF_A_1b |
| PDF/A-2a | PDF_A_2a |
| PDF/A-2u | PDF_A_2u |
| PDF/A-2b | PDF_A_2b |
| PDF/A-3a | PDF_A_3a |
| PDF/A-3u | PDF_A_3u |
| PDF/A-3b | PDF_A_3b |
| PDF/A-4 | PDF_A_4 |
| PDF/A-4e | PDF_A_4e |
| PDF/A-4f | PDF_A_4f |
Select the level that matches your archival policy.
Configuring PDF/A conversion
PDF/A documents have a stricter structure than regular PDF documents. To meet the selected conformance level, conversion may change the document’s content or appearance. For example, the SDK embeds fonts, converts color spaces to compliant ones, adds archival metadata, validates embedded resources, and adds, edits, or removes document structure elements.
When direct conversion of a page isn’t possible, the SDK can use two fallback techniques, if you allow them:
- Vectorization — Page elements that can’t be used directly, typically fonts and paths, are embedded as vector graphics.
- Rasterization — Page content that can’t be used directly is embedded as raster images. If vectorization is allowed but fails, the SDK tries rasterization next.
Both techniques lose fonts and text information, because text becomes shapes or images. To recover the text, run OCR on the output, as described in the PDF to searchable PDF guide.
Close the document
CloseDocument releases the loaded document and its resources. Disposing of the GdPicturePDF object does the same, so call CloseDocument when you keep the object alive after a conversion — for example, to process the next file.
Handle errors
LoadFromFile and ConvertToPDFA return GdPictureStatus values. In production, validate:
- Input file availability and format
- Operation status after loading and conversion
- Output conformance with your validation tools
The example below checks the status after each call, reports when the document needs vectorization or rasterization, and closes the document:
using GdPicturePDF checkedPdf = new GdPicturePDF();
GdPictureStatus status = checkedPdf.LoadFromFile(@"input.pdf");if (status != GdPictureStatus.OK){ throw new Exception($"Loading the PDF failed: {status}");}
status = checkedPdf.ConvertToPDFA(@"output_checked.pdf", PdfConversionConformance.PDF_A_2b, false, false);if (status == GdPictureStatus.PdfConversionFailed){ throw new Exception("The document needs vectorization or rasterization to meet PDF/A-2b.");}if (status != GdPictureStatus.OK){ throw new Exception($"PDF/A conversion failed: {status}");}
checkedPdf.CloseDocument();Using checkedPdf As New GdPicturePDF() Dim status As GdPictureStatus = checkedPdf.LoadFromFile("input.pdf") If status <> GdPictureStatus.OK Then Throw New Exception($"Loading the PDF failed: {status}") End If
status = checkedPdf.ConvertToPDFA("output_checked.pdf", PdfConversionConformance.PDF_A_2b, False, False) If status = GdPictureStatus.PdfConversionFailed Then Throw New Exception("The document needs vectorization or rasterization to meet PDF/A-2b.") End If If status <> GdPictureStatus.OK Then Throw New Exception($"PDF/A conversion failed: {status}") End If
checkedPdf.CloseDocument()End UsingFor status-handling patterns, refer to the handling errors with .NET SDK guide.
Common use cases
PDF/A is common in legal archives, government records, medical and financial record retention, and research and publication archives.
Conclusion
This guide converts a standard PDF file to PDF/A for archiving and compliance-oriented document storage.