我正在开发一个应用程序,我希望通过垂直滚动实现PDF视图功能,请指导任何可以在查看PDF时实现垂直滚动的免费第三方库。
先谢谢
答案 0 :(得分:0)
第1步:首先将jar PdfViewer.jar 从https://github.com/jblough/Android-Pdf-Viewer-Library添加到 libs 文件夹,然后右键单击它构建路径 - >点击“添加到构建路径”
第2步:将以下可绘制文件夹从PdfViewer / res / drawable复制到 res 文件夹到YourProject / res / drawable
要复制的文件是
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
但请确保复制res文件夹中的drawable文件夹。
第3步:将以下布局资源从PdfViewer / res / layout复制到 res>布局文件夹到YourProject / res / layout
要复制的文件是
1> dialog_pagenumber.xml
2.> graphics_view.xml
3.> navigation_overlay.xml
4.> pdf_file_password.xml
5.> scroll_layout.xml
第4步:从net.sf.andpdf.pdfviewer.PdfViewerActivity中导出您的PDF活动,如下所示
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;
}
}
第5步:在您的 MainActivity 电话中,如下所示
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;
}
}
第6步:在您的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>
第7步:运行代码
答案 1 :(得分:0)
执行以下操作.swipeVertical(true)
添加如下所示的行
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();