Opening docx and pdf documents in react native - android

Faced a number of problems opening documents in a mobile application. We have 2 types of PDF and DOCX documents available.
There are no packages to open Docx for react native.
In order to open a pdf, you need to have the base64 of that document. The back-end does not give back, and in order for the mobile application to create it itself, you need to fasten a heavy package.
Two types of documents can be opened in webview, but only viewing without saving will be available there, and then, this will only work on ios, android immediately starts downloading documents without viewing.
You can use the google.docs service to view documents, but you won't be able to open the document without cookies. Our back-end doesn't let the google.docs robot (for obvious reasons) download the document and display it to us.

Related

Android Online PDF Load - Preview Not available error via Google Doc

The core part of my application is load PDF online and user have access to download it as per their given rights.
The problem I am facing is that I want to load pdf online. After many research I have found that,
There are likely two ways to show pdf online in android:
1) In Web view by loading simple hosted URL
2) By google doc.
But in our case, if we use way (1), the mobile web view does not redirect hosted url of PDF.
And if we use way (2), then there are certain limitations of the google docs regarding the file sizes. (Small pdf it will load like 5 to 10 with size of 1MB)
But after loading PDF with the size of 2 or 3 MB it's also giving me error as "No PREVIEW AVAILABLE" and its continuously giving me this error opening different urls.
So it seems there is still no easy solution for viewing a pdf from url (online without downloading pdf).
The other way to open pdf online is that we can open it in any other third party applications like browser, adobe pdf reader or any kind of pdf viewer application available in the device.
Cons: If we open pdf in browser then it will get downloaded automatically and if we open it in any third party application then they have options to download the pdf.
Please give me some solution to read the PDF online.
And if there are any paid pdf SDK availble which gives functionality of loading pdf online from URL, then please provide information of that too.
Please also suggest me some pdf viewer library for displaying pdf online.
I have used many of the library, but it increases my application's size to 8 to 10 MB.
Thanks in advance.
The suggested primary solution,
Download the file, store it in the app specific folder so users don't have access. For viewers who don't have access rights to download it, you will delete the file as they leave the view. For viewers who have access rights to download it, they will be given an option to copy the file to their SD card (an accessible location) and then you will delete the original file as they leave the view.
For storing in app specific directory to restrict user access,
http://www.grokkingandroid.com/how-to-correctly-store-app-specific-files-in-android/
Also use a library to view the pdf(MUCH SIMPLER), choose an appropriate one from here
https://android-arsenal.com/search?q=pdf
Alternate solution,
If security is a major concern, you can encrypt the pdf file and store it on the server. And decrypt the file when you download it to the device.
For added security, don't store the file as pdf, just store it as a file. Download it as a file. Set type as pdf when you want to access it.
Conclusion,
Data wise, Even if you load it online, the device will consume almost same data as downloading the pdf. (Infact for viewing something online, your device downloads the data and stores it in the cache and you can view it)
Security wise, only a rooted phone will be able to access the file but that too for as long as you have decided to store it.
I suggest you check out PDF.js, a Javascript library from Mozilla to render PDF's in a browser. You can adapt this into a WebView easily, and display PDF's without downloading them.
Here is an open source app which does something similar to what you're looking for

Display a pdf that is loaded via webview (android)

I'm looking for a way to display a pdf that is loaded in a webview.
The case is as follows:
- We load a (external) web application inside a webview.
- The web application is secured, users have to login to access their data.
- When the user has logged in there is a button for downloading a pdf file.
- On iOS the pdf file is being displayed inside the webview, on Android it isn't.
- It is not possible to access the pdf by using a webservice instead of the webview (so, Titanium.Network.HTTPClient cannot be used)
We tried several solutions that we found on the internet. Unfortunately, till now without any success.
We tried:
- Google's documentviewer: http://docs.google.com/viewer?embedded=true&url=. This is not working because the pdf is 'behind' a username/password. Google is not aware of the session.
- Saving the pdf to the local file system and open it with Android Intent. We did not succeed in saving the pdf on the local filesystem.
The last option (saving the pdf and open it by using Ti.Android.Intent) seems to be the best option. But is it possible to save a pdf from a webview???
Maybe an external module (or using pdf.js) is also an option.
Can someone point me in the right direction.
We even don't know if what we want is possible?
Any help is really appreciated.
Stefan.

Make app generated content show in stock android Downloads app

We are working on an android app that generates PDFs based on app contents on users' request. We are providing an option to launch an email agent and attach the generate PDF, but we also want the user be able to view the document later at any time. On android, there are no stock file explorer, so our first thought was to show on the stock Downloads app's file list. We've tried the following two methods but without luck.
We firstly tried to save the PDF to the default download folder (given by calling Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)) and invoke media scanner, but the file doesn't show up in the Downloads app's list. It's shown in Adobe Acrobat's local document list though.
After some research, it seems that the Downloads app would only show files that downloaded though DownloadManager, so we tried to generate the PDF in a temporary directory and call DownloadManager to download it, but, somehow expected, it complains that we can only download via HTTP(S), so this approach isn't working as well.
Is there any other solution?
well if you have to provide access to the document without any file explorer app, i think your approach is correct it to allow to store it in the Download lists. To achive this you can use Nanohttpd in your application to host your pdf document and then invoke the DownloadManager download action using HTTP(S) to your webapp (you will have to create a small webapp to handle the download request) hosted on localhost server.

How to convert a MS Office DOC/XLS/PPT & PDF to image on Android

We need to be able to import Office documents as images into an app. On Windows we use LibreOffice which has a command line --convert flag.
Now we need to do the same for Android and iOS.
LibreOffice is not ready for Android yet.
Open Office for Android (AdrOpen Office) is there, but it does not have the --convert line option
One possibility I am looking at is to use JodConverter, but the solution needs to work offline - my reading of JodConverter is that it "uses openeoffice.org", and I'm not if this means it accesses the web site when doing the conversion, or it simply requires some software components from openoffice.org to be installed locally.
Note I am not asking how to open the documents, but how to convert them to an image, which we then import as a background in our app. We do not need to "live edit" them.
you can use PDF2JPG app to convert PDF to jpg. This app is available on google playstore freely. for doc to jpg conversion , you need to use the combination of two apps. First you need to use Doc To Pdf app from playstore for convert it to PDF, which is freely available on google playstore then convert PDF to jpg.

Viewing pdf bytestream without saving it in Android

Ref: How to render PDF in Android
I have a bytestream with PDF contents and want to display the same in my android app. Is there a way I can do that without saving it as a physical file? For security reasons: I want the user to be able to just view the PDF and not store it in the phone memory or SDCard.
Does google doc viewer has the ability to take bytestream and render it? Or any other app that is installed in the android phone?
You cannot push "a bytestream" (presumably a byte[]) to another application. While there may be ways you can have another application pull the bytes to render it, any application will be able to do that, not just your PDF viewer, which will defeat your security goals.

Categories

Resources