2016-09-17 125 views
1

你好,我發現this library用於顯示我的活動 裏面的PDF文件我嘗試使用示例代碼,但未能...我的代碼不會從資產AndroidPdfViewer圖書館

這裏載入PDF文件是我的代碼

主活動 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> 

有什麼解決辦法嗎?

回答

4

您只是缺少需要加載pdf的​​。

您的代碼應該看起來像:pdfView.fromAsset("zan.pdf").load();

+0

謝謝你的工作 –