Some test text!

menu
search
chevron_right .NET Framework samples

Convert PDF to PDF/A in VB

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

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

'---------------------------------------------------------------------------------------
' Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
' Consult legal.txt regarding legal and license information.     
'---------------------------------------------------------------------------------------
Imports System

Imports PDFTRON
Imports PDFTRON.PDF
Imports PDFTRON.PDF.PDFA

'-----------------------------------------------------------------------------------
' The sample illustrates how to use PDF/A related API-s.
'-----------------------------------------------------------------------------------

Module mainModule
    Dim pdfNetLoader As PDFNetLoader
	Sub New()
		pdfNetLoader = pdftron.PDFNetLoader.Instance()
	End Sub

    ' The main entry point for the application.
    Sub Main()

        PDFNet.Initialize()
        PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms) 'Required for PDFA validation.

        'Relative path to the folder containing test files.
        Dim input_path As String = "../../../../TestFiles/"
        Dim filename As String = "newsletter.pdf"
        Dim output_path As String = "../../../../TestFiles/Output/"


        '//-----------------------------------------------------------
        '// Example 1: PDF/A Validation
        '//-----------------------------------------------------------
        Try
            filename = "newsletter.pdf"
            Dim pdf_a As PDFACompliance = New PDFACompliance(False, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level1B, Nothing, 10, False)
            PrintResults(pdf_a, filename)
            pdf_a.Dispose()
        Catch e As PDFTRON.Common.PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '//-----------------------------------------------------------
        '// Example 2: PDF/A Conversion
        '//-----------------------------------------------------------
        Try
            filename = "fish.pdf"
            Using pdf_a As PDFACompliance = New PDFACompliance(True, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level1B, Nothing, 10, False)
                filename = "pdfa.pdf"
                pdf_a.SaveAs(output_path + filename, True)
            End Using

            '// Re-validate the document after the conversion...
            filename = "pdfa.pdf"
            Using pdf_a As PDFACompliance = New PDFACompliance(False, output_path + filename, Nothing, PDFACompliance.Conformance.e_Level1B, Nothing, 10, False)
                PrintResults(pdf_a, filename)
            End Using
        Catch e As pdftron.Common.PDFNetException
            Console.WriteLine(e.Message)
        End Try
        Console.WriteLine("PDFACompliance test completed.")
    End Sub

    Function PrintResults(ByRef pdf_a As PDFACompliance, ByVal filename As String) As Int32
        PrintResults = 0
        Dim err_cnt As Int32 = pdf_a.GetErrorCount()
        If err_cnt = 0 Then
            Console.WriteLine("{0}: OK.", filename)
        Else
            Dim i As Int32
            Console.WriteLine("{0} is NOT a valid PDFA.", filename)
            For i = 0 To err_cnt - 1 Step 1
                Dim c As PDFACompliance.ErrorCode = pdf_a.GetError(i)
                Console.WriteLine(" - e_PDFA {0}: {1}.", Int(c), PDFACompliance.GetPDFAErrorMessage(c))
                If True Then
                    Dim num_refs As Int32 = pdf_a.GetRefObjCount(c)
                    If num_refs > 0 Then
                        Console.Write("   Objects: ")
                        Dim j As Int32
                        For j = 0 To num_refs - 1 Step 1
                            Console.Write("{0}", pdf_a.GetRefObj(c, j))
                            If Not (j + 1) = num_refs Then
                                Console.Write(", ")
                            End If
                        Next j
                        Console.WriteLine()
                    End If
                End If
            Next i
            Console.WriteLine()
        End If
    End Function

End Module
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.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close