如何在不使用第三方应用的情况下阅读Android中的Pdf?

时间:2010-11-22 04:59:23

标签: android

我使用了Itext和Pdf渲染器库文件来读取java中的Pdf文件。 但在android中我使用相同的库读取pdf文件是可能的,但我无法显示文件..

如何在模拟器中显示pd ffile ???

File sdcard = Environment.getExternalStorageDirectory();
        Log.v("Tag:","entered sdcard");
        String input = "/sdcard/andr.pdf";
        Log.v("Tag:","file  recog");

//        File file = new File(sdcard, input);





        try {
//   PdfWriter write = new PdfWriter();

   PdfReader read = new PdfReader(input);
   Log.v("Tag","reading------------"+read.getPageN(9).toString());
//   fl.addView((View)read);
   Log.v("Tag page",read.getPageN(5).getKeys().toString());
//   PdfStream pdfd=new PdfStream(is, write);
   read.getCatalog();

   Log.v("Catalog",read.getCatalog().toString());



   Log.v("Tag:","pdf opened");
   System.gc();
   int n = read.getNumberOfPages();
   Integer num=n;
   Log.v("Tag:",num.toString() );
   Log.v("Tag:","got pages");

//   int n1 = read.getFileLength();
//   
//   Integer num1 = n1;
//   Log.v("tag", num1.toString());


   for(int i=0;i <=1;i++){
//   tv.setText((CharSequence) page);

   read.getPageSize(1);
   Log.v("tag", "page size"+read.getPageSize(1).toString());



    Log.v("Tag:","got pages");



    wv = new WebView(this); 
    setContentView(wv); 
//    wv.getSettings().setJavaScriptEnabled(true);

//    wv.loadUrl("/sdcard/andr.pdf");



   }

  } 
        catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:0)

操作PDF后,保存并查看:How to render PDF in Android

只需从答案中的onClick获取方法正文,并在完成PDF编写后调用它。