Validate PDF conformance
PDF conformance validation verifies that a document actually complies with the archival (PDF/A) or accessibility (PDF/UA) standard it claims. A document that carries a PDF/A or PDF/UA identifier in its metadata isn’t guaranteed to satisfy the standard — files produced by external tools, edited after conversion, or assembled from mixed sources often violate the requirements they declare.
Conformance validation is a common requirement in these workflows:
- Archive ingestion — Verifying documents before accepting them into long-term storage
- Compliance auditing — Checking existing document repositories against declared standards
- Conversion verification — Confirming the output of a PDF/A or PDF/UA conversion pipeline
- Accessibility programs — Testing documents against PDF/UA before publication
This sample demonstrates how to validate a PDF document against the conformance level it claims, and how to force validation against a specific conformance level.
Validating documents with our Python SDK
Developers can implement this feature by adding a few lines of code to their applications. The SDK validates all PDF/A conformance levels (PDF/A-1 through PDF/A-4) and PDF/UA-1 with a single API, and it produces a detailed report that lists every rule violation it finds.
Preparing the project
Import Nutrient Python SDK:
from nutrient_sdk import Documentfrom nutrient_sdk import PdfValidatorfrom nutrient_sdk import PdfValidationConformancefrom nutrient_sdk import NutrientExceptionLoading the PDF document
Use Python’s context manager(opens in a new tab) to enable proper lifecycle management of the document instance. The validator only accepts PDF documents; other formats aren’t converted implicitly:
def main(): try: with Document.open("input_pdfa_valid.pdf") as document:This path can be absolute or relative. This example loads the file from the application’s working directory.
Validating the claimed conformance
Create a validator instance bound to the document with PdfValidator.set(document), then call validate(). By default, the validator reads the conformance level the document claims in its metadata and validates against it:
validator = PdfValidator.set(document)
result = validator.validate() print(f"Document is valid: {result.is_valid}") print(f"Validated conformance: {result.validated_conformance}")
with open("report.xml", "w", encoding="utf-8") as report_file: report_file.write(result.report)The result carries three values:
is_valid— Whether the document complies with the conformance level it was validated against.validated_conformance— The conformance level the validation ran against. In automatic mode, this is the level detected from the document’s metadata.report— A detailed machine-readable XML report. When the document doesn’t comply, the report lists every problem found during validation.
If the document claims no PDF/A or PDF/UA conformance at all, no validation runs: the result reports the document as not valid, validated_conformance stays at PdfValidationConformance.AUTO, and the report explains that there was nothing to validate against.
Forcing a specific conformance level
To check a document against a standard it doesn’t claim — for example, to test whether an archival document is also accessible — set the conformance property before calling validate():
validator.conformance = PdfValidationConformance.PDF_UA1
ua_result = validator.validate() print(f"PDF/UA-1 conformant: {ua_result.is_valid}") except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()The sample document is a valid PDF/A file, so the forced PDF/UA-1 check reports it as not conformant — the accessibility standard imposes tagging and structure requirements that archival conformance doesn’t.
The PdfValidationConformance enumeration covers all supported validation targets:
- PDF/A-1 —
PDF_A1A,PDF_A1B - PDF/A-2 —
PDF_A2A,PDF_A2U,PDF_A2B - PDF/A-3 —
PDF_A3A,PDF_A3U,PDF_A3B - PDF/A-4 —
PDF_A4,PDF_A4E,PDF_A4F - PDF/UA-1 —
PDF_UA1 - Automatic —
AUTO(validates against the claimed conformance; this is the default)
Error handling
Nutrient Python SDK handles errors with exception handling. The methods presented in this guide raise a NutrientException if a failure occurs — for example, when the document isn’t a PDF or when it’s encrypted. This helps with troubleshooting and implementing error handling logic.
Conclusion
That’s all it takes to verify that a PDF document genuinely complies with the archival or accessibility standard it claims. To produce compliant documents from regular PDF files, refer to the PDF to PDF/A and PDF to PDF/UA guides. You can also download this ready-to-use sample package, which is configured to help you explore the Python SDK and conformance validation capabilities.