PdfTools

object PdfTools

JVM/Desktop-only post-processing utilities that operate on already-encoded PDF bytes (from PdfKmp or any other producer), backed by Apache PdfBox.

These live in jvmMain and have no Android, iOS, or Web counterpart: Android's android.graphics.pdf and iOS's Core Graphics only expose PDF-writing APIs, and the Web target has no PDF engine at all. Merging, splitting, stamping, and overlaying existing documents all require a full PDF parser/manipulator, which on the JVM is PdfBox (a pure-Java engine, so no native libraries are pulled in). If you need these operations on mobile/web, run them on a JVM/Desktop backend (or a server) instead.

Every method reads the input into an in-memory PDDocument, operates on it, and serialises the result to a fresh ByteArray; inputs are never mutated.

Functions

Link copied to clipboard
fun addWatermarkText(pdf: ByteArray, text: String, fontSizePt: Float = 96.0f, color: PdfColor = PdfColor.LightGray, opacityFraction: Float = 0.3f, rotationDegrees: Float = 45.0f): ByteArray

Stamps diagonal watermark text across every page of pdf, centered, semi-transparent, and rotated.

Link copied to clipboard

Embeds invoice's factur-x.xml into pdf as a ZUGFeRD / Factur-X attachment and returns the new bytes.

Link copied to clipboard

Extracts the pages in range (1-based, inclusive on both ends) from pdf into a new document, via PdfBox's PageExtractor.

Link copied to clipboard
fun merge(vararg documents: ByteArray): ByteArray

Merges documents into a single PDF, concatenating their pages in argument order, via PdfBox's PDFMergerUtility.

Link copied to clipboard
fun overlay(pdf: ByteArray, overlayPdf: ByteArray): ByteArray

Overlays overlayPdf onto pdf (the overlay drawn in front of each page's existing content) via PdfBox's Overlay.

Link copied to clipboard

Splits pdf into one single-page document per page, preserving page order, via PdfBox's Splitter.

Link copied to clipboard

Runs a quick, dependency-free self-check of pdf for the entries a PDF/A reader expects, returning human-readable findings (one per issue). An empty list means none of the checked problems were found.