Does android provide any built it control like video view or image view to display pdf ebook?
More specifically I want to open a pdf ebook in android with following controls on the screen.
zooming controls
turn over functionality/swipe to change page.
What is the suitable way to achieve this?
Android does not provide a default PDF reader. I believe some phones come with a pre-installed application for reading PDFs, but you cannot rely on this fact for all devices. The best you can do for now is choose to open the user's default PDF reader (if they have one installed).
Use an intent to open up the user's default PDF app (untested, should be something like this):
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(pathToPDF, "application/pdf");
startActivity(intent)
Related
I know there are many similar questions, but I need specifics. I originally wanted my app to open PDFS within the app itself, but I have settled to send an intent activity to adobe reader. I am currently opening PDFS by looking for the file on the device itself. Is there a way I can have the PDFS in my app, and create a folder on the users device, and then look for them? or something similar? Obvisouly the user isn't going to have the PDF already installed on their device. Here is my current code.
Intent intent7 = new Intent();
intent7.setPackage("com.adobe.reader");
intent7.setDataAndType(Uri.fromFile(new File("/storage/emulated/0/Download/Auto-example.pdf")), "application/pdf");
startActivity(intent7);
Is there a way I can have the PDFS in my app, and create a folder on the users device, and then look for them?
You can put the PDF in internal storage (e.g., getFilesDir()), then use FileProvider to serve them via a ContentProvider. This sample project demonstrates serving a PDF from internal storage (copied there from assets/) and viewing it in the user's chosen PDF viewer. There is also an Android training module covering this.
With respect to the code that you have, please use ACTION_VIEW as your Intent action (e.g., pass that to the constructor) and delete the setPackage() line.
So, I would need a option to view a PDF within my own app (yes, so basicly I don´t need something like the code i will post as example below.... since it will just open the PDF in a new window using a external, installed app on the device)
final Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
this.startActivity(pdfIntent);
What i want to do is to open (and view) a PDF inside my app, so for example inside a FrameLayout within any layout file from my app. I know, that there would be the option to upload the PDF and using a WebView and GoogleDocs to display the PDF - but since you can´t call GoogleDocs without a internet connection... well, I need something else.
I searched for librarys, wich are able to read/view and display PDFs (and wich you can use for free), but most of the android compatible results i found were just other stand-alone apps... and like I mentioned before, I want to view the PDF within MY app, in a FrameLayout (without opening a new window) or something and nothing else.
Does anybody know if there is a option to do this?
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);
i open a PDF with the default reader on the system.
Someone know if is possible inherits this reader (ex. Thinkoffice or Adobe Reader) into a layout on my app?
Because i need to open a PDF and show an header, or something like that, with a special description.
Someone know if is possible inherits this reader (ex. Thinkoffice or Adobe Reader) into a layout on my app?
That is impossible. You cannot embed other applications' UIs into your app.
Because i need to open a PDF and show an header, or something like that, with a special description..
Put that information into the PDF file itself.
As far as I know, I don't think it's possible. You can however fire intents which can be captured by an appropriate application on the phone. This is handled by the OS. I don't know if there is any intent for opening PDFs. Here is a useful library for intents though: http://www.openintents.org/en/intentstable. See if you can find something there.
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.