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

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

PDF/A is an ISO-standardized version of the Portable Document Format (PDF) specialized for use in the archiving and long-term preservation of electronic documents.
PDF/A differs from PDF by prohibiting features ill-suited to long-term archiving, such as font linking (as opposed to font embedding) and encryption. The ISO requirements for PDF/A file viewers include color management guidelines, support for embedded fonts, and a user interface for reading embedded annotations.


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_A
            };
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)
        {
            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/examples/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_A
            };

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

            // Open the result for demonstation 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

    ''' <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/examples/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_A}

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

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

Download.

© SautinSoft 2002 - 2018