gpt4 book ai didi

AndroidPdfViewer 库

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:35:01 24 4
gpt4 key购买 nike

我找到了 Barteksc library用于在我的 Activity 中显示 PDF 文件。我尝试使用示例代码但失败了。我的代码没有从 Assets 文件夹加载 PDF 文件。

这是我的主要 Activity 代码:

package ir.diamonddesign.pdfviewer;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.github.barteksc.pdfviewer.PDFView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String TAG = MainActivity.class.getSimpleName();
int REQUEST_CODE = 42;

String SAMPLE_FILE = "zan.pdf";
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
Integer pageNumber = 0;
String pdfFileName;

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, REQUEST_CODE);

pdfView.fromAsset("zan.pdf");

}
}

这是我的布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ir.diamonddesign.pdfviewer.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="salam donya !" />

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

</RelativeLayout>

可能的解决方案是什么?

最佳答案

您只是缺少需要加载 pdf 的 .load()

您的代码应如下所示:pdfView.fromAsset("zan.pdf").load();

关于AndroidPdfViewer 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39550057/

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