Verify(String,ProcessingState) Метод (PdfDocumentVerifier)
В этом разделе
Проверяет указанный PDF документ.
Синтаксис
Parameters
- filename
- Имя файла PDF документа.
- processingState
- Состояние обработки.
Return Value
Результат процесса проверки.
Пример
Вот пример, показывающий, как проверить 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)
Dim verifier As New Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bVerifier()
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 = verifier.Verify(pdfFilename, processingState)
' output the verification result
System.Console.WriteLine("finished.")
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 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 e.ActivationResult.Severity = Vintasoft.Imaging.Processing.TriggerSeverity.Important Then
_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)
{
Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bVerifier verifier =
new Vintasoft.Imaging.Pdf.Processing.PdfA.PdfA1bVerifier();
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 =
verifier.Verify(pdfFilename, processingState);
// output the verification result
System.Console.WriteLine("finished.");
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 (e.ActivationResult.Severity == Vintasoft.Imaging.Processing.TriggerSeverity.Important)
_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
Смотрите также