Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Opening pdf in android webview

 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have a very simple use case a pdf is already downloaded in the device of my app user. That pdf has to be rendered in webview using file protocol.

Things which I have tried :




Problem: I have tried with loadData and loadurl but it never gets loaded just a blank screen. No Error is getting logged. Any suggestions will be appreciated.





 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fairly certain webview can't do that. What's wrong with letting an app open it? At least Google Drive is likely to be installed everywhere.
 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:I'm fairly certain webview can't do that. What's wrong with letting an app open it? At least Google Drive is likely to be installed everywhere.



I really don't know about its possibility with webview. But the reason for not using Gdrive app for opening pdf is, recently a very weird problem I am facing with drive i.e. in some devices, mainly Android 10 (Not sure yet) pdf opens for a while and then comes back to my app.

I am not able to figure out any reason (any exception, and no problem with the response code of intent)

Here: https://support.google.com/drive/thread/44585950?hl=en
 
Tim Moores
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, we don't know what you tried to display PDFs using an external viewer app, so we can't advise on that.

WebView likely won't help, although you can try https://inducesmile.com/android-programming/how-to-display-a-pdf-in-webview-in-android/

You could also render the PDF as a Bitmap using the PDFRenderer class: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html
 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Well, we don't know what you tried to display PDFs using an external viewer app, so we can't advise on that.

WebView likely won't help, although you can try https://inducesmile.com/android-programming/how-to-display-a-pdf-in-webview-in-android/

You could also render the PDF as a Bitmap using the PDFRenderer class: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html



Thanks Tim Moores for help. I have opened another thread related to the issue I am facing with another app. You can check this out : Problem with Gdrive

 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:
WebView likely won't help, although you can try https://inducesmile.com/android-programming/how-to-display-a-pdf-in-webview-in-android/



Regarding this, I have already tried opening using google docs in webview. In this Pdf was opening fine but it was hampering the experience like :
1. Pdf used to load late and slow.
2. And sometimes pdf does not even loads. i.e on pdf loading finishes then a white screen comes.


And Regarding the pdf Renderer class is supported for API level 21+. But my app minimum sdk is 19. So I can't use it.

Adding to the above solution I have also tried adding a third-party library for rendering it was increasing app size up to 16mb.Just for sake of rendering a pdf increasing app size or adding a complete library I don't find it efficient enough.

It would be great if we could solve the root cause which I have mentioned in my last comment/another thread. Just as a quick hack I was trying to shift to webview. I have tried adding each and every details of my issue. Please check it. I am already stuck with this issue for a month now.


 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I have also asked the same questions in another community too like gdrive. But got no response yet.
 
Tim Moores
Bartender
Posts: 7488
171
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Regarding the pdf Renderer class is supported for API level 21+. But my app minimum sdk is 19. So I can't use it.


Then use the PdfRenderer class on Android 10, and have the earlier versions open it externally via Intent. That would be a quick improvement until you figure out the actual problem with Android 10. Just make sure to wrap all calls to PdfRenderer inside of

Also, seriously consider dropping support for Android 4.4 - it's 7 years old, and upping that to Lollipop lets you drop the pre-Material Design UI stuff. (Unless there are contractual obligations, obviously.)
 
priyanshi bhardwaj
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

Regarding the pdf Renderer class is supported for API level 21+. But my app minimum sdk is 19. So I can't use it.


Then use the PdfRenderer class on Android 10, and have the earlier versions open it externally via Intent. That would be a quick improvement until you figure out the actual problem with Android 10. Just make sure to wrap all calls to PdfRenderer inside of



This is something that I can use. Thanks, Tim Moores

Also, seriously consider dropping support for Android 4.4 - it's 7 years old, and upping that to Lollipop lets you drop the pre-Material Design UI stuff. (Unless there are contractual obligations, obviously.)


I understand it's 7 years old. I will be planning this also very soon.


 
This is my favorite tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic