ComposePrintAdapter

class ComposePrintAdapter(activity: ComponentActivity, documentName: String, pageModifier: Modifier = Modifier, pageDpi: Int = DefaultPageDpi, printBreakpoints: Boolean = false, mainContext: CoroutineContext = Dispatchers.Main, ioDispatcher: CoroutineDispatcher = Dispatchers.IO, content: @Composable () -> Unit) : CoroutinePrintDocumentAdapter

A PrintDocumentAdapter that prints a composable function. The composable content is paginated as best-effort to avoid cutting off composables in the middle (see Paged).

Long blocks of text and subcompositions are not fully supported: the paginator will try to not split them, but if they don't fit on a page, they will be split arbitrarily.

See composeToPdf for details on how the composable is actually written to the PDF.

Parameters

activity

The ComponentActivity used to create various printing resources.

documentName

The file name that will be reported to the printing system, e.g. to use as the default for the Save to PDF virtual printer.

pageModifier

A Modifier that will be applied to each individual page of the printed content. responsivePadding is a good choice.

pageDpi

The resolution to use for the Density of the composable.

printBreakpoints

If true, horizontal lines are drawn at each breakpoint for debugging. False by default.

mainContext

The CoroutineContext to interact with the composable and view system on.

Constructors

Link copied to clipboard
constructor(activity: ComponentActivity, documentName: String, pageModifier: Modifier = Modifier, pageDpi: Int = DefaultPageDpi, printBreakpoints: Boolean = false, mainContext: CoroutineContext = Dispatchers.Main, ioDispatcher: CoroutineDispatcher = Dispatchers.IO, content: @Composable () -> Unit)

Functions

Link copied to clipboard
open override fun onFinish()
Link copied to clipboard
open suspend override fun onLayout(oldAttributes: PrintAttributes?, newAttributes: PrintAttributes, extras: Bundle?): PrintDocumentInfo
override fun onLayout(oldAttributes: PrintAttributes?, newAttributes: PrintAttributes, cancellationSignal: CancellationSignal, callback: PrintDocumentAdapter.LayoutResultCallback, extras: Bundle?)
Link copied to clipboard
open fun onStart()
Link copied to clipboard
open suspend override fun onWrite(pages: Array<out PageRange>, destination: ParcelFileDescriptor): Array<out PageRange>
override fun onWrite(pages: Array<out PageRange>, destination: ParcelFileDescriptor, cancellationSignal: CancellationSignal, callback: PrintDocumentAdapter.WriteResultCallback)