> 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/uwp/get-started/samples/pdfatest.md).

# PDF/A

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

Sample 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 [UWP SDK](/core/get-started/frameworks/dotnet.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="C#" %}
{% code lineNumbers="true" %}

```csharp
//
// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
//

using System;
using System.IO;
using System.Threading.Tasks;
using Windows.Foundation;

using pdftron;
using pdftron.PDF;
using pdftron.PDF.PDFA;
using pdftron.SDF;

using PDFNetUniversalSamples.ViewModels;

namespace PDFNetSamples
{
    public sealed class PDFATest : Sample
    {
        public PDFATest() :
            base("PDF/A", "This sample illustrates how to use PDF/A add-on to validate existing PDF documents for PDF/A compliance as well as to convert generic PDF documents to PDF/A format.")
        {
        }

        public override IAsyncAction RunAsync()
        {
            return Task.Run(new System.Action(async () =>
            {
                WriteLine("--------------------------------");
                WriteLine("Starting PDF/A Test...");
                WriteLine("--------------------------------\n");
			
                PDFNet.SetColorManagement(CMSType.e_lcms);  // Required for PDFA validation.

			    //-----------------------------------------------------------
			    // Example 1: PDF/A Validation
			    //-----------------------------------------------------------
			    try
			    {
				    string filename = Path.Combine(InputPath, "newsletter.pdf");
				    PDFACompliance pdf_a = new PDFACompliance(false, filename, "", PDFAComplianceConformance.e_Level1B, null, 10, false);
				    PrintResults(pdf_a, filename);
			    }
			    catch (Exception e)
			    {
				    WriteLine(GetExceptionMessage(e));
			    }

			    //-----------------------------------------------------------
			    // Example 2: PDF/A Conversion
			    //-----------------------------------------------------------
			    try
			    {
				    string filename = Path.Combine(InputPath, "fish.pdf");
                    PDFACompliance pdf_a = new PDFACompliance(true, filename, "", PDFAComplianceConformance.e_Level1B, null, 10, false);
				    filename = Path.Combine(OutputPath, "pdfa.pdf");
				    pdf_a.SaveAs(filename, true);
                    WriteLine("Saved PDF/A converted doc to" + filename);
                    await AddFileToOutputList(filename).ConfigureAwait(false);

				    // Re-validate the document after the conversion...
				    pdf_a = new PDFACompliance(false, filename, "", PDFAComplianceConformance.e_Level1B, null, 10, false);
				    PrintResults(pdf_a, filename);				
			    }
			    catch (Exception e)
			    {
				    WriteLine(GetExceptionMessage(e));
                }

                WriteLine("\n--------------------------------");
                WriteLine("Done PDF/A Test.");
                WriteLine("--------------------------------\n");
            })).AsAsyncAction();
		}

        void PrintResults(PDFACompliance pdf_a, String filename) 
		{
			int err_cnt = pdf_a.GetErrorCount();
			if (err_cnt == 0) 
			{
                WriteLine(string.Format("{0}: OK.", filename));
			}
			else 
			{
                WriteLine(string.Format("{0} is NOT a valid PDFA.", filename));
				for (int i=0; i<err_cnt; ++i) 
				{
					PDFAComplianceErrorCode c = pdf_a.GetError(i);
					WriteLine(string.Format(" - e_PDFA{0}: {1}.", c, PDFACompliance.GetPDFAErrorMessage(c)));

					if (true) 
					{
						int num_refs = pdf_a.GetRefObjCount(c);
						if (num_refs > 0)  
						{
							Write("   Objects:");
							for (int j=0; j<num_refs; ) 
							{
                                Write(string.Format("{0}", pdf_a.GetRefObj(c, j)));
                                if (++j != num_refs) Write(", ");
							}
                            WriteLine("");
						}
					}
				}
			}
		}
	}
}
```

{% 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/uwp/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.
