2

I have uploaded some pdf files to my server and use that url to display pdf in webview in Android app with "http://docs.google.com/gview?embedded=true&url=myurl".

But I am getting error as :

whooopss..Preview not available.

Sometimes it works and sometimes it's giving that error. All my pdf files are made in Acrobat 6.x .

I have used following code ;

url = "http://docs.google.com/gview?embedded=true&url=" + url;
   loadUrl(url);
   private void loadUrl(String url){

   webView = (WebView) findViewById(R.id.webView1);
   webView.setWebViewClient(new WebViewClient(){

   @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {


   return false;

    }
    });

    webView.setWebChromeClient(new WebChromeClient());

    webView.getSettings().setJavaScriptEnabled(true);     
    webView.getSettings().setPluginState(PluginState.ON);
    webView.loadUrl(url);

Sometimes it also gives error as :

Web Console(2448): Uncaught ReferenceError: _init is not defined at http://docs.google.com/gview?embedded=true&url=myurl/system/download/Datasheet_X1Carbon_2015f1201faba8ab0c3da16d9886ec8a0d1d.pdf:1

I have searched a lot about this but could not find any solution.

I can not understand why this happen. Any help to this are appreciable.

Rohan
  • 2,939
  • 5
  • 36
  • 65

1 Answers1

1

The pdf is displayed easily. but sometimes the app do not have enough memory to load whole pdf.

You can give below code:

<application android:name="pkg.name" android:hardwareAccelerated="true" android:largeHeap="true">

here android:largeHeap="true" code tells system to get allocate more memory for an app. but not every time.

There are many libraries also available to show the pdf in single Activity.

Here is one Android-Pdf-Viewer-Library and documentation you may find here mupdf.com.

Here is another lib android-pdfview

DearDhruv
  • 778
  • 13
  • 34