I am developing an application in which I wanted to implement PDF view functionality with vertical scrolling, please guide any free third party library by which vertical scrolling can be implemented while viewing PDF.
Thanks in Advance
I am developing an application in which I wanted to implement PDF view functionality with vertical scrolling, please guide any free third party library by which vertical scrolling can be implemented while viewing PDF.
Thanks in Advance
Step 1 : First Add jar PdfViewer.jar from https://github.com/jblough/Android-Pdf-Viewer-Library to your libs folder and also right click it and in build path -> click on "add to build path"
Step 2 : Copy the following drawable folder to your res folder from PdfViewer/res/drawable into YourProject/res/drawable
The files to be copied are
1.> back01.png
2.> back02.png
3.> doc.png
4.> folder.png
5.> icon.png
6.> left_arrow.png
7.> pdf.png
8.> right_arrow.png
9.> zoom_in.png
10.> zoom_out.png
But make sure you copy the folder drawable in res folder.
Step 3: Copy the following layout resources to your res>layout folder from PdfViewer/res/layout into YourProject/res/layout
The files to be copied are
1.> dialog_pagenumber.xml
2.> graphics_view.xml
3.> navigation_overlay.xml
4.> pdf_file_password.xml
5.> scroll_layout.xml
Step 4: Derive your PDF activity from net.sf.andpdf.pdfviewer.PdfViewerActivity as below
package com.example.viewsdcardpdfs;
import android.os.Bundle;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;
public class mypdfactivity extends PdfViewerActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
Step 5 : In your MainActivity call as follow
package com.example.viewsdcardpdfs;
import java.io.File;
import java.io.FilenameFilter;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(MainActivity.this, mypdfactivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Step 6: In your AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.viewsdcardpdfs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.viewsdcardpdfs.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.viewsdcardpdfs.mypdfactivity">
</activity>
</application>
</manifest>
Step 7 : Run your code
Doing the following worked for me .swipeVertical(true)
add the line as shown below
pdfView.fromAsset(SAMPLE_FILE)
// .pages(0, 2, 1, 3, 3, 3)
.defaultPage(1)
.showMinimap(false)
.enableSwipe(true)
.swipeVertical(true)
//.onDraw(onDrawListener)
.onLoad(this)
.onPageChange(this)
.load();