0

I want to show pdf converted from base64 string. In ios swift its simple as loading the decoded string to webview

fun decodeString() {

val imageBytes = Base64.decode(pdf_string, Base64.DEFAULT)
val decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
binding.imageView4.setImageBitmap(decodedImage)

}

}

So no need to make a pdf file and store it.

Iam getting the error "D/skia: --- Failed to create image decoder with message 'unimplemented"

Sander
  • 51
  • 6
  • "there is absolutely no need to store the file on the phone" -- if you want the user to use the user's preferred PDF viewer app, you will need to save the PDF to a file. That could be on [what the SDK refers to as internal storage](https://commonsware.com/blog/2019/10/06/storage-situation-internal-storage.html), such as `getCacheDir()` on `Context`. Then, you would use `FileProvider` to make it available to the PDF viewer app. – CommonsWare Apr 11 '21 at 18:12
  • Android's `WebView` has no built-in ability to render PDF content (whether from files or anything else). You could look around for a PDF library that can handle your scenario; all the ones that I know of work with files, not base64-encoded strings. – CommonsWare Apr 11 '21 at 18:15
  • Ok, thanks i already knew that webview is not doing this. Iam looking for a kotlin solution. I can find a lot of java code but not so many kotlin based (convert base64 to pdf) – Sander Apr 11 '21 at 18:38
  • "Iam looking for a kotlin solution" -- for what? "I can find a lot of java code but not so many kotlin based (convert base64 to pdf)" -- converting base64 is not tied to a file format. Converting base64 to a PDF is the same as converting base64 to a JPEG, which is the same as converting base64 to a Word document. https://stackoverflow.com/a/58955588/115145 – CommonsWare Apr 11 '21 at 20:02
  • i looked at it, but val imageBytes = Base64.decode(base64String, Base64.DEFAULT) its not working, i cant import decode. It stays red in android studio – Sander Apr 12 '21 at 09:07
  • `Base64` has existed [since the Android 2.x days](https://developer.android.com/reference/kotlin/android/util/Base64). Make sure you are importing the correct class and that `base64String` is a `String`. – CommonsWare Apr 12 '21 at 10:38
  • ok, so i rebuild the code as mentioned in stackoverflow.com/a/58955588/115145. See my code above, but now iam getting the error " "D/skia: --- Failed to create image decoder with message 'unimplemented". – Sander Apr 12 '21 at 12:13

0 Answers0