如何阅读PDF在我的Andr​​oid应用程序?我的、应用程序、PDF、oid

2023-09-11 10:57:44 作者:海曾怀疑过天的蓝

我提出需要打开PDF格式的应用程序。

I am making an application which require to open pdf.

我也有资产文件夹一些PDF格式,所以我不能够在web视图直接打开它。

I also have some pdf in asset folder so i am not able to open it in webview directly.

在默认情况下Android不支持PDF格式。

By default android does not support pdf.

有没有在Android上的作品的任何API(MuPdf除外)??

Is there any API that works on android(except MuPdf) ??

我的设备没有安装任何PDF阅读器等等动作视图是不是对我有帮助的。

My device does not have any pdf reader installed so ACTION VIEW is not helpful for me

以下是不工作.......

Following is not working.......

显示PDF?

应用打开资源文件PDF

Open asset file pdf in application

ü可以建议我什么好的API ...

can u suggest me any good api...

在此先感谢...

推荐答案

我只是做到了使用 PdfViewer.jar (用蓝色按钮下载),使一个code如下图所示。

I've simply done that using PdfViewer.jar (download it with the blue button) and making a code like below.

First.java

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.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));
}

@Override
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(First.this, Second.class);
      intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
      startActivity(intent);
    }
    catch (Exception e) 
    {
      e.printStackTrace();
    }
}

Second.java

public class Second 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;
}
}

希望这有助于你很多东西。尝试这个。不要忘了添加 Second.java 在你的清单。添加一些可绘不管它需要在 second.java 您可绘制。而且,请参阅从 GitHub上

Hope this helps you lot. Try this. Don't forgot to add your Second.java in your manifest. Add some drawables whatever it requires in second.java with your drawables. And, Refer the example from GitHub