2

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?

Community
  • 1
  • 1
bschandramohan
  • 1,968
  • 5
  • 27
  • 52
  • Thanks Alexanoid. From the features page, it does seem to support bytestream PDF rendering. Zero footprint - You can open PDF files directly from the byte array(memory), leaving zero footprint on the device. This means you can make your own secure document readers. – bschandramohan Nov 12 '15 at 04:07

1 Answers1

3

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is there any way to show this PDF in our application without calling another app? I need the same thing he needs. For security reasons, I can't save PDF file and I have to show it to the user in my application. I am getting it as byte stream. Is there any way to achieve this? – Gokhan Arik Jun 15 '15 at 20:25
  • 1
    @GokhanArik: You are welcome to investigate the various PDF-viewing libraries for Android. You might also consider whether PDF is the best file format to be using, over HTML, which you can render locally in a `WebView`. – CommonsWare Jun 15 '15 at 20:29
  • We have considered options for HTML and JPEG, but that's what client requires. I checked a couple of libraries. If you have any recommendation I would love to investigate it more. – Gokhan Arik Jun 15 '15 at 20:32
  • 1
    @GokhanArik: I have not used any. Personally, I would start with Mozilla's `PDF.js` in a `WebView`. Also note that if your `minSdkVersion` happens to be 21, there is a `PdfRenderer` in Android now, though it's really geared towards print preview. – CommonsWare Jun 15 '15 at 20:34
  • I tried `PDFRenderer` of Android, but still we have to have PDF file saved for that. Am I wrong? – Gokhan Arik Jun 15 '15 at 20:37
  • @GokhanArik: You are going to have to have the PDF file saved for probably any solution. The difference is whether or not you have to have the data accessible to other apps. You can keep the file on your portion of [internal storage](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html), which will be only accessible to your app, with the primary exception being rooted device users. If even that is unacceptable, you are probably out of luck. – CommonsWare Jun 15 '15 at 20:41