コード例 #1
0
        public void PrintHtml(string html)
        {
            var webview = new Android.Webkit.WebView(MainActivity.Instance);

            webview.SetWebViewClient(new PrintHTMLWebClient());
            webview.LoadDataWithBaseURL(null, html, "text/HTML", "UTF-8", null);
        }
コード例 #2
0
ファイル: PDFService_Android.cs プロジェクト: GeorGeWzw/Forms
        public async Task <string> ConvertHtmlToPDF(string html, string fileName)
        {
            var dir  = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Download/");
            var file = new Java.IO.File(dir + "/" + fileName + ".pdf");

            if (!dir.Exists())
            {
                dir.Mkdirs();
            }

            int x = 0;

            while (file.Exists())
            {
                x++;
                file = new Java.IO.File(dir + "/" + fileName + "(" + x + ")" + ".pdf");
            }

            var webpage = new Android.Webkit.WebView(MainActivity.Instance);
            //var windowManager = MainActivity.Instance.GetSystemService(Android.Content.Context.WindowService);
            //DisplayMetrics outMetrics = new DisplayMetrics();
            //windowManager.DefaultDisplay.GetMetrics(outMetrics);
            //int widthPixels = outMetrics.WidthPixels;
            //int heightPixels = outMetrics.HeightPixels;

            //int width = widthPixels;
            //int height = heightPixels;
            int width  = 2102;
            int height = 2937;

            webpage.Layout(0, 0, width, height);

            var client      = new WebViewCallBack(file.ToString());
            var tokenSource = new CancellationTokenSource();
            var task        = Task.Run(() =>
            {
                if (tokenSource.Token.IsCancellationRequested)
                {
                    return;
                }
                while (true)
                {
                    if (tokenSource.Token.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }, tokenSource.Token);

            client.OnPageLoadFinished += (s, e) =>
            {
                tokenSource.Cancel();
            };
            webpage.SetWebViewClient(client);
            webpage.LoadDataWithBaseURL("", html, "text/html", "UTF-8", null);

            await task;

            return(file.ToString());
        }
コード例 #3
0
ファイル: WebView.Android.cs プロジェクト: unoplatform/uno
        partial void NavigateToStringPartial(string text)
        {
            if (!this.VerifyWebViewAvailability())
            {
                return;
            }

            _wasLoadedFromString = true;
            //Note : _webView.LoadData does not work properly on Android 10 even when we encode to base64.
            _webView.LoadDataWithBaseURL(null, text, "text/html; charset=utf-8", "utf-8", null);
        }
コード例 #4
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //var ignored = base.OnCreateView(inflater, container, savedInstanceState);
            //return inflater.Inflate(Resource.Layout.fragRules3, null);
            var ignored = base.OnCreateView(inflater, container, savedInstanceState);

            View v = inflater.Inflate(Resource.Layout.fragRules1, container, false);

            Android.Webkit.WebView webView = v.FindViewById <WebView>(Resource.Id.wvw_Rules);

            //webView.LoadUrl("https://google.com");

            //webView.Settings.JavaScriptEnabled = true;
            //webView.SetWebViewClient(new WebViewClient());

            //<><><><><><><><><><><><><><><><><><><><><><><><><>
            //Use this to return content of a text file as a List from
            //Files included as Assets in the OS-specific native Project. Pass Filename only with extension (i.e. DartRules.txt)
            Activities.Activity3 activity      = new Activities.Activity3();
            List <string>        infoRequested = activity.GetStoredInfo(infoFile: "DartRules.txt");

            StringBuilder sb = new StringBuilder();

            foreach (string strOut in infoRequested)
            {
                System.Diagnostics.Debug.Print(strOut);

                if (0 == strOut.Trim().Length)
                {
                    sb.Append("<br/>");
                }
                else
                {
                    sb.Append(strOut);
                }
            }

            webView.LoadDataWithBaseURL(null, @"<html><body><h1>Strike Out</h1><p>" + sb.ToString() + "</p></body></html>", "text/html", "utf-8", null);


            return(v);
        }