PdfView не показывает pdf

Я использую библиотеку barteksc pdfViewer для отображения строки в представлении pdf. У меня есть код ниже:

PDFView pdfView  = (PDFView) findViewById(R.id.pdfView);
String text = "some string";
Uri textUri = Uri.parse(text);
pdfView.fromUri(textUri).load();

Мой файл xml:

<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = ".PdfActivity">

    <com.github.barteksc.pdfviewer.PDFView
        android:id = "@+id/pdfView"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:layout_marginStart = "8dp"
        android:layout_marginTop = "8dp"
        android:layout_marginEnd = "8dp"
        android:layout_marginBottom = "8dp"
        android:visibility = "visible"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"/>

</android.support.constraint.ConstraintLayout>

но pdfView остается пустым. Кто-нибудь знает, почему я не могу предварительно просмотреть pdfView?

1
0
650
1

Ответы 1

to show a string in pdf view

Вы не можете этого сделать. PDFViewer может отображать только PDF.

Ниже перечислены различные методы установки PDF-файла в PDFViewer:

pdfView.fromUri(Uri)
pdfView.fromFile(File)
pdfView.fromBytes(byte[])
pdfView.fromStream(InputStream)
pdfView.fromAsset(String)

Если у вас есть String, попробуйте преобразовать его в ByteArray.

https://github.com/barteksc/AndroidPdfViewer

Хорошо, я конвертирую строку в PdfDocument. Но тогда как мне установить PdfDocument для просмотра?

ktsakiris 18.10.2018 18:10

Другие вопросы по теме