Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

PDF Standard Validation ​

Use validateStandardPDFWithType:basePath: of CPDFDocument to run a basic rule check of an opened document against a specified standard. The method returns a CPDFStandardValidationResult. Validation works on the document that is opened in memory, so to validate a conversion result, open the converted output file first and then validate it.

Supported Validation Targets

StandardformattypenumpartTypeStatus
PDF/A-1a, 1bCPDFStandardFormatPDFA1CPDFPartTypePDF_a, CPDFPartTypePDF_bStable
PDF/A-2a, 2u, 2b, PDF/A-3a, 3u, 3bCPDFStandardFormatPDFA2, 3CPDFPartTypePDF_a, CPDFPartTypePDF_u, CPDFPartTypePDF_bStable
PDF/E-1, E-2CPDFStandardFormatPDFE1, 2CPDFPartTypeNoneStable
PDF/X-1a, X-3, X-4CPDFStandardFormatPDFX1, 3, 4CPDFPartTypeNoneExperimental
PDF/UACPDFStandardFormatPDFUAIgnoredCPDFPartTypeNoneExperimental
PDF/VTCPDFStandardFormatPDFVTIgnored (checks the VT level the document declares)CPDFPartTypeNoneExperimental

basePath is the directory used to resolve externally referenced files. It is only used for PDF/X validation and can be nil.

The method returns nil in the following cases:

  • The document is not loaded.
  • The target standard is not in the table above.
  • The license does not include PDF/A conversion.

Validation Results

Properties of CPDFStandardValidationResult:

PropertyTypeDescription
passedBOOLWhether the document conforms to the validated standard.
detectedTypeCPDFStandardModeThe standard level the document declares; nil when validating PDF/E, PDF/UA, or PDF/VT.
issuesNSArray<CPDFStandardValidationIssue *>The list of issues found.

Properties of CPDFStandardValidationIssue:

PropertyTypeDescription
codeNSIntegerThe issue code reported by the core library.
ruleIdNSStringThe identifier of the violated rule, such as a clause of the standard. May be empty.
messageNSStringThe description of the issue.
pageIndexNSIntegerThe index of the page the issue belongs to; -1 means the issue applies to the whole document.
standardNameNSStringThe name of the standard the rule belongs to. May be empty.
severityCPDFStandardValidationSeverityThe severity of the issue.

Values of CPDFStandardValidationSeverity:

ValueDescription
CPDFStandardValidationSeverityErrorError. The document does not conform to the standard.
CPDFStandardValidationSeverityWarningWarning.
CPDFStandardValidationSeverityInfoInformational note.

"Converted" vs. "Passed Validation"

A successful conversion only means that a document of the target standard has been generated (converted). Whether the document conforms to the rules of the standard must be confirmed by calling the validation method (passed is YES when the document passes the basic validation). These are two different states, and we recommend showing them separately in your UI.

This example shows how to convert a document to PDF/A-2b, then validate the converted document and print the issues:

swift
let document = CPDFDocument(url: URL(fileURLWithPath: pdfPath))

let pdfA2b = CPDFStandardMode()
pdfA2b.format = .PDFA
pdfA2b.typenum = 2
pdfA2b.partType = .pdf_b

do {
    // 1. Convert to PDF/A-2b
    try document?.writeStandardPDF(toFilePath: savePath, withType: pdfA2b, iccFilePath: nil, with: nil, isSaveFontSubset: false, error: ())
} catch {
    print("Conversion failed: \((error as NSError).localizedFailureReason ?? "")")
    return
}

// 2. Open the converted document and validate it against PDF/A-2b
let convertedDocument = CPDFDocument(url: URL(fileURLWithPath: savePath))
guard let result = convertedDocument?.validateStandardPDF(withType: pdfA2b, basePath: nil) else {
    // The document is not loaded, the target is not supported, or the license does not include PDF/A conversion
    return
}

print("Passed: \(result.passed)")
for issue in result.issues {
    let level: String
    switch issue.severity {
    case .error:
        level = "Error"
    case .warning:
        level = "Warning"
    default:
        level = "Info"
    }
    // pageIndex -1 means a document-level issue
    let location = issue.pageIndex == -1 ? "Document" : "Page \(issue.pageIndex + 1)"
    print("[\(level)] \(location) \(issue.ruleId): \(issue.message)")
}
objective-c
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:pdfPath]];

CPDFStandardMode *pdfA2b = [[CPDFStandardMode alloc] init];
pdfA2b.format = CPDFStandardFormatPDFA;
pdfA2b.typenum = 2;
pdfA2b.partType = CPDFPartTypePDF_b;

// 1. Convert to PDF/A-2b
NSError *error = nil;
if (![document writeStandardPDFToFilePath:savePath
                                 withType:pdfA2b
                              iccFilePath:nil
                             withUAConfig:nil
                         isSaveFontSubset:NO
                                    error:&error]) {
    NSLog(@"Conversion failed: %@", error.localizedFailureReason);
    return;
}

// 2. Open the converted document and validate it against PDF/A-2b
CPDFDocument *convertedDocument = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:savePath]];
CPDFStandardValidationResult *result = [convertedDocument validateStandardPDFWithType:pdfA2b basePath:nil];
if (!result) {
    // The document is not loaded, the target is not supported, or the license does not include PDF/A conversion
    return;
}

NSLog(@"Passed: %d", result.passed);
for (CPDFStandardValidationIssue *issue in result.issues) {
    NSString *level = @"Info";
    if (issue.severity == CPDFStandardValidationSeverityError) {
        level = @"Error";
    } else if (issue.severity == CPDFStandardValidationSeverityWarning) {
        level = @"Warning";
    }
    // pageIndex -1 means a document-level issue
    NSString *location = issue.pageIndex == -1 ? @"Document" : [NSString stringWithFormat:@"Page %ld", (long)issue.pageIndex + 1];
    NSLog(@"[%@] %@ %@: %@", level, location, issue.ruleId, issue.message);
}

Note: Standard validation is a basic rule check. It is not a full compliance certification equivalent to a third-party professional validator. PDF/X, PDF/UA, and PDF/VT validation are experimental, and the results may be incomplete.