Я пытаюсь отобразить документ PDF с PdfViewerFragment из библиотеки
androidx.pdf:pdf-viewer:1.0.0-alpha10 внутри JetPack Compose UI. < /p>
Я использую AndroidView для размещения фрагмента. FileProvider) выглядит правильно, и сам файл PDF действителен (можно открыть для других зрителей), и хотя контейнер AndroidView (с цветом испытательного фона) и занимает правильное пространство, сам PDF не отображается в PDFViewerFragment.
нет ошибок или исключения в LogCat. В комплексе. /> То, что я уже проверил/Пробовал:
uri valoity: the content: // uri генерируется FileProvider для файла в каталоге кэша приложения.
File существует, не пуст и может быть загружен/открыт из эмулятора. Власти соответствуют. Этот фон виден и заполняет ожидаемую область. < /P>
Logcat output: < /p>
PdfFragmentScreen D LaunchedEffect triggered. pdfUri:content://com.xxx.fileprovider/my_cache_files/xxx.pdf
PdfFragmentScreen D Attempting to copy PDF to cache. Temp file path: /data/user/0/com.xxx/cache/temp_pdf_viewer.pdf
PdfFragmentScreen D Deleting existing temp file.
PdfFragmentScreen D Successfully opened InputStream for pdfUri.
PdfFragmentScreen D Successfully copied data to temp file.
PdfFragmentScreen I Successfully created CONTENT URI: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf
PdfFragmentScreen D Setting isLoading to false. fileUriForViewer: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf
MyPdfViewer D Composing with URI: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf, Modifier: androidx.compose.foundation.layout.FillElement@d444f175
MyPdfViewer D Factory called. Creating FragmentContainerView with id: 1
MyPdfViewer D Update called. URI: content://com.xxx/my_cache_files/temp_pdf_viewer.pdf, FragmentContainerView ID: 1
MyPdfViewer I Fragment with tag PdfViewerFragmentTag not found. Adding new PdfViewerFragment.`
< /code>
code: < /p>
@SuppressLint("ContextCastToActivity")
@Composable
fun MyPdfViewer(
uri: Uri?,
modifier: Modifier = Modifier
) {
val activity = LocalContext.current as FragmentActivity
val themeContext = ContextThemeWrapper(activity, R.style.PdfViewerTheme)
val fragmentTag = remember { "PdfViewerFragmentTag" }
Log.d("MyPdfViewer", "Composing with URI: $uri, Modifier: $modifier")
AndroidView(
modifier = modifier.then(Modifier.background(Color.Blue)),
factory = {
Log.d("MyPdfViewer", "Factory called. Creating FragmentContainerView with id: $containerId")
FragmentContainerView(themeContext).apply {
id = containerId
}
},
update = { fragmentContainerView ->
Log.d("MyPdfViewer", "Update called. URI: $uri, FragmentContainerView ID: ${fragmentContainerView.id}")
if (uri != null) {
if (activity.supportFragmentManager.findFragmentByTag(fragmentTag) == null) {
Log.i("MyPdfViewer", "Fragment with tag $fragmentTag not found. Adding new PdfViewerFragment.")
val newFragment = PdfViewerFragment()
newFragment.arguments = bundleOf("uri" to uri)
activity.supportFragmentManager.commit {
replace(
fragmentContainerView.id,
newFragment,
fragmentTag
)
}
} else {
Log.d("MyPdfViewer", "Fragment with tag $fragmentTag already exists.")
}
} else {
Log.w("MyPdfViewer", "Update called but URI is null. Not doing anything.")
}
}
)
}
< /code>
Зависимости: < /p>
def composeBom = platform('androidx.compose:compose-bom:2025.09.00')
// pdf viewer
implementation "androidx.pdf:pdf-viewer:1.0.0-alpha10"
implementation "androidx.pdf:pdf-compose:1.0.0-alpha10"
implementation "androidx.pdf:pdf-viewer-fragment:1.0.0-alpha10"
Подробнее здесь: https://stackoverflow.com/questions/797 ... laying-pdf
JetPack Compose: pdfViewerFragment (androidx.pdf: pdf-viewer) не отображает PDF внутри AndroidView ⇐ Android
Форум для тех, кто программирует под Android
1759131779
Anonymous
Я пытаюсь отобразить документ PDF с PdfViewerFragment из библиотеки
androidx.pdf:pdf-viewer:1.0.0-alpha10 внутри JetPack Compose UI. < /p>
Я использую AndroidView для размещения фрагмента. FileProvider) выглядит правильно, и сам файл PDF действителен (можно открыть для других зрителей), и хотя контейнер AndroidView (с цветом испытательного фона) и занимает правильное пространство, сам PDF не отображается в PDFViewerFragment.
нет ошибок или исключения в LogCat. В комплексе. /> То, что я уже проверил/Пробовал:
uri valoity: the content: // uri генерируется FileProvider для файла в каталоге кэша приложения.
File существует, не пуст и может быть загружен/открыт из эмулятора. Власти соответствуют. Этот фон виден и заполняет ожидаемую область. < /P>
Logcat output: < /p>
PdfFragmentScreen D LaunchedEffect triggered. pdfUri:content://com.xxx.fileprovider/my_cache_files/xxx.pdf
PdfFragmentScreen D Attempting to copy PDF to cache. Temp file path: /data/user/0/com.xxx/cache/temp_pdf_viewer.pdf
PdfFragmentScreen D Deleting existing temp file.
PdfFragmentScreen D Successfully opened InputStream for pdfUri.
PdfFragmentScreen D Successfully copied data to temp file.
PdfFragmentScreen I Successfully created CONTENT URI: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf
PdfFragmentScreen D Setting isLoading to false. fileUriForViewer: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf
MyPdfViewer D Composing with URI: content://com.xxx.fileprovider/my_cache_files/temp_pdf_viewer.pdf, Modifier: androidx.compose.foundation.layout.FillElement@d444f175
MyPdfViewer D Factory called. Creating FragmentContainerView with id: 1
MyPdfViewer D Update called. URI: content://com.xxx/my_cache_files/temp_pdf_viewer.pdf, FragmentContainerView ID: 1
MyPdfViewer I Fragment with tag PdfViewerFragmentTag not found. Adding new PdfViewerFragment.`
< /code>
code: < /p>
@SuppressLint("ContextCastToActivity")
@Composable
fun MyPdfViewer(
uri: Uri?,
modifier: Modifier = Modifier
) {
val activity = LocalContext.current as FragmentActivity
val themeContext = ContextThemeWrapper(activity, R.style.PdfViewerTheme)
val fragmentTag = remember { "PdfViewerFragmentTag" }
Log.d("MyPdfViewer", "Composing with URI: $uri, Modifier: $modifier")
AndroidView(
modifier = modifier.then(Modifier.background(Color.Blue)),
factory = {
Log.d("MyPdfViewer", "Factory called. Creating FragmentContainerView with id: $containerId")
FragmentContainerView(themeContext).apply {
id = containerId
}
},
update = { fragmentContainerView ->
Log.d("MyPdfViewer", "Update called. URI: $uri, FragmentContainerView ID: ${fragmentContainerView.id}")
if (uri != null) {
if (activity.supportFragmentManager.findFragmentByTag(fragmentTag) == null) {
Log.i("MyPdfViewer", "Fragment with tag $fragmentTag not found. Adding new PdfViewerFragment.")
val newFragment = PdfViewerFragment()
newFragment.arguments = bundleOf("uri" to uri)
activity.supportFragmentManager.commit {
replace(
fragmentContainerView.id,
newFragment,
fragmentTag
)
}
} else {
Log.d("MyPdfViewer", "Fragment with tag $fragmentTag already exists.")
}
} else {
Log.w("MyPdfViewer", "Update called but URI is null. Not doing anything.")
}
}
)
}
< /code>
Зависимости: < /p>
def composeBom = platform('androidx.compose:compose-bom:2025.09.00')
// pdf viewer
implementation "androidx.pdf:pdf-viewer:1.0.0-alpha10"
implementation "androidx.pdf:pdf-compose:1.0.0-alpha10"
implementation "androidx.pdf:pdf-viewer-fragment:1.0.0-alpha10"
Подробнее здесь: [url]https://stackoverflow.com/questions/79777859/jetpack-compose-pdfviewerfragment-androidx-pdfpdf-viewer-not-displaying-pdf[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия