2011-03-26 114 views

回答

0

否。目前,沒有庫可以逐字節解析.pdf。

Android確實有一些用於顯示.pdf的第三方庫,但是Android本身並沒有包含這樣做的類/包。

2

你可以做的最多的就是調用其他程序與像這樣打開它

public class OpenPdf extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button button = (Button) findViewById(R.id.OpenPdfButton); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       File file = new File("/sdcard/example.pdf"); 

       if (file.exists()) { 
        Uri path = Uri.fromFile(file); 
        Intent intent = new Intent(Intent.ACTION_VIEW); 
        intent.setDataAndType(path, "application/pdf"); 
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

        try { 
         startActivity(intent); 
        } 
        catch (ActivityNotFoundException e) { 
         Toast.makeText(OpenPdf.this, 
          "No Application Available to View PDF", 
           Toast.LENGTH_SHORT).show(); 
        } 
       } 
      } 
     }); 
    } 
} 
+0

感謝您的意見 – 2011-03-26 15:16:20

+0

如果我們要設置另一個應用程序,我們必須寫什麼?必須在SD卡中看到? – Hosein 2012-12-13 09:37:59

2

Android不支持原生PDF(如果已安裝的Quickoffice只適用)。但是,您可以通過Google文檔查看器在線閱讀您的PDF文件。這裏的代碼:

WebView webview = (WebView) findViewById(R.id.webview); 
webview.getSettings().setJavaScriptEnabled(true); 
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf"; 
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf); 
+0

對於操作系統的PDF本地支持沒有這樣的東西。它總是附加的軟件! – 2014-10-22 19:49:37