Some test text!

menu

Convert PDF to PDF/A in Go

More languages

chevron_right
More languages
JavaScript
Java (Android)
C++
C#
C# (.NET Core)
Go
Java
Kotlin
Obj-C
JS (Node.js)
PHP
Python
Ruby
Swift
C# (UWP)
VB
C# (Xamarin)

Sample Go code for using PDFTron 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 Go PDF Library and PDF/A Library. A command-line tool for batch conversion and validation is also available.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	"strconv"
    . "pdftron"
)

//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//    PDFA standard, using the PDFACompliance class object. 
//---------------------------------------------------------------------------------------

func PrintResults(pdfa PDFACompliance, filename string){
    errCnt := pdfa.GetErrorCount()
    if errCnt == 0{
        fmt.Println(filename + ": OK.")
    }else{
        fmt.Println(filename + " is NOT a valid PDFA.")
        i := int64(0)
        for i < errCnt{
            c := pdfa.GetError(i)
            str1 := " - e_PDFA " + strconv.Itoa(int(c)) + ": " + PDFAComplianceGetPDFAErrorMessage(c) + "."
            if true{
                num_refs := pdfa.GetRefObjCount(c)
                if num_refs > int64(0){
                    str1 = str1 + "\n   Objects: "
                    j := int64(0)
                    for j < num_refs{
                        str1 = str1 + strconv.Itoa(int(pdfa.GetRefObj(c, j)))
                        if j < num_refs-1{
                            str1 = str1 + ", "
						}
                        j = j + 1
					}
				}
			}
            fmt.Println(str1)
            i = i + 1
		}
        fmt.Println("")
	}
}

func main(){
    // Relative path to the folder containing the test files.
    inputPath := "../../TestFiles/"
    outputPath := "../../TestFiles/Output/"
    
    PDFNetInitialize()
    PDFNetSetColorManagement()     // Enable color management (required for PDFA validation).
    
    //-----------------------------------------------------------
    // Example 1: PDF/A Validation
    //-----------------------------------------------------------
    filename := "newsletter.pdf"
	var cErrorCode PdftronPDFPDFAPDFAComplianceErrorCode
    // 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.
    pdfa := NewPDFACompliance(false, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    PrintResults(pdfa, filename)
    pdfa.Destroy()
    
    //-----------------------------------------------------------
    // Example 2: PDF/A Conversion
    //-----------------------------------------------------------
    filename = "fish.pdf"
    pdfa = NewPDFACompliance(true, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    filename = "pdfa.pdf"
    pdfa.SaveAs(outputPath + filename, false)
    pdfa.Destroy()
    
    // Re-validate the document after the conversion...
    pdfa = NewPDFACompliance(false, outputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    PrintResults(pdfa, filename)
    pdfa.Destroy()
	
    fmt.Println("PDFACompliance test completed.")
}
close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.