如何使用pdfjs xamarin从url显示pdf

时间:2018-05-03 11:32:25

标签: c# xamarin asp.net-web-api xamarin.forms

我使用过pdfjs并且使用本地存储pdf工作得很好,但我有其他问题我需要从web api显示pdf,因为我已经存储了我需要显示的pdf的二进制数据?这是我的代码

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;
        }

现在这是与本地pdf合作我有web api url,我需要从那里得到pdf在线.......这是链接 http://veezo2007pkk.somee.com/api/DiagnosticDetail/RetrieveFile/1

0 个答案:

没有答案