gpt4 book ai didi

android - 有什么办法可以将 Composables 转换为 Pdf 文件?

转载 作者:行者123 更新时间:2023-12-04 23:50:17 24 4
gpt4 key购买 nike

我想允许用户从应用程序以 PDF 格式下载票证并将其存储在本地。我想以 PDF 格式获得完全相同的 View ,这就是为什么我正在寻找将可组合文件转换为 PDF 的方法。直接将撰写 View 转换为 Pdf 格式会很酷。这有可能实现吗?
1.) KotOrderTicket.kt

@Composable
fun KotOrderTicket(modifier: Modifier = Modifier) {
var totalQuantity: Int = 0

val rowModifier = Modifier
.fillMaxWidth()

val textCenterModifier = Modifier
.fillMaxWidth()
.wrapContentWidth(align = Alignment.CenterHorizontally)

LazyColumn(
modifier = modifier
.fillMaxWidth(),
){
item {
KotDashedDivider()
Text("Kitchen Order Ticket - Dinning", modifier = textCenterModifier)
KotDashedDivider()
Text("Running", modifier = textCenterModifier)
KotDashedDivider()

Row(
modifier = rowModifier,
horizontalArrangement = Arrangement.SpaceBetween,
){
Text("Kot# 22")
Text("Table T7")
}
Text("Date 2022-04-3 10: 23: 22")
Text("Ready Till 2022-04-3 10: 23: 22")
KotDashedDivider()

Row(
modifier = rowModifier,
horizontalArrangement = Arrangement.SpaceBetween,
){
Text("SN")
Text("Item's Name")
Text("Qty")
}
KotDashedDivider()
}

itemsIndexed(summaryItems) { index, item ->
totalQuantity += (item.qty?.toInt() ?: 0)
KotItemSummary(sn = index.toString(), name = item.productId.toString(), qty = item.qty.toString(), comment = "\"Nun kam rakhnu hai\"")
}

item {
KotDashedDivider()
Row(
modifier = rowModifier,
horizontalArrangement = Arrangement.SpaceBetween,
){
Text("")
Text("Total Qty: ")
Text(totalQuantity.toString())
}
KotSpacer()
Text("Remarks: ")
Text("\"Please cook fast, i am so hungry\"")
}
}
}
2.) 这个 View 看起来像这样。
How to convert composeables into pdf format and save it.

最佳答案

您可以在此 tutorial 的一部分之后将您的可组合文件转换为位图然后使用 android 实用程序类 PdfDocument 将该位图放在 pdf 中

关于android - 有什么办法可以将 Composables 转换为 Pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71750606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com