首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AndroidPdfViewer库

AndroidPdfViewer库
EN

Stack Overflow用户
提问于 2016-09-18 02:00:44
回答 1查看 5.3K关注 0票数 4

我在我的活动中找到了Barteksc library来显示PDF文件。我尝试使用示例代码,但失败了。我的代码没有从资源文件夹加载PDF文件。

下面是我的主要活动代码:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
<?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>

可能的解决方案是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-18 02:15:25

你只是错过了需要加载pdf的.load()

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

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39550057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档