Convert Byte Array to pdf for android and iOS in Xamarin forms

KholoudAliKholoudAli USMember ✭✭
edited August 2016 in Xamarin.Forms

I developing the app that receiving a pdf in base64biniary format from a web service in Xamarin forms, I want to save the file and display it in android/ ios

var base64BinaryStr = "JVBERi0xLjMNJe....."
byte[] bytes = Convert.FromBase64String(base64BinaryStr);

Tagged:

Posts

  • KholoudAliKholoudAli USMember ✭✭

    BTW, I use dependencyService that mentioned in this post, and I replaced WriteAllText with WriteAllBytes and run with no exception but it doesn't work (no saved file)
    https://developer.xamarin.com/guides/xamarin-forms/working-with/files/#Loading_and_Saving_Files

  • kavya16kavya16 USMember ✭✭

    Hi @KholoudAli, Were you able to do the same ? Can you upload your solution?

  • kavya16kavya16 USMember ✭✭

    Hi @KholoudAli,
    Thanks for the excellent implementation. Can you please tell if you are returning string response of pdf from Web Api Service?

  • KholoudAliKholoudAli USMember ✭✭
    edited February 2017

    @kavya16 said:
    Hi @KholoudAli,
    Thanks for the excellent implementation. Can you please tell if you are returning string response of pdf from Web Api Service?

    Thanks

    Yes we retrieve the pdf base64binary string from Web service and then convert it to byte[] in the app

  • kavya16kavya16 USMember ✭✭

    Hi @KholoudAli,

    Thanks :) I am able to achieve the same with your help.

    Regards,
    Kenika

  • MohanadZahedMohanadZahed DEMember ✭✭

    Hi @KholoudAli,
    I am trying to do the same as you did. which I don't understand is what should I do with the returned filepath from LoadAndDisplayPDF() in my plc project? how can I show the pdf from this filepfath ?

  • RasmusVindRasmusVind USMember ✭✭
    edited September 2017

    Hey @MohanadZahed
    That is a bit off topic, but look at this recipe that should help you getting there.
    https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

  • MohanadZahedMohanadZahed DEMember ✭✭

    @RasmusVind Thanks for the reply I'll give it a try

  • MohanadZahedMohanadZahed DEMember ✭✭
    edited September 2017

    I don't know why there is a return filePath, when he is already opening the file with another application using the intent. I had errors from the returning filepath but after canceling it, everything works now.

Sign In or Register to comment.