0

My requirement is, I need to display content in pdf for my app. I'm getting InputStream of a file over HTTP call. How can I convert this InputStream to PDF view without storing in SD card?

I can use the below code:

        Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.fromFile(new File(File Path)), "application/pdf");
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);

But is there any other way to display in PDF?

Sam
  • 244
  • 2
  • 5
  • 20

2 Answers2

0

There is another way for showing PDF in android app that is embedding the PDF document to android webview using support from http://docs.google.com/viewer

pseudo

String doc="<iframe src='http://docs.google.com/viewer?url=+location to your PDF File+' 
              width='100%' height='100%' 
              style='border: none;'></iframe>";

a sample is is shown below

 String doc="<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true' 
              width='100%' height='100%' 
              style='border: none;'></iframe>";

Code

    WebView  wv = (WebView)findViewById(R.id.webView); 
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginsEnabled(true);
    wv.getSettings().setAllowFileAccess(true);
    wv.loadUrl(doc);
    //wv.loadData( doc, "text/html",  "UTF-8");

and in manifest provide

<uses-permission android:name="android.permission.INTERNET"/>

See this

Caution : I am not aware of compatibility issues with various android versions

Community
  • 1
  • 1
edwin
  • 7,985
  • 10
  • 51
  • 82
-1

Try out this way:

   File m_file=new File("/sdcard/myPdf.pdf");
   Uri m_uri=Uri.fromFile(m_file);

try
  {
    Intent intentUrl = new Intent(Intent.ACTION_VIEW);
     intentUrl.setDataAndType(m_uri, "application/pdf");
     intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     startActivity(intentUrl);
   }
catch (ActivityNotFoundException e)
{
    Toast.makeText(m_context, "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
}
GrIsHu
  • 29,068
  • 10
  • 64
  • 102