I want to open the pdf file Programmatically without using any support of PDF reader. Is it possible to open the pdf file with webview,if yes how?
or if any other possible way is there please suggest me.
than you.
kriss
I want to open the pdf file Programmatically without using any support of PDF reader. Is it possible to open the pdf file with webview,if yes how?
or if any other possible way is there please suggest me.
than you.
kriss
I want to open the pdf file Programmatically without using any support of PDF reader.
By definition, that is impossible. That's like saying you want to view HTML without an HTML reader.
Is it possible to open the pdf file with webview,if yes how?
All it will do is try to redirect you to an on-device PDF reader.
Please allow the user to view PDFs in the PDF reader of their choice. Many Android devices ship with a PDF reader already installed.
you cannot open local PDF in webview but if you want PDF to be opened in your own application then you have to use third party libraries. one of the easy to use library is android-pdfview
you can find jar here check out this question for more details
it says to open PDF all you have to do is:
1) add jar and armeabi-v7a folder in your libs
2) add pdf view in your layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.joanzapata.pdfview.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
3) load your PDF
PDFView pdfView= (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset("yourPDF.pdf") //you can also load from File using pdfView.fromFile()
.defaultPage(1)
.load();
you can also set onPageChangeListner, onPageLoadListner if you want.
You can only use the installed pdf reader applications in device to open the pdf
You can use the google's document viewer service for viewing the pdf,ppt contents in the webview if your document resource is on online.
create following HTML string like :
String googleDocUrl ="<iframe src='http://docs.google.com/gview?url="
+ YOUR_ONLINE_PDF_DOC_URL
+ "&embedded=true' width='100%' height='100%'style='border: none;'></iframe>";
call webviews loadData() method :
mWebView.loadData(googleDocUrl ,"text/html","UTF-8");
thats it. as this worked for me in my last project.
Hope this might help you.