VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfDocument Class / VerifyDocument Methods / VerifyDocument(PdfDocumentConformance,ProcessingState) Method
Syntax Remarks Example Requirements SeeAlso
In This Topic
    VerifyDocument(PdfDocumentConformance,ProcessingState) Method (PdfDocument)
    In This Topic
    Verifies the PDF document to conformance with the specified format.
    Syntax
    Remarks

    The method supports only the following formats: PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-1a, PDF/A-2a, PDF/A-3a, PDF/A-2u, PDF/A-3u, PDF/A-4, PDF/A-4e, PDF/A-4f.

    Example

    Here is an example that shows how to verify a PDF document to conformance with PDF/A-1b specification and show the detailed result of verification:

    
    ''' <summary>
    ''' Verifies a PDF document to conformance with PDF/A-1b specification and
    ''' shows the detailed result of verification.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    Public Shared Sub VerifyDocumentToPdfA1bDetailed(pdfFilename As String)
        ' open PDF document
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
            Using processingState As New Vintasoft.Imaging.Processing.ProcessingState()
                ' subscribe to the events for monitoring the progress and activated important triggers
                AddHandler processingState.Progress, New System.EventHandler(Of Vintasoft.Imaging.ProgressEventArgs)(AddressOf verifyProcessingState_Progress)
                AddHandler processingState.TriggerActivated, New System.EventHandler(Of Vintasoft.Imaging.Processing.TriggerActivatedEventArgs)(AddressOf verifyProcessingState_TriggerActivated)
                ' clear the count of important trigger activations
                _verifyActivatedTriggerCount = 0
    
                ' execute the verification
                Dim result As Vintasoft.Imaging.Processing.VerificationProfileResult = document.VerifyDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b, processingState)
                System.Console.WriteLine("finished.")
    
                ' output the verification result
    
                If result.IsPassed Then
                    System.Console.WriteLine("Document conforms to PDF/A-1b.")
                Else
                    System.Console.WriteLine("Document does not conform to PDF/A-1b:")
                    ' for each activated trigger
                    For Each command As Vintasoft.Imaging.Processing.IProcessingCommandInfo In result.ActivatedTriggers.Keys
                        ' output information about activated trigger
                        System.Console.WriteLine(String.Format("  {0} ({1} matches)", command, result.ActivatedTriggers(command).Count))
                    Next
                End If
            End Using
        End Using
    End Sub
    
    ''' <summary>
    ''' The count of trigger activations.
    ''' </summary>
    Shared _verifyActivatedTriggerCount As Integer
    
    ''' <summary>
    ''' Handles the TriggerActivated event of the ProcessingState.
    ''' </summary>
    Private Shared Sub verifyProcessingState_TriggerActivated(sender As Object, e As Vintasoft.Imaging.Processing.TriggerActivatedEventArgs)
        ' if important trigger is activated
        If e.ActivationResult.Severity = Vintasoft.Imaging.Processing.TriggerSeverity.Important Then
            ' increment the count of important trigger activations
            _verifyActivatedTriggerCount += 1
        End If
    End Sub
    
    ''' <summary>
    ''' Handles the Progress event of the ProcessingState.
    ''' </summary>
    Private Shared Sub verifyProcessingState_Progress(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
        System.Console.CursorLeft = 0
        If _verifyActivatedTriggerCount > 0 Then
            System.Console.Write(String.Format("Verification {0}%: {1} errors...", e.Progress, _verifyActivatedTriggerCount))
        Else
            System.Console.Write(String.Format("Verification {0}%...", e.Progress))
        End If
    End Sub
    
    
    
    /// <summary>
    /// Verifies a PDF document to conformance with PDF/A-1b specification and
    /// shows the detailed result of verification.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    public static void VerifyDocumentToPdfA1bDetailed(string pdfFilename)
    {
        // open PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            using (Vintasoft.Imaging.Processing.ProcessingState processingState = 
                new Vintasoft.Imaging.Processing.ProcessingState())
            {
                // subscribe to the events for monitoring the progress and activated important triggers
                processingState.Progress += new System.EventHandler<Vintasoft.Imaging.ProgressEventArgs>(
                    verifyProcessingState_Progress);
                processingState.TriggerActivated += new System.EventHandler<Vintasoft.Imaging.Processing.TriggerActivatedEventArgs>(
                    verifyProcessingState_TriggerActivated);
                // clear the count of important trigger activations
                _verifyActivatedTriggerCount = 0;
    
                // execute the verification
                Vintasoft.Imaging.Processing.VerificationProfileResult result =
                    document.VerifyDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b, processingState);
                System.Console.WriteLine("finished.");
    
                // output the verification result
    
                if (result.IsPassed)
                {
                    System.Console.WriteLine("Document conforms to PDF/A-1b.");
                }
                else
                {
                    System.Console.WriteLine("Document does not conform to PDF/A-1b:");
                    // for each activated trigger
                    foreach (Vintasoft.Imaging.Processing.IProcessingCommandInfo command in result.ActivatedTriggers.Keys)
                    {
                        // output information about activated trigger
                        System.Console.WriteLine(string.Format("  {0} ({1} matches)",
                            command,
                            result.ActivatedTriggers[command].Count));
                    }
                }
            }
        }
    }
    
    /// <summary>
    /// The count of trigger activations.
    /// </summary>
    static int _verifyActivatedTriggerCount;
    
    /// <summary>
    /// Handles the TriggerActivated event of the ProcessingState.
    /// </summary>
    static void verifyProcessingState_TriggerActivated(
        object sender,
        Vintasoft.Imaging.Processing.TriggerActivatedEventArgs e)
    {
        // if important trigger is activated
        if (e.ActivationResult.Severity == Vintasoft.Imaging.Processing.TriggerSeverity.Important)
            // increment the count of important trigger activations
            _verifyActivatedTriggerCount++;
    }
    
    /// <summary>
    /// Handles the Progress event of the ProcessingState.
    /// </summary>
    static void verifyProcessingState_Progress(object sender, Vintasoft.Imaging.ProgressEventArgs e)
    {
        System.Console.CursorLeft = 0;
        if (_verifyActivatedTriggerCount > 0)
            System.Console.Write(string.Format("Verification {0}%: {1} errors...", e.Progress, _verifyActivatedTriggerCount));
        else
            System.Console.Write(string.Format("Verification {0}%...", e.Progress));
    }
    
    

    Requirements

    Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also