我为pdf文件创建了android应用程序,但它只显示简单的视图。 其实我想在我的android pdf View中添加翻页。我的PDFViewer代码是: 我还想添加搜索页码的功能(通过搜索转到specefic页面)。
MainActivity.java
package com.example.mnaum.quranasaanurdutrjuma;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.github.barteksc.pdfviewer.PDFView;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
PDFView pdfView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pdfView=(PDFView)findViewById(R.id.pdfView);
pdfView.fromAsset("parah1.pdf").load();
new RetrievePDFStream().execute("http://ancestralauthor.com/download/sample.pdf");
}
class RetrievePDFStream extends AsyncTask<String,Void,InputStream>{
@Override
protected InputStream doInBackground(String... strings) {
InputStream inputStream=null;
try {
URL url=new URL(strings[0]);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
if (urlConnection.getResponseCode()==200){
inputStream=new BufferedInputStream(urlConnection.getInputStream());
}
}
catch (IOException e){
return null;
}
return inputStream;
}
@Override
protected void onPostExecute(InputStream inputStream) {
pdfView.fromStream(inputStream).load();
}
}
}
这是我的主要活动的XML文件
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<com.github.barteksc.pdfviewer.PDFView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pdfView"/>
</RelativeLayout>
的build.gradle
compile 'com.github.barteksc:android-pdf-viewer:2.3.0'
compile 'org.apache.commons:commons-io:1.3.2'