How to create a PDF/A Compliance document in C# and .NET

  1. Add SautinSoft.Document from Nuget.
  2. Load/Create a document.
  3. Specify PDF/A compliance in pdf save options.
  4. Save the document as PDF.


Let's create a simple PDF document from a DOCX file. By the way, this code shows - how to load an existing document and save it as a PDF/A compliant version.


                PdfSaveOptions options = new PdfSaveOptions()
            {
                // PdfComliance supports: PDF/A, PDF/1.5, etc.
                Compliance = PdfCompliance.PDF_A1a
            };
If you need to load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, etc) and save it as a PDF/A compliant version, you need to point a path for this file:

                // Path to a loadable document.
            string loadPath = @"..\..\example.pdf";
            //string loadPath = @"..\..\example.html";
            //string loadPath = @"..\..\example.rtf";

As the result, you will get the fully compatible PDF/A document

Complete code

using System.IO;
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/

            LoadAndSaveAsPDFA();
        }
        
        /// <summary>
        /// Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it as a PDF/A compliant version. 
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-and-save-document-in-pdf-a-format-net-csharp-vb.php
        /// </remarks>
        public static void LoadAndSaveAsPDFA()
        {
            // Path to a loadable document.
            string loadPath = @"..\..\..\example.docx";

            DocumentCore dc = DocumentCore.Load(loadPath);

            PdfSaveOptions options = new PdfSaveOptions()
            {
                // PdfComliance supports: PDF/A, PDF/1.5, etc.
                Compliance = PdfCompliance.PDF_A1a
            };

            string savePath = Path.ChangeExtension(loadPath, ".pdf");
            dc.Save(savePath, options);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true });
        }
    }
}

Download

Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        LoadAndSaveAsPDFA()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it as a PDF/A compliant version. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/create-and-save-document-in-pdf-a-format-net-csharp-vb.php
    ''' </remarks>
    Sub LoadAndSaveAsPDFA()
        ' Path to a loadable document.
        Dim loadPath As String = "..\..\..\example.docx"

        Dim dc As DocumentCore = DocumentCore.Load(loadPath)

        Dim options As New PdfSaveOptions() With {.Compliance = PdfCompliance.PDF_A1a}

        Dim savePath As String = Path.ChangeExtension(loadPath, ".pdf")
        dc.Save(savePath, options)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(savePath) With {.UseShellExecute = True})
    End Sub
End Module

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.