Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin Android Convert Byte array to PDF file

private void ConvertToFile(string fileName , string filePath,Byte[] Bytes){

    if (!File.Exists (filePath)) {
        File.WriteAllBytes(filePath, Bytes);



Above mentioned code is giving me Invalid format PDF


  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited January 2016


    Try something like this :

        Java.IO.File dir = Environment.GetExternalStoragePublicDirectory ();
        Java.IO.File assist = new Java.IO.File ("/mnt/sdcard/Sample.pdf");
            Java.IO.InputStream fis = new Java.IO.InputStream(assist);
            long length =assist.Length();
                Android.Util.Log.Error("Warning","Sorry! Your given file is too large.");
            byte[] bytes = new byte[(int)length];
            int offset = 0;
            int numRead = 0;
            while(offset < bytes.Length && (numRead=fis.Read(bytes, offset, bytes.Length-offset)) >= 0)
            Java.IO.File data = new Java.IO.File(dir,"mydemo.pdf");
            Java.IO.OutputStream outPut = new Java.IO.OutputStream(data);
        catch (System.Exception ex)
            System.Diagnostics.Debug.WriteLine (ex.StackTrace);
Sign In or Register to comment.