在我的布局中打开pdf,没有任何查看器离线

时间:2013-04-03 07:10:05

标签: android

我正在创建学校应用程序,我想在我的布局中打开pdf,我使用pdfviewer但该类将pdf转换为图像并在该类视图中查看。 有没有办法在没有任何查看器的情况下在我的应用程序中打开pdf,我没有使用任何网络连接,所以我无法使用谷歌文档打开我的PDF格式。

那么我怎样才能在我的布局中打开一个pdf我展示这个例子Example of code to implement a PDF reader但这是在pdfviewer类布局中显示而不是在我的布局中。

提前谢谢

1 个答案:

答案 0 :(得分:0)

您是否尝试过MuPDF

您可以在布局中嵌入MuPDFReaderView。这里是伪代码;在你的活动中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* First create the document view */
    mDocView = new MuPDFReaderView(this) {
        @Override
        protected void onMoveToChild(int i) {
            super.onMoveToChild(i);
            Log.d("MyTAG", "pages: " + 
                String.format("%d / %d", i + 1, core.countPages()));
        }

        @Override
        protected void onTapMainDocArea() {
            Log.d("MyTAG", "onTapMainDocArea");
        }

        @Override
        protected void onDocMotion() {
            Log.d("MyTAG", "onDocMotion");
        }
    };

    /* Set the rendering mode */
    mDocView.setMode(MuPDFReaderView.Mode.Drawing);

    /* Load the PDF document... */
    core = new MuPDFCore(path_to_your_pdf_file);
    /* ...and connect the core at the view */
    mDocView.setAdapter(new MuPDFPageAdapter(this, core));

    /* Add the MuPDFReaderView to this layout */
    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(mDocView);
    /* Add more views layout.addView(myOtherView); */
    setContentView(layout);

    /* TODO ...your other code... */        
}