Все круто классно, но русский язык не работает...
This commit is contained in:
parent
3fe3d41253
commit
359d8311fb
@ -96,4 +96,7 @@ dependencies {
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||
|
||||
//PDF
|
||||
implementation ("com.itextpdf:itextpdf:5.5.13")
|
||||
}
|
@ -3,6 +3,10 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
|
||||
|
||||
<application
|
||||
android:name=".BikeApplication"
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.example.myapplication.database.entities.composeui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
@ -41,6 +43,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@ -57,6 +60,11 @@ import com.example.myapplication.datastore.DataStoreManager
|
||||
import com.example.myapplication.datastore.SettingData
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import com.itextpdf.text.Document
|
||||
import com.itextpdf.text.Paragraph
|
||||
import com.itextpdf.text.pdf.PdfWriter
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@SuppressLint("UnrememberedMutableState")
|
||||
@Composable
|
||||
fun UserProfile(
|
||||
@ -67,6 +75,8 @@ fun UserProfile(
|
||||
entryUserViewModel: EntryUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
||||
currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
var username by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var isRegistration by remember { mutableStateOf(false) }
|
||||
@ -228,6 +238,18 @@ fun UserProfile(
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
generatePdf(context = context, fileName = "отчет.pdf")
|
||||
Log.d("context", "${context}")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp)
|
||||
) {
|
||||
Text("Сформировать")
|
||||
}
|
||||
|
||||
Text(
|
||||
"Темная тема",
|
||||
modifier = Modifier
|
||||
@ -356,3 +378,37 @@ fun LoginScreenProfile(currentUserViewModel: CurrentUserViewModel = viewModel(fa
|
||||
}
|
||||
}
|
||||
|
||||
fun generatePdf(context: Context, fileName: String) {
|
||||
// Создаем документ
|
||||
val document = Document()
|
||||
|
||||
// Получаем публичный каталог документов
|
||||
val directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
|
||||
|
||||
// Создаем каталог, если его нет
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs()
|
||||
}
|
||||
|
||||
// Получаем полный путь к файлу
|
||||
val filePath = File(directory, fileName).absolutePath
|
||||
|
||||
// Указываем путь к файлу PDF
|
||||
val writer = PdfWriter.getInstance(document, FileOutputStream(filePath))
|
||||
|
||||
// Открываем документ для записи
|
||||
document.open()
|
||||
|
||||
// Добавляем текст "Привет, мир" в документ
|
||||
document.add(Paragraph("hello! русский не работает?"))
|
||||
|
||||
// Закрываем документ
|
||||
document.close()
|
||||
|
||||
// Закрываем писатель
|
||||
writer.close()
|
||||
|
||||
// Выводим путь в журнал
|
||||
Log.d("PDF Generation", "File created at: $filePath")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user