Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.2
  • Convert and Validate PDF/A and PDF/UA

    • 10 minutes to read

    The PDF Document API allows you to convert PDF documents to PDF/A and PDF/UA, validate documents against these standards, and analyze compliance issues.

    PDF/A (ISO 19005)
    A PDF standard for long-term archiving. A PDF/A document embeds all resources that a PDF viewer needs to render the document (for example, fonts and color profiles) and does not contain content that depends on external resources or scripts.
    PDF/UA (ISO 14289)
    A PDF standard for universal accessibility. A PDF/UA document contains a logical structure tree, tagged page content, and settings required by assistive technologies.

    Supported Conformance Levels

    Conformance Level Conversion Validation
    PDF/A-1b, PDF/A-2b, PDF/A-3b Yes Yes
    PDF/A-1a, PDF/A-2a, PDF/A-3a No Yes
    PDF/UA-1 Yes Yes
    PDF/UA-2 No Yes

    Note

    If you pass an unsupported conformance level, ConvertToPdfA and ConvertToPdfUA methods do not modify the document and return a result with the ConversionStatus.Errors status. The result contains an issue with the ComplianceRule.UnsupportedConversionTarget rule.

    Convert a Document to PDF/A

    Call the PdfDocument.ConvertToPdfA method to convert a document to PDF/A. The conversion embeds fonts, adds an output intent if the document uses device colors, and removes content that the standard does not allow (for example, encryption, JavaScript actions, and XFA forms). The ConvertToPdfA method also declares the conformance level in XMP metadata.

    The ConvertToPdfA method modifies the document in memory. Call the PdfDocument.Save(stream) method to save the converted document.

    The following code snippet converts a PDF document to PDF/A-3b, displays conversion issues, and saves the converted document:

    using System;
    using System.IO;
    using DevExpress.Docs.Pdf;
    
    using var inputStream = File.OpenRead("Document.pdf");
    using var document = new PdfDocument(inputStream);
    
    var result = document.ConvertToPdfA(PdfACompatibility.PdfA3b);
    Console.WriteLine($"Conversion status: {result.Status}");
    foreach (var issue in result.Issues)
        Console.WriteLine($"{issue.Severity} ({issue.Rule}): {issue.Message}");
    
    if (result.Status != ConversionStatus.Errors) {
        Directory.CreateDirectory("output");
        using var outputStream = File.Create(Path.Combine("output", "Document.pdf"));
        document.Save(outputStream);
    }
    

    Note

    After conversion, the PdfDocument.Save method rewrites the whole document. If the document contains digital signatures, the signatures become invalid.

    Embedded Files

    The target conformance level determines how the ConvertToPdfA method processes embedded files (PdfDocument.Attachments):

    Conformance Level Embedded Files
    PDF/A-1b The ConvertToPdfA method removes embedded files and reports the EmbeddedFilesRemoved warning.
    PDF/A-2b The ConvertToPdfA method keeps embedded files. The API cannot verify that embedded files conform to PDF/A and reports the EmbeddedFilesNotValidated error.
    PDF/A-3b The ConvertToPdfA method keeps embedded files of any type (for example, the XML file of a ZUGFeRD invoice).

    Convert a Document to PDF/UA

    Call the PdfDocument.ConvertToPdfUA method to convert a document to PDF/UA-1. The conversion includes the following changes:

    • Marks the document as tagged (PdfDocument.MarkInfo) and enables the ViewerPreferences.DisplayDocTitle setting.
    • Adds missing descriptions of link annotations (link URIs) and missing alternate names of form fields (field names).
    • Embeds missing fonts.
    • Removes XFA form data.
    • Adds an output intent if the document does not contain a PDF/A output intent.
    • Declares the conformance level in XMP metadata.

    Important

    The ConvertToPdfUA method does not create a structure tree, does not tag page content, and does not modify the annotation tab order (Page.TabOrder). The Success conversion status does not mean that the document meets PDF/UA requirements. Tag the document and specify DocumentInfo.Title and PdfDocument.LanguageCulture properties before conversion. After conversion, call the PdfDocument.ValidatePdfUA method to check PDF/UA conformance.

    The following code snippet specifies the document title and language, converts a tagged PDF document to PDF/UA-1, displays compliance issues that remain after conversion, and saves the document if it conforms to PDF/UA-1:

    using System;
    using System.Globalization;
    using System.IO;
    using DevExpress.Docs.Pdf;
    
    using var inputStream = File.OpenRead("Document.pdf");
    using var document = new PdfDocument(inputStream);
    
    // Specify the document title and language that PDF/UA requires.
    document.Metadata.DocumentInfo.Title = "Annual Report";
    document.LanguageCulture = new CultureInfo("en-US");
    
    var conversion = document.ConvertToPdfUA(PdfUACompatibility.PdfUA1);
    Console.WriteLine($"Conversion status: {conversion.Status}");
    
    // Check whether the converted document conforms to PDF/UA-1.
    var validation = document.ValidatePdfUA(PdfUACompatibility.PdfUA1);
    foreach (var issue in validation.Issues)
        Console.WriteLine($"{issue.Severity} ({issue.Rule}): {issue.Message}");
    
    if (validation.IsValid) {
        Directory.CreateDirectory("output");
        using var outputStream = File.Create(Path.Combine("output", "Document.pdf"));
        document.Save(outputStream);
    }
    

    Refer to the following help topic for additional information: Generate and Edit Tagged PDF Documents.

    Conform to PDF/A and PDF/UA

    A document can conform to both PDF/A and PDF/UA. To create a document that conforms to both standards, do the following:

    1. Call the ConvertToPdfUA method.
    2. Call the ConvertToPdfA method for the same document.

    Analyze Conversion Results

    Conversion methods return a ConversionResult object. Use the ConversionResult.Status property to get the conversion status:

    Status Description
    Success The conversion completed without warnings or errors.
    Warnings The conversion completed with warnings. The document content can differ from the original content.
    Errors The conversion completed with errors. The document does not conform to the target standard.

    The status corresponds to the most severe issue in conversion results. Issues with the Information severity do not affect the status.

    Use the ConversionResult.Issues property to get changes that the conversion made and issues that the conversion cannot fix. Each issue is a ComplianceIssue object. Use the following properties to get issue details:

    Property Description
    Rule Gets the compliance rule that the issue relates to.
    Severity Gets the severity of the compliance issue.
    Message Gets the compliance issue description.
    PageIndex Gets the index of the page that the compliance issue relates to.

    ComplianceRule lists rules that conversion and validation methods report.

    Validate a Document

    Call the PdfDocument.ValidatePdfA or PdfDocument.ValidatePdfUA method to check whether a document conforms to the specified conformance level. Both methods return a ValidationResult object. Use the following properties to get the validation result:

    Property Description
    IsValid Gets whether the document conforms to the target standard.
    Issues Gets compliance issues that validation found.

    Note

    The IsValid property gets false if the Issues collection contains an issue with the Error severity. Warnings and information messages do not affect the IsValid property value.

    Validation methods check the file that the PdfDocument.Save(stream) method writes, including pending changes. For PDF/A-1a, PDF/A-2a, and PDF/A-3a conformance levels, the ValidatePdfA method also checks whether the document is tagged and validates the document structure tree.

    Validation methods also check the conformance level declared in XMP metadata. If the document does not declare a conformance level, the validation result contains the ConformanceClaimMissing error. If the declared level differs from the target conformance level, the validation result contains the ConformanceClaimMismatch error.

    The following code snippet validates a PDF document against PDF/A-2b and displays compliance issues:

    using System;
    using System.IO;
    using DevExpress.Docs.Pdf;
    
    using var inputStream = File.OpenRead("Document.pdf");
    using var document = new PdfDocument(inputStream);
    
    var result = document.ValidatePdfA(PdfACompatibility.PdfA2b);
    Console.WriteLine(result.IsValid
        ? "The document conforms to PDF/A-2b."
        : "The document does not conform to PDF/A-2b.");
    foreach (var issue in result.Issues)
        Console.WriteLine($"{issue.Severity} ({issue.Rule}): {issue.Message}");
    

    Validation Options

    If you load a document from a stream and the document contains signatures, the PdfDocument.Save method appends changes to the source file as an incremental update. Validation methods check this incremental update.

    To validate the document as a fully rewritten file, do the following:

    1. Create a ValidationOptions object and set the ValidationOptions.ForcePreProcessing property to true.
    2. Pass the object to the PdfDocument.ValidatePdfA or PdfDocument.ValidatePdfUA method.

    Warning

    After validation with the ForcePreProcessing property set to true, the PdfDocument.Save method rewrites the whole document. A full rewrite invalidates existing signatures.

    The following code snippet validates a PDF document against PDF/A-2b as a fully rewritten file and saves the document if it conforms to PDF/A-2b:

    using System;
    using System.IO;
    using DevExpress.Docs.Pdf;
    
    using var inputStream = File.OpenRead("Document.pdf");
    using var document = new PdfDocument(inputStream);
    
    var options = new ValidationOptions { ForcePreProcessing = true };
    var result = document.ValidatePdfA(PdfACompatibility.PdfA2b, options);
    foreach (var issue in result.Issues)
        Console.WriteLine($"{issue.Severity} ({issue.Rule}): {issue.Message}");
    
    if (result.IsValid) {
        Directory.CreateDirectory("output");
        using var outputStream = File.Create(Path.Combine("output", "Document.pdf"));
        document.Save(outputStream);
    }
    

    Output Intents

    An output intent (OutputIntent) specifies an ICC profile and color characteristics of the output device or production condition. A PDF/A document that uses device colors (DeviceRGB, DeviceCMYK, or DeviceGray) requires an output intent.

    Conversion methods add output intents as follows:

    • The PdfDocument.ConvertToPdfUA method adds an output intent with the sRGB IEC61966-2.1 profile if the document does not contain a PDF/A output intent.
    • The PdfDocument.ConvertToPdfA method adds an output intent if the document uses device colors and does not contain a PDF/A output intent. The output intent contains a CMYK profile (CGATS21_CRPC1) if the document uses only CMYK colors. Otherwise, the output intent contains the sRGB IEC61966-2.1 profile.

    Use the PdfDocument.OutputIntents property to access output intents of a document.

    The following code snippet converts a PDF document to PDF/A-2b and displays the subtype, output condition identifier, and number of color components of each output intent in the converted document:

    using System;
    using System.IO;
    using DevExpress.Docs.Pdf;
    
    using var inputStream = File.OpenRead("Document.pdf");
    using var document = new PdfDocument(inputStream);
    
    document.ConvertToPdfA(PdfACompatibility.PdfA2b);
    foreach (var intent in document.OutputIntents)
        Console.WriteLine($"{intent.Subtype}: {intent.OutputConditionIdentifier}, {intent.ComponentsCount} color components");
    

    Declare Conformance without Conversion

    DocumentMetadata.SetPdfACompatibility and DocumentMetadata.SetPdfUACompatibility methods declare the conformance level in XMP metadata and do not modify document content. Call the SetPdfACompatibility or SetPdfUACompatibility method if the document already meets the standard requirements (for example, if you create a tagged document in code). Then, call a validation method to check conformance.

    Refer to the following help topic for additional information: Specify Basic and XMP Metadata.