pdf viewer library for android - android

I know this question has been asked several times but I couldnt find one satisfying answer.My requirement is simple.just to open the pdf docs within my app(android).But I am not able to find a simple way of doing this.either its native c/c++ way or writing your own engine.But isnt there any simple API so that I can include it like a jar and view the pdf?

No. There is no API in the Android SDK to natively display PDF.
Solutions I can suggest:
-Use an external application:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);
-If your PDF document is accessible online, use the Google Docs Viewer to open your PDF in a WebView:
http://docs.google.com/viewer?url=http://mypdf.pdf

you can use native plugin to show the PDF within your app. try this apv

Related

Call default apps in android to view different documents

I am developing a Cordova Android and iOS application. I am downloading multiple format of documents in my app like PDF and HTML.
I need to open these document from my app. Is there any way to call a default PDF application or other application that support the format of the document from my Cordova application?
I know that the final resolution is to write my own implementation to read the documents using 3rd party libraries.
UPDATE:(Another plugin option)
IF you have similar requirement. Have a look at
https://github.com/pwlin/cordova-plugin-file-opener2
This plugin supports both iOS and Android
If you have to try out with external FileOpener library then i think it will works.
Try this link :- https://github.com/markeeftb/FileOpener
Hope it will helps you.
You can achieve this in Android as follows:
Uri fileUri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(fileUri);
startActivity(intent);
If you are handling multiple file types, use Intent.setType
You can use MimeTypeMap.getMimeTypeFromExtension to get the type you need to set in the Intent.

Open pdf in external app

I have and android app. It has a pdf in assets folder. I written a code to view this pdf in external app(like adobe pdf viewer). It is working fine but problem is that there is Share option in Adobe pdf viewer. I dont want that user can distribute this pdf.
My problem is that there is an important pdf book and I want user can read only but can not share or redistribute it. Please give an idea. I will change my code.
I am using following code:
Uri path = Uri.fromFile(new File(str,
"lemmelibroandroid.pdf"));
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(pdfIntent);
I dont think it is possible to limit the capabilities of the external application used to open the pdf
Have a look at
http://asmncl.blogspot.in/2012/06/android-open-pdf-file-in-webview.html to see how to open the pdf in a WebView
It is not possible,so the best option here will be to show your content in your own app.
I am sure that you will find a proper way to display it some how in activity.
Maybe you should change the format of PDF to HTML and it will be easier to show.

How to view binary PDF documents on an android device

We have a serious problem to tackle here. We are loading pdf documents as binaries into our application and need to be able to view them. Due to security reasons we are not allowed to store them on an external storage.
Our investigations showed that adobe reader x does not support handling binaries and can only digest physical links to a document. This means, it is not an option for us.
Is it correct that Google does not provide a native API to view PDF documents? We could not find any evidence.
Only option left is to implement either our own pdf viewer activity or integrating an existing library.
Are our findings correct? If so, could somebody point out a suggestion on how to proceed here? Are there any ressources available enabling us to implement our own viewer?
We are currently looking at using: http://code.google.com/p/apv/
You can use this: http://www.adobe.com/devnet/readermobile.html. RMSDK supports everything that Adobe Reader built on top of it supports. Though, I wonder why the security? Why can't you generate password protected PDFs or livecycle protected ones? What is there to stop people from stealing your 'binary' (PDF document).
Is it correct that Google does not provide a native API to view PDF documents?
Yes it is true
We could not find any evidence.
Run a search yourself
Are there any resources available enabling us to implement our own viewer?
Besides the one you've shown there is andpdf
You can try searching if there is an application supporting pdf viewing on the phone. Some phones like Nexus supports this.
Uri path = Uri.parse("android.resource://com.your.app/raw/pdfId");
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) {
// no apps with pdf support, run your own
}

Android PDF viewer app to be invoked

I need a pointer to a (preferably free) PDF viewer app that I can invoke on a file or URL link via a startActivity on an Intent. I know that there is no real standard - I have one phone that came with OpenOffice that can read local PDF files, and one phone that has no built-in PDF reader.
What I want is the name of an application that I can suggest to my users to download from the market that is a PDF viewer that I can invoke by configuring an Intent and calling startActivity. I would make this suggestion when I intercept a URL to a pdf file, and discover that the application is not yet installed. Although ugly, this is better than the blank screen they get now because the built in browser doesn't do PDF.
I already installed Adobe's PDF viewer but it is not showing up in the package manager as being a candidate to handle PDF files.
I have used the technique suggested in SO:how-to-render-pdf-in-android to examine the candidate activities for a URL based PDF link and a local file PDF link and see that the com.android.browser.Browser is always invoked for http:// URL links; a URL of "file.pdf" causes OpenOffice to be selected on one phone and nothing on the other phone. Adobe's PDF viewer is not a candidate for either approach.
I tried the Google Docs viewer approach (as suggested in SO:android-load-pdf-pdf-viewer but that leaves a lot to be desired, especially as the PDF image I tried to load kept moving further and further down the device's screen until a user would need to scroll several screen fulls of blank screen to get to the document.
I see libraries such as android-pdf-viewer as a potential solution. But I'd prefer to link to another application rather than build in PDF support (including the fonts, etc) into my application. This then allows my application to support multiple PDF viewer applications - choosing one that the user has already installed or suggesting my favorite one if no compatible reader is present when I need it. Potentially I could see using these types of libraries to create such an application and load it to the market place, but before doing that I want to make sure that I'm not re-inventing the wheel.
I found the droid-reader application which looks promising, but this doesn't appear to be available from the market place. While I'm personally comfortable with the gymnastics of downloading files to my sdcard and installing from there, its not a viable option for the general public user that I'm targeting.
I hope the following code snippit would be helpful to you for reading pdfs. It will use the default pdf viewer that has been set on your device.
Intent intent= new Intent(Intent.ACTION_VIEW);
File f = new File("/mnt/sdcard/file.pdf");
intent.setDataAndType(Uri.fromFile(f),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

Display PDF in webview

I want to show a pdf in my application. My webservice gives me the pdf and I want to download it to sd card and then I want show that pdf in my app through webview.
I was also struggling with Android PDF showing problem for some time. I did the same approach as you mentioned with downloading the PDF to the SD card, but I did not manage to open it up otherwise than using a preinstalled Android App which could do the PDF opening (e.g. Adobe Reader or similar). I think that it's not possible to view the PDF in a WebView widget. The reason is simply that the included webview does not support plugins like adobe reader (see: http://osdir.com/ml/Android-Developers/2010-09/msg03331.html)
You can easily open up the downloaded PDF using an Intent call:
File file = new File("/sdcard/filename.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Due to the fact that this technique opens up the PDF viewer directly after my application makes this call, the back button takes the user directly back to the app, so it feels like the pdf viewing is part of my app.
Hope this helps, best regards
As already answered here, the WebView can't render PDFs. You can do what it is said in the accepted answer in this question and try to open the PDF with the default PDF viewer in the device. If the device has no PDF viewer installed, a message will be displayed to the user.

Categories

Resources