【问题标题】:Android pdf reader安卓PDF阅读器
【发布时间】:2012-10-31 21:52:38
【问题描述】:

我想使用 Android pdf 库 http://andpdf.sourceforge.net/,但我有同样的错误。日志:

 ST='file 'no file selected' not found'
 ST='reading page 1, zoom:1.0'

我的课:

public class Reader extends PdfViewerActivity {

 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; }
}

public class StartScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(this, Reader.class);
     intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "/sdcard/test.pdf");
     startActivity(intent);
}
}

【问题讨论】:

  • 这个库在渲染方面也有同样的问题 :( 有时 pdf 文件的片段没有加载。
  • 你看到我告诉你的最后一个对我来说很好用吗?检查你的pdf文件,下载或复制时可能有错误。

标签: android pdf pdf-reader


【解决方案1】:

这里的一些谷歌代码有一些不错的源代码,用于在 android 中阅读 pdf。

Link1

Link2

an awesome example

Link 4

Link 5

【讨论】:

【解决方案2】:

现在我们有了这个很棒的 PDF 查看库:

https://github.com/JoanZapata/android-pdfview

使用起来真的很简单,功能也很多:

Android PDFView 是一个库,它为 Android 提供了一个快速的 PDFView 组件,包括动画、手势和缩放。它基于 VuDroid 解码 PDF 文件。

只需在您的 XML 中包含视图并按如下方式使用它:

pdfView.fromAsset(pdfName)
    .pages(0, 2, 1, 3, 3, 3)
    .defaultPage(1)
    .showMinimap(false)
    .enableSwipe(true)
    .onDraw(onDrawListener)
    .onLoad(onLoadCompleteListener)
    .onPageChange(onPageChangeListener)
    .load();

【讨论】:

  • 注意:这是一个 GPL 库。可能并不适合所有项目。
  • @steipete 这基本上使它对大多数 android 项目无用,因为您必须使整个应用程序的代码可用。这似乎不是库本身的问题,而是它的依赖项之一。作者说:“不幸的是,我的库正在使用 VuDroid,它使用 MuPDF 来呈现 pdf 页面。muPDF 已获得 GPL3 许可,所以我不得不使用相同的。”
【解决方案3】:

使用PdfViewPager,您可以轻松加载和显示 PDF 文件。您需要的所有代码是:

PdfViewPager pdfViewPager = new PDFViewPager(this, "sample.pdf");
setContentView(pdfViewPager);

或者你可以像这样将它嵌入到你的布局中:

<es.voghdev.pdfviewpager.library.PDFViewPager
  android:id="@+id/pdfViewPager"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:assetFileName="sample.pdf"/>

如果您想了解更多信息,请查看 lib。

【讨论】:

  • 在缩小 pdf 时显示此错误请帮助我使用您上面提到的相同 PDFViewerPager 处理:com.pdffilereader,java.lang.IllegalArgumentException:pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(本机方法)在 android.view.MotionEvent.getX(MotionEvent.java:2057)
猜你喜欢
  • 2018-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-16
  • 2011-08-31
相关资源
最近更新 更多