Ejemplo n.º 1
0
        private async void ToolbarItem_Clicked(object sender, EventArgs e)
        {
            mDocumentType = null;
            FileData fileData = await CrossFileHelper.CrossFileHelper.Current.PickFile();

            if (fileData != null)
            {
                mFileStream = fileData.GetStream();
                //using (mFileStream = await CrossFileHelper.CrossFileHelper.Current.GetFileReadStreamAsync(fileData.FilePath))
                //{
                mHtmlFileName = "Test.html";
                DocumentHelper documentHelper = new DocumentHelper();
                await documentHelper.ConvertToHTML(mFileStream, mHtmlFileName, mDocumentType);

                mFileStream.Dispose();
                mFileStream = null;
                //}
                string htmlContent = null;
                using (Stream htmlReaderStream = await DependencyService.Get <ISaveAndLoad>().GetLocalFileInputStreamAsync(mHtmlFileName))
                {
                    using (StreamReader streamReader = new StreamReader(htmlReaderStream))
                    {
                        htmlContent = await streamReader.ReadToEndAsync();
                    }
                }
                webView.Source = new HtmlWebViewSource
                {
                    Html = htmlContent
                };
            }
        }
Ejemplo n.º 2
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            LoadingSpinner.IsRunning = true;
            LoadingSpinner.IsVisible = true;

            if (mFileStream != null && !string.IsNullOrWhiteSpace(mDocumentType))
            {
                mHtmlFileName = "Test.html";

                DocumentHelper documentHelper = new DocumentHelper();
                await documentHelper.ConvertToHTML(mFileStream, mHtmlFileName, mDocumentType);

                mFileStream.Dispose();
                mFileStream = null;

                string htmlContent = null;
                using (Stream htmlReaderStream = await DependencyService.Get <ISaveAndLoad>().GetLocalFileInputStreamAsync(mHtmlFileName))
                {
                    using (StreamReader streamReader = new StreamReader(htmlReaderStream))
                    {
                        htmlContent = await streamReader.ReadToEndAsync();
                    }
                }

                webView.Source = new HtmlWebViewSource
                {
                    Html = htmlContent
                };
            }
            else
            {
                webView.Source = new HtmlWebViewSource
                {
                    Html = "<center>Choose file directly from file browser and choose open with My Document Viewer to open the file.</center>"
                };
            }
            LoadingSpinner.IsRunning = false;
            LoadingSpinner.IsVisible = false;
        }