Click or drag to resize
Pdf Library for .NET

Validate Pdf Documents against PDF/A, PDF/UA and PDF/X

SelectPdf PDF Library for .NET can check whether an existing PDF document conforms to a standard: PDF/A (archiving, parts 1 to 4), PDF/UA (accessibility, parts 1 and 2) and PDF/X (print exchange: PDF/X-1a, PDF/X-3 and PDF/X-4). Every rule of the standard is checked and each object that fails one is reported, with the rule, what it requires, why the object fails it and where the object is. The document is only read, never changed.

Validation is done with PdfValidator:

The report
  • IsCompliant is true when every check passed and the validation was complete.

  • Failures lists the failed checks, each a RuleFailure: the rule (its specification, clause and test number), what the rule requires, why the object fails it, the object's place in the document as a path (document/pages[3]/annots[0]), its page and its object number. At most 100 failures are listed per rule by default; ChecksFailed counts them all.

  • Complete is false when the validation stopped early - at a time or size limit, or on a part of the file that could not be read. Such a report is never compliant: a check that was not made is not a check that passed.

The limits are set with ValidationOptions: the failures listed per rule and in all, and how long the validation may run, reading the file included (30 seconds by default). The memory a validation holds is limited too, to about 16 GB (1 GB in a 32-bit process, and no more than half the memory the process may use), so that a very large or hostile file ends as an incomplete report rather than taking the process's memory.

The rules

PDF/A and PDF/UA are checked with the validation profiles of the veraPDF project, the reference for these standards; the results agree with veraPDF's on its test corpora. PDF/X is checked with rules written from the public descriptions of ISO 15930. The version of the rules is in ProfilesVersion.

Example
byte[] pdf = File.ReadAllBytes("document.pdf");

ValidationReport report = PdfValidator.Validate(pdf, null,
    PdfConformanceStandard.PdfA2B);

if (report.IsCompliant)
{
    Console.WriteLine("The document conforms to PDF/A-2b.");
}
else
{
    if (!report.Complete)
        Console.WriteLine("The validation did not complete.");
    foreach (RuleFailure failure in report.Failures)
        Console.WriteLine(failure.Rule + ": " + failure.Message
            + " (" + failure.Context + ")");
}

To check a document against the standard it claims:

PdfConformanceStandard? claimed = PdfValidator.ClaimedStandard(pdf, null);
if (claimed != null)
{
    ValidationReport report = PdfValidator.Validate(pdf, null, claimed.Value);
    Console.WriteLine(claimed + ": " + (report.IsCompliant ? "yes" : "no"));
}
See Also