VerifyDocument(PdfDocumentConformance,ProcessingState) Метод (PdfDocument)
Проверяет соответствие PDF документа указанному формату.
Метод поддерживает только следующие форматы: PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-1a, PDF/A-2a, PDF/A- 3а, PDF/А-2у, PDF/А-3у, PDF/А-4, PDF/А-4е, PDF/А-4ф.
Вот пример, показывающий, как проверить PDF документ на соответствие спецификации PDF/A-1b, и показывающий подробный результат проверки:
''' <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));
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5