PdfSource

sealed interface PdfSource

Unified, sealed description of where a PDF comes from.

Earlier revisions of the library mixed two concerns: in-memory payloads were modelled as PdfSource while remote / disk / asset loads travelled as a bare uri: String. That string had to be pattern-matched ("does it start with https://?"), couldn't carry per-shape configuration (headers, timeouts), and made "URI" a misnomer for what was in practice five different transports.

Every variant now lives under PdfSource, split along two axes:

  • In-memoryBytes, Document. The bytes are already in hand; the viewer renders synchronously.

  • AsyncFilePath, Remote, ContentUri, Asset. The viewer fetches the bytes on a background dispatcher, showing a loading state until they arrive.

Use the matching constructor directly when you know the shape (e.g. PdfSource.Remote("https://…", headers = mapOf(…))), or fall back to auto when you only have an opaque string.

PdfDocument payloads stay special-cased because the viewer can overlay an invisible, selectable text layer on top of each rasterised page — that overlay needs the captured PdfTextRuns and PdfHyperlinks, which only the PdfKmp DSL produces.

Inheritors

Types

Link copied to clipboard
class Asset(val path: String) : PdfSource

PDF packaged with the host application. Resolved through Context.assets on Android and Bundle.main on iOS so the same Asset("manuals/quickstart.pdf") works on both platforms.

Link copied to clipboard
class Bytes(val bytes: ByteArray) : PdfSource

Opaque PDF payload — bytes only, no associated text-position data. Yields a viewer with rasterised pages but no selectable text layer.

Link copied to clipboard
object Companion
Link copied to clipboard
class ContentUri(val uri: String) : PdfSource

Android-only payload referenced by a content:// URI. Resolved through the host's android.content.ContentResolver. On iOS, the resolver throws — content URIs are an Android concept.

Link copied to clipboard
class Document(val bytes: ByteArray, val textRuns: List<<Error class: unknown class>>, val hyperlinks: List<<Error class: unknown class>>) : PdfSource

PDF payload paired with the laid-out text runs and hyperlink annotations the renderer produced. Lets PdfViewer mount a transparent, selectable text overlay on each page and attach a clickable layer for hyperlink targets.

Link copied to clipboard
class FilePath(val path: String) : PdfSource

PDF stored on the local filesystem. Accepts bare absolute paths (/storage/emulated/0/…) and file:// URLs alike — both forms resolve through the platform's standard file I/O.

Link copied to clipboard
class Remote(val url: String, val headers: Map<String, String> = emptyMap(), val timeoutMillis: Long = DEFAULT_TIMEOUT_MILLIS) : PdfSource

PDF fetched from an HTTP(S) endpoint. Bytes are downloaded in full to a transient buffer before rendering starts — this implementation is not streaming. Apps that need progress reporting or streaming should fetch the bytes themselves and hand them in as Bytes.