./serve.sh in this directory.
dependencies {
implementation("com.pdfcora:pdfcora:0.1.0")
implementation("com.pdfcora:pdfcora-ui:0.1.0") // optional, the viewer
implementation("com.pdfcora:pdfcora-ai:0.1.0") // optional, AI features
}
Or drop pdfcora-release.aar into libs/. All four ABIs are included.
val document = PdfDocument.open(bytes) val page = document.page(0) val bitmap = page.render(width = 1024, options = PdfRenderOptions(annotations = true, forms = true))
Every engine call runs on one engine thread that all documents share, so concurrent use is
safe and calls on separate documents take turns. Most calls are suspend;
close(), isClosed, fingerprint and page.text are not.
Close it when done — PdfDocument is Closeable.
for (signature in document.signatures()) {
if (!signature.coversWholeDocument) {
// Valid, but content was appended after signing and is not protected.
}
}
when (val verdict = document.verify(signature, PdfVerifyOptions(trustAnchors = roots))) {
is PdfSignatureValidity.Valid -> println(verdict.signer.commonName)
is PdfSignatureValidity.DigestMismatch -> println("the bytes changed after signing")
is PdfSignatureValidity.Untrusted -> println("intact, but not trusted")
else -> Unit
}
val report = document.redact(
listOf(
PdfRedactionTarget.Region(rect, pageIndex = 0),
PdfRedactionTarget.TextMatches("account number"),
),
)
val clean = document.toByteArray(PdfSaveMode.FULL) // full, always
val signed = document.sign(
PdfSignOptions(
signer = Pkcs12Signer(p12, password),
reason = "Approved",
timestampUrl = "https://your-tsa.example/tsr", // optional, PAdES B-T
),
)
val transform = PdfViewTransform.fittingWidth(page.size(), viewportPx)
page.formFields().forEach { field -> val box = transform.toView(field.base.rect) }