how to display pdf from url using pdfjs xamarin

i have worked with pdfjs and its working fine with local storage pdf, but i have other issue i need to display pdf from web api, as i have stored binary data of pdf which i need to display?? this is my code

        public pdfjsPage(string url)
        {
            InitializeComponent();

            var localPath = string.Empty;

            if (Device.RuntimePlatform == Device.Android)
            {
                var dependency = DependencyService.Get<ILocalFileProvider>();

                if (dependency == null)
                {
                    DisplayAlert("Error loading PDF", "Computer says no", "OK");

                    return;
                }

                var fileName = Guid.NewGuid().ToString();

                // Download PDF locally for viewing
                using (var httpClient = new HttpClient())
                {
                    var pdfStream = Task.Run(() => httpClient.GetStreamAsync(url)).Result;

                    localPath =
                        Task.Run(() => dependency.SaveFileToDisk(pdfStream, $"{fileName}.pdf")).Result;
                }

                if (string.IsNullOrWhiteSpace(localPath))
                {
                    DisplayAlert("Error loading PDF", "Computer says no", "OK");

                    return;
                }
            }

            if (Device.RuntimePlatform == Device.Android)
                PdfView.Source = $"file:///android_asset/pdfjs/web/viewer.html?file={WebUtility.UrlEncode(localPath)}";
            else
                PdfView.Source = url;
        }

now this is working with local pdf i have web api url and i need to get pdf from there its online....... this is the link
http://veezo2007pkk.somee.com/api/DiagnosticDetail/RetrieveFile/1

Best Answer

Answers

Sign In or Register to comment.