1. Home
  2. /
  3. GroupDocs.Conversion.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Using PDF to PDF/A Converter

Using PDF to PDF/A Converter

This topic shows how to use the PdfToPdfAConverter with examples that demonstrate common use cases for converting PDF files to PDF/A (Archive).

Prerequisites

Refer to the Developer Guide to learn how to set up your environment and run code examples in this section.

You can also check two related topics on Loading Source Documents and Saving Converted Documents to learn how to specify intput and output documents.

Basic Example

The following example shows the most common use case for converting PDF document to PDF/A. The source PDF file is loaded from a current folder. The converted file is saved to the same folder.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Create a converter for the PDF file
var converter = new PdfToPdfAConverter("business-plan.pdf");

// Convert PDF to PDF/A
converter.Convert("archived.pdf");
Imports System
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Create a converter from file path
        Dim converter As New PdfToPdfAConverter("business-plan.pdf")

        ' Convert PDF to PDF/A
        converter.Convert("archived.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Create a converter from file path
    let converter = new PdfToPdfAConverter("business-plan.pdf")

    // Convert PDF to PDF/A
    converter.Convert("archived.pdf")
    0

Sample input file: Download business-plan.pdf

Expected output: Download archived.pdf

PDF Load Options

This section covers only the main scenarious you also reffer to the API references for the PdfLoadOptions for a complete list of options that you can specify.

Convert Protected PDF to PDF/A

The following example shows how to convert protected PDF file and save it to unprotected PDF/A file.

In case you do not specify password for protected document PasswordRequiredException is going to be thrown.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Provide password through load options
var converter = new PdfToPdfAConverter("protected.pdf", options =>
{
    options.Password = "12345";
});

// Convert PDF to PDF/A
converter.Convert("not-protected.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Provide password through load options
        Dim converter As New PdfToPdfAConverter("protected.pdf", Sub(options)
            options.Password = "12345"
        End Sub)

        ' Convert PDF to PDF/A
        converter.Convert("not-protected.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Provide password through load options
    let converter = new PdfToPdfAConverter("protected.pdf", fun options ->
        options.Password <- "12345"
    )
    
    // Convert PDF to PDF/A
    converter.Convert("not-protected.pdf")
    0

Sample input: Download protected.pdf (Password: 12345)

Flatten Fields in Form-Fillable PDF

The following example shows how to convert a form‑fillable PDF into static content by flattening form fields.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Hide tracked changes through load options
var converter = new PdfToPdfAConverter("form-fields.pdf", options =>
{
    options.FlattenAllFields = true;
});

// Convert PDF to PDF/A
converter.Convert("flattened.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Hide tracked changes through load options
        Dim converter As New PdfToPdfAConverter("form-fields.pdf", Sub(options)
            options.FlattenAllFields = True
        End Sub)

        ' Convert PDF to PDF/A
        converter.Convert("flattened.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Hide tracked changes through load options
    let converter = new PdfToPdfAConverter("form-fields.pdf", fun options ->
        options.FlattenAllFields <- true
    )

    // Convert PDF to PDF/A
    converter.Convert("flattened.pdf")
    0

Sample input: Download form-fields.pdf (Fillable PDF)

Expected output: Download flattened.pdf

Convert PDF with Annotations to PDF/A without Annotations

By default, annotations are added to the output PDF file, see this with-annotations.pdf (text HOME BASED PROFESSIONAL SERVICES is highlighted) as an example of PDF file with annotations.

The following example shows how to convert a PDF file that contains annotations and save a PDF/A file without annotations.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Hide annotations using HidePdfAnnotations
var converter = new PdfToPdfAConverter("with-annotations.pdf", options =>
{
    options.HidePdfAnnotations = true;
});

// Convert PDF to PDF/A
converter.Convert("no-annotations.pdf");
Imports System
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey As String = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey As String = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Hide annotations using HidePdfAnnotations
        Dim converter As New PdfToPdfAConverter("with-annotations.pdf", Sub(options)
                                                                             options.HidePdfAnnotations = True
                                                                         End Sub)

        ' Convert PDF to PDF/A
        converter.Convert("no-annotations.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main argv =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Hide annotations using HidePdfAnnotations
    let converter = 
        new PdfToPdfAConverter("with-annotations.pdf", fun options ->
            options.HidePdfAnnotations <- true
        )

    // Convert PDF to PDF/A
    converter.Convert("no-annotations.pdf")

    0 // return an integer exit code

Sample input: Download with-annotations.pdf (Contains highlight annotations)

Expected output: Download no-annotations.pdf (Comments hidden)

PDF Convert Options

The examples in this section shows how you can adjust the output using PdfConvertOptions.

Convert Specific PDF Pages to PDF/A

To convert only a portion of the document instead of all pages. You can specify which pages to include in the output PDF using the Pages property of PdfConvertOptions class.

As an alternative you can use PageNumber to specify the page number to start conversion from and PagesCount to set number of pages to convert starting from PageNumber.

The following example shows how to convert the first three pages of a PDF file to PDF/A:

using System;
using System.Collections.Generic;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new PdfToPdfAConverter("business-plan.pdf");

// Save first three pages to PDF/A
converter.Convert("pages-1-2-3.pdf", (convertOptions) => {
    convertOptions.Pages = new List<int> { 1, 2, 3 };
});
Imports System
Imports System.Collections.Generic
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey As String = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey As String = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New PdfToPdfAConverter("business-plan.pdf")

        ' Save first three pages to PDF/A
        converter.Convert("pages-1-2-3.pdf", Sub(convertOptions)
                                                convertOptions.Pages = New List(Of Integer) From {1, 2, 3}
                                            End Sub)
    End Sub
End Module
open System
open System.Collections.Generic
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main argv =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new PdfToPdfAConverter("business-plan.pdf")

    // Save first three pages to PDF/A
    converter.Convert("pages-1-2-3.pdf", fun convertOptions ->
        convertOptions.Pages <- List<int>([1; 2; 3])
    )

    0 // return exit code

Expected output: Download pages-1-2-3.pdf

Convert PDF to Password-Protected PDF/A

You can protect the output PDF with a password by setting the Password property in PdfConvertOptions class.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new PdfToPdfAConverter("business-plan.pdf");

// Convert to password-protected PDF
converter.Convert("protected.pdf", convertOptions =>
{
    convertOptions.Password = "12345";
});
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New PdfToPdfAConverter("business-plan.pdf")

        ' Convert to password-protected PDF
        converter.Convert("protected.pdf", Sub(convertOptions)
            convertOptions.Password = "12345"
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new PdfToPdfAConverter("business-plan.pdf")

    // Convert to password-protected PDF
    converter.Convert("protected.pdf", fun convertOptions ->
        convertOptions.Password <- "12345"
    )

    0

Expected output: Download protected.pdf (Password: 12345)