【问题标题】:load pdf from url in PDFView从 PDFView 中的 url 加载 pdf
【发布时间】:2020-08-15 18:14:42
【问题描述】:

我想从 url 加载 pdf,为此我正在使用 PDFViewer 库。但是,打开我的应用程序时它显示为空白。 :( 我需要你的帮助。

这是我的代码:

        PDFView pdfView = findViewById(R.id.pdfView);
            pdfView.fromUri(Uri.parse("https://firebasestorage.googleapis.com/v0/b/pdff-69823.appspot.com/o/ehp1.pdf?alt=media&token=9bb1792e-0787-461c-a6a8-1be6724be93f")).load();

而且,这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

而且,我正在使用这个依赖:

    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

【问题讨论】:

  • 方法 fromUri():使用 URI 作为 pdf 源,用于内容提供者
  • @young ,我没听懂。你能解释一下吗?
  • 你能解决这个问题吗?如果是的话,您能否分享一下您的答案,因为我也面临同样的问题?

标签: android android-studio pdf


【解决方案1】:

为什么我无法从 URL 打开 PDF?

下载文件是一个长时间运行的过程,必须了解 Activity 生命周期,必须支持一些配置、数据清理和缓存,因此创建这样的模块可能最终会作为新库。

我认为这个库只支持设备存储中已经存在的文件,或者您可以使用其他选项,如 fromBytes(byte[]) 或 fromStream(InputStream)。

另一种选择是您可以下载并加载文件。

如果您选择实时渲染,请选择其他选项,例如 Pdfjs 等。

【讨论】:

    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多