Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mahmoud-b28887f9.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

KPdfSource is a sealed interface with three variants: Url, Bytes, and Base64. You pass a KPdfSource value to KPdfViewerState.open() or to KPdf.viewerState() to tell the SDK where to load the document from. Each variant is a data class, so equality and caching are based on the field values you provide.

KPdfSource.Url

Use KPdfSource.Url when your PDF is hosted at a remote HTTPS address. The SDK fetches the document through its internal source pipeline. Because HTTP headers can affect the response — for example, authentication tokens or content-negotiation directives — headers are part of the source identity: two Url instances with identical URLs but different headers are treated as distinct sources.
url
String
required
The HTTPS URL of the remote PDF document.
headers
Map<String, String>
default:"emptyMap()"
Custom HTTP request headers to include when fetching the PDF. Headers are part of the source identity — changing a header value produces a distinct source that bypasses the previous cache entry.
Because headers contribute to source identity, supplying a new Authorization value or any other changed header causes the SDK to treat the request as a new source and fetch the document again rather than serving the cached copy.
// Public URL with no extra headers
val publicSource = KPdfSource.Url(
    url = "https://example.com/document.pdf"
)

// Authenticated URL — different token = different cached source
val authenticatedSource = KPdfSource.Url(
    url = "https://api.example.com/reports/q1.pdf",
    headers = mapOf("Authorization" to "Bearer eyJhbGci...")
)

KPdfSource.Bytes

Use KPdfSource.Bytes when you have already loaded the raw PDF bytes in your application — for example, after reading a file from disk or downloading it yourself. The SDK does not perform any network request; it reads directly from the ByteArray you provide. KPdfSource.Bytes implements structural equality via contentEquals, so two instances wrapping byte-for-byte identical arrays are considered equal.
data
ByteArray
required
The complete, raw bytes of a valid PDF document.
// Read bytes from a local file (platform-specific I/O shown for illustration)
val pdfBytes: ByteArray = File("invoice.pdf").readBytes()

val bytesSource = KPdfSource.Bytes(data = pdfBytes)

KPdfSource.Base64

Use KPdfSource.Base64 when your PDF is delivered as a Base64-encoded string. The SDK accepts both a raw Base64 string and a data URL of the form data:application/pdf;base64,<encoded>.
value
String
required
A raw Base64-encoded PDF string or a full data URL in the format data:application/pdf;base64,<encoded>. Both forms are accepted.
// Raw Base64 string
val rawBase64Source = KPdfSource.Base64(
    value = "JVBERi0xLjQKJ..."
)

// Data URL form
val dataUrlSource = KPdfSource.Base64(
    value = "data:application/pdf;base64,JVBERi0xLjQKJ..."
)