Forum Xamarin.Forms

display PDF in webview not working Xamarin forms

MehdiMllMehdiMll Member ✭✭
edited June 2019 in Xamarin.Forms

i am trying to display a hosted IMAGE from a secure web api it working

                    VerticalOptions="FillAndExpand" />

but trying to display a hosted PDF from a secure web api it not working

                VerticalOptions="FillAndExpand" />

*= http

Best Answer

  • MehdiMllMehdiMll ✭✭
    edited July 2019 Accepted Answer

    i use method from APi for get file

           [HttpGet, AllowAnonymous, Route("api/File/{id}")]
            public async Task<HttpResponseMessage> GetFile(long id)
                var file = await context.File.FindAsync(id);
                var data = file?.SystemFileName;
                System.IO.MemoryStream memoryStream = new MemoryStream();
                if (data != null && data.Length > 10)
                    var localPhotoData = File.ReadAllBytes(data);
                    memoryStream = new System.IO.MemoryStream(localPhotoData);
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
                    Content = new StreamContent(memoryStream)
                var contentType = MimeMapping.GetMimeMapping(file.OriginalFileName);
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
                return response;

    and Call It in Mobile projrct

    var Id = FileId;
    Device.OpenUri(new Uri(Constants.BaseApiAddress + "api/File/" + Id));
    i dont use
    await Xamarin.Essentials.Browser.OpenAsync(UrlFile);

    because it working just with Pdf


Sign In or Register to comment.