Skip to Content
NexPDF

PDF/A and PDF/UA validation

Validate PDF/A (every level from 1a to 4f) and PDF/UA-1 and -2 with clause ids, and convert to a chosen PDF/A level or to PDF/UA, with NexPDF for Android.

English

License module

Validation and conversion need the standards module (Enterprise tier).

NexPDF checks documents against the machine-checkable rules of PDF/A (ISO 19005-1 to -4) and PDF/UA (ISO 14289). Each failure names the clause of the standard that requires it, with the same numbers the veraPDF rule sets use.

Validate PDF/A

validatePdfaJson(level) takes 1a, 1b, 2a, 2b, 2u, 3a, 3b, 3u, 4, 4e or 4f (or PDF/A-2b). null uses the level the document declares, or 2b. It returns an empty string on failure, with the reason in NexPdfJni.lastError().

import com.nexdevit.nexpdf.NexPdfDocument
import com.nexdevit.nexpdf.NexPdfJni
import org.json.JSONObject

NexPdfDocument.openBytes(archive).use { doc ->
    val report = JSONObject(doc.validatePdfaJson("2b"))
    Log.i("NexPDF", "${report.getString("level")} ${if (report.getBoolean("compliant")) "compliant" else "not compliant"}")
    val failures = report.getJSONArray("failures")
    for (i in 0 until failures.length()) {
        val f = failures.getJSONObject(i)
        Log.i("NexPDF", "${f.getString("clause")} ${f.getString("message")} ${f.opt("page")} ${f.opt("object")}")
    }
}

Each failure has clause (such as 6.2.11.4.1), message, page (1-based, or null) and object (such as 12 0 R, or null).

The rules cover file structure, metadata (XMP, pdfaid, extension schemas), fonts (embedding, glyphs, widths, encodings), colour (output intents, ICC profiles), graphics and transparency, interactive features (annotations, actions, forms, embedded files) and, for level A, the tagged structure.

Validate PDF/UA

validatePdfuaJson() validates against the PDF/UA part the document declares, PDF/UA-1 by default. The report has the same shape, with level PDF/UA-1 or PDF/UA-2.

val ua = JSONObject(doc.validatePdfuaJson())
Log.i("NexPDF", "${ua.getString("level")} ${ua.getBoolean("compliant")} ${ua.getJSONArray("failures").length()}")

PDF/UA-1 follows the Matterhorn Protocol. PDF/UA-2 validation covers the PDF 2.0 namespaces (/NS, /RoleMapNS, the root /RoleMap, MathML), the ISO 14289-2 structure, annotation, form, destination and text-string rules, and the ISO/TS 32005 parent and child rules.

Convert to a level

convertPdfaLevel(level) converts to the level you choose (null is 2b). Level A tags the document first. It returns true when the result validates against the level. When some clauses still fail, it returns false: the fixes that could be made are kept, and NexPdfJni.lastError() lists the clauses that are left:

NexPdfDocument.openBytes(report).use { doc ->
    if (!doc.convertPdfaLevel("3a")) {
        Log.w("NexPDF", "still failing: ${NexPdfJni.lastError()}")   // the document keeps the fixes that worked
    }
    File(filesDir, "report-pdfa3a.pdf").writeBytes(doc.saveBytes())
}

Calls without a typed method

NexPdfJni has no typed method for these engine calls:

C functionDoes
validate_pdfua_part_json(doc, part)Validates against PDF/UA-1 (1) or PDF/UA-2 (2) whatever the document declares, with the same report
convert_pdfua_json(doc, part, lang)Converts to PDF/UA-1 or -2: tags an untagged document, embeds fonts; for part 2 uses the PDF 2.0 namespace, structure destinations and the annotation rules. lang (null or "" is en-US) applies when the document has none. Returns profile, compliant, fixed, warnings, substitutions and remaining
convert_pdfa_json(doc, level, flatten_dpi, substitute_fonts)Converts like convertPdfaLevel but reports the clauses that remain instead of failing. flatten_dpi is the resolution PDF/A-1 transparency is flattened at (0 or less is 300); substitute_fonts 0 leaves non-embedded non-standard fonts alone. Returns level, compliant, fixed, substitutions (original, substitute, exact, widths_adjusted) and remaining (clause, message, page, object)
register_substitute_font(data)Registers TrueType font data (with glyf outlines) for PDF/A and PDF/UA substitution: non-embedded fonts with the same PostScript or family name use it. Returns the PostScript name

Reach them through NexPdfJni.invoke, the whole C API as one JSON call. Its document handles are its own, not the long handles of NexPdfDocument, so open the document through invoke too:

import android.util.Base64
import org.json.JSONArray

fun call(fn: String, vararg args: Any?): Any? {
    val request = JSONObject().put("fn", fn).put("args", JSONArray(args.toList()))
    val response = JSONObject(NexPdfJni.invoke(request.toString()))
    if (!response.getBoolean("ok")) error(response.getString("error"))
    return response.opt("result")
}
fun b64(bytes: ByteArray) = Base64.encodeToString(bytes, Base64.NO_WRAP)

val h = call("open_bytes", b64(report))
try {
    val ua2 = JSONObject(call("validate_pdfua_part_json", h, 2) as String)
    val conv = JSONObject(call("convert_pdfua_json", h, 2, "en-GB") as String)
    Log.i("NexPDF", "${conv.getString("profile")} ${conv.getBoolean("compliant")} ${conv.get("remaining")}")
    val pdf = Base64.decode(call("save_bytes", h) as String, Base64.DEFAULT)
    File(filesDir, "report-ua2.pdf").writeBytes(pdf)
} finally {
    call("close", h)
}

PDF/A conversion flattens PDF/A-1 transparency into opaque image patches (text stays text), fixes device colour (a CMYK output intent, Default colour spaces), draws missing appearance streams for widgets and markup annotations, substitutes metric-compatible fonts for non-embedded fonts and removes unreachable objects. For PDF/A-4e it keeps U3D and PRC 3D streams and 3D and RichMedia annotations.

For raw handles the calls are NexPdfJni.validatePdfaJson(handle, level), validatePdfuaJson(handle) and convertPdfaLevel(handle, level). See PDF/A, PDF/X and PDF/UA for PDF/X and accessibility tagging.

On this page