> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/get-started/samples/pdfatest.md).

# PDF/A

Convert PDF to PDF/A format using Obj-C. All you need is full API enabled in WebViewer to validare pdf/a js. it supports all versions of PDF/A

Sample Obj-C code for using Apryse SDK to programmatically convert generic PDF documents into ISO-compliant, VeraPDF-valid PDF/A files, or to validate PDF/A compliance. Supports all three PDF/A parts (PDF/A-1, PDF/A-2, PDF/A-3), and covers all conformance levels (A, B, U). Learn more about our [iOS SDK](/ios/guides.md) and [PDF/A Library](/core/pdf-a/pdfa.md). A command-line tool for batch conversion and validation is also available.

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#import <OBJC/PDFNetOBJC.h>
#import <Foundation/Foundation.h>

void PrintResults(PTPDFACompliance *pdf_a, NSString *filename) {
    unsigned long err_cnt = [pdf_a GetErrorCount];
    if (err_cnt == 0) 
    {
        NSLog(@"%@: OK.", filename);
    }
    else 
    {
        NSLog(@"%@ is NOT a valid PDFA.", filename);
        int i = 0;
        for (; i<err_cnt; ++i) 
        {
            int c = [pdf_a GetError: i];
            NSLog(@" - e_PDFA %d: %@.", c, [PTPDFACompliance GetPDFAErrorMessage: c]);
            if (true) 
            {
                unsigned long num_refs = [pdf_a GetRefObjCount: c];
                if (num_refs > 0)  
                {
                    NSString *str = @"   Objects: ";
                    int j=0;
                    for (; j<num_refs; ++j) 
                    {
                        str = [str stringByAppendingFormat: @"%lu", [pdf_a GetRefObj: c err_idx: j]];
                        if (j<num_refs-1) 
                            str = [str stringByAppendingString: @", "];
                    }
                    NSLog(@"%@", str);
                }
            }
        }
        NSLog(@"\n");
    }
}

//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//    PDFA standard, using the PTPDFACompliance class object. 
//---------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
    @autoreleasepool {    
       
        int ret = 0;
        
        [PTPDFNet Initialize: 0];
        [PTPDFNet SetColorManagement: e_ptlcms];  // Enable color management (required for PDFA validation).

        //-----------------------------------------------------------
        // Example 1: PDF/A Validation
        //-----------------------------------------------------------
        @try
        {
            NSString *filename = @"newsletter.pdf";
            // The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
            // of object numbers that are collected for particular error codes. The default value is 10 
            // in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
            PTPDFACompliance *pdf_a = [[PTPDFACompliance alloc] initWithConvert: NO file_path: @"../../TestFiles/newsletter.pdf" password: @"" conf: e_ptLevel2B exceptions: 0 num_exceptions: 10 max_ref_objs: 10 first_stop: NO];
            PrintResults(pdf_a, filename);
        }
        @catch (NSException *e)
        {
            NSLog(@"%@", e.reason);
            ret = 1;
        }

        //-----------------------------------------------------------
        // Example 2: PDF/A Conversion
        //-----------------------------------------------------------
        @try
        {
            NSString *filename = @"fish.pdf";
            PTPDFACompliance *pdf_a = [[PTPDFACompliance alloc] initWithConvert: YES file_path: @"../../TestFiles/fish.pdf" password: @"" conf: e_ptLevel2B exceptions: 0 num_exceptions: 10 max_ref_objs: 10 first_stop: NO];
            filename = @"../../TestFiles/Output/pdfa.pdf";
            [pdf_a SaveAsFile: filename linearized: NO];

            // Re-validate the document after the conversion...
            PTPDFACompliance *comp =[[PTPDFACompliance alloc] initWithConvert: NO file_path: filename password: @"" conf: e_ptLevel2B exceptions: 0 num_exceptions: 10 max_ref_objs: 10 first_stop: NO];
            filename = @"pdfa.pdf";
            PrintResults(comp, filename);
        }
        @catch (NSException *e)
        {
            NSLog(@"%@", e.reason);
            ret = 1;
        }

        NSLog(@"PDFACompliance test completed.");
        [PTPDFNet Terminate: 0];
        return ret;
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import PDFNet
import Foundation

func PrintResults(pdf_a: PTPDFACompliance, filename: String) {
    let err_cnt: UInt = pdf_a.getErrorCount()
    if err_cnt == 0 {
        print("\(filename) OK.")
    }
    else {
        print("\(filename) is NOT a valid PDFA.")
        
        for i in 0..<err_cnt {
            let c = pdf_a.getError(i)
            print(" - e_PDFA \(c.rawValue): \(PTPDFACompliance.getPDFAErrorMessage(c)!).")
            if true {
                let num_refs: UInt = pdf_a.getRefObjCount(c)
                if num_refs > 0 {
                    print("   Objects:")
                    var str = ""
                    
                    for j in 0..<num_refs {
                        str = str + ("\(pdf_a.getRefObj(c, err_idx: j))")
                        if j < num_refs - 1 {
                            str = str + (", ")
                        }
                    }
                    print("\(str)")
                }
            }
        }
    }
}

//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//    PDFA standard, using the PTPDFACompliance class object.
//---------------------------------------------------------------------------------------
func runPDFATest() -> Int {
    return autoreleasepool {
        var ret = 0
        
        
        PTPDFNet.setColorManagement(e_ptlcms)
        
        // Enable color management (required for PDFA validation).
        //-----------------------------------------------------------
        // Example 1: PDF/A Validation
        //-----------------------------------------------------------
        do {
            try PTPDFNet.catchException {
                let filename = "newsletter.pdf"
                let pdf_a: PTPDFACompliance = PTPDFACompliance(convert: false, file_path: Bundle.main.path(forResource: "newsletter", ofType: "pdf"), password: "", conf: e_ptLevel1B, exceptions: 0, num_exceptions: 10, max_ref_objs: 10, first_stop: false)
                PrintResults(pdf_a: pdf_a, filename: filename)
            }
        } catch let e as NSError {
            print("\(e)")
            ret = 1
        }
        
        //-----------------------------------------------------------
        // Example 2: PDF/A Conversion
        //-----------------------------------------------------------
        do {
            try PTPDFNet.catchException {
                var filename = "fish.pdf"
                let pdf_a: PTPDFACompliance = PTPDFACompliance(convert: true, file_path: Bundle.main.path(forResource: "fish", ofType: "pdf"), password: "", conf: e_ptLevel1B, exceptions: 0, num_exceptions: 10, max_ref_objs: 10, first_stop: false)
                filename = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("pdfa.pdf").path
                pdf_a.save(asFile: filename, linearized: true)
                
                // Re-validate the document after the conversion...
                let comp: PTPDFACompliance = PTPDFACompliance(convert: false, file_path: filename, password: "", conf: e_ptLevel1B, exceptions: 0, num_exceptions: 10, max_ref_objs: 10, first_stop: false)
                PrintResults(pdf_a: comp, filename: filename)
            }
        } catch let e as NSError {
            print("\(e)")
            ret = 1
        }
        
        print("PTPDFACompliance test completed.")
        return ret
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/get-started/samples/pdfatest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
