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.
Related
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.
I have the below tag in my website for downloading image
<a href="data:image/png;base64,%20iVBOdfd...." download="myimage.png" />
The above tag is working normally, when it is pressed, it will download the image without any issue.
When I tried this function on ios / android, the web browser will download the image to some "Download" folder instead of writing it to camera roll (IOS) / DCIM (android).
My question is, is it possible to write to camera roll or DCIM? If it is possible, how can I achieve it? This function is crucial to my application as my users always find it hard to navigate on phone to retrieve the downloaded images at later time.
P.S: My concern is more about the writing destination, filesystem access on phone, not the download itself.
P.S: this is a normal website written using html, vuejs. not native, not react native, not vue-native.
Thank you.
That is not possible since it is the web browser who has access to the device and your web application cannot decide where to save the image. You'll need to implement an app to achieve the expected result. Also study Progressive Web Apps to see whether it's possible
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
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.
I have encrypted fiiles in the external Storage dir / the SD card. The files are crypted
images (jpg, bmp,...)
videos (3gp, mp4,...)
Pdfs
I want to load the bitmaps, videos or pdfs to load them in my ImageView, VideoView or open them via a pdf viewer. The problem is the files are secret. I dont want the files to be stored to open them. They could be read by others during the PDFviewer shows them for example.
Is there a way to directly open an image or pdf even though it is encrypted without copying an unencrypted copy?
If you want to keep your files as secret as possible for your app, I would use
javax.crypto.CipherInputStream
or a customized subclass of it. To do that you'll have to display your content embedded in your app, which is pretty straightforward for images and video. For PDFs you'll need to add a control which can display that kind of file to prevent others from getting access to the content.
Hope it helps.
You cite three scenarios: images into an ImageView, videos into a VideoView, and PDFs to a third-party app.
Images are easy. Make sure your decryption logic can give you an InputStream of the decrypted contents, then use appropriate methods on BitmapFactory.
I am not aware of a way to reliably serve videos to VideoView from an encrypted source. I know some people have experimented with embedding an HTTP server and streaming it.
You can publish a ContentProvider that supplies the decrypted content of a PDF to a third party app. This sample app just reads in the file, but you could use the same approach to decrypt it along the way.
All of this assumes that the user is the one responsible for requesting that this content be encrypted, and that you have collected a passphrase from the user. If, instead, your vision is that you are trying a DRM solution, anyone who wants to will be able to decrypt your content by reverse-engineering your app.