Exemple #1
0
        void InnerPrint(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string jobName, FailAction failAction)
        {
            try
            {
                var size    = new Size(8.5, 11);
                var webView = new Android.Webkit.WebView(Android.App.Application.Context);
                webView.Settings.JavaScriptEnabled = true;
                webView.Settings.DomStorageEnabled = true;
#pragma warning disable CS0618 // Type or member is obsolete
                webView.DrawingCacheEnabled = true;
#pragma warning restore CS0618 // Type or member is obsolete
                webView.SetLayerType(LayerType.Software, null);

                //webView.Layout(0, 0, (int)((size.Width - 0.5) * 72), (int)((size.Height - 0.5) * 72));
                webView.Layout(36, 36, (int)((PageSize.Default.Width - 0.5) * 72), (int)((PageSize.Default.Height - 0.5) * 72));

                webView.SetWebViewClient(new WebViewCallBack(taskCompletionSource, jobName, PageSize.Default, null, OnPageFinished));
                webView.LoadData(html, "text/html; charset=utf-8", "UTF-8");
            }
            catch (Exception e)
            {
                if (failAction == FailAction.ShowAlert)
                {
                    using (Forms9Patch.Alert.Create("Print Failure", e.Message)) { }
                }
                else if (failAction == FailAction.ThrowException)
                {
                    throw e;
                }
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.MarkUp);

            // Get our buttonTransform from the layout resource,
            // and attach an event to it
            Button buttonTransform = FindViewById <Button>(Resource.Id.Transform);

            Android.Webkit.WebView browser = FindViewById <Android.Webkit.WebView>(Resource.Id.webView1);

            string html = "";

            html = BusinessLogicObject.MarkUpHTML;

            if (Android.OS.Build.VERSION.Release.StartsWith("2."))
            {
                // http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
                // In 2.x platforms loadData() fails in some cases (it requires the html to be escaped),
                // use loadDataWithBaseURL() instead and pass null for baseUrl and historyUrl:

                //html = Java.Net.URLEncoder.Encode(BusinessLogicObject.MarkUpHTML).Replace("\\+", " ");
                browser.LoadDataWithBaseURL(null, html, "text/html", "utf-8", null);
            }
            else
            {
                browser.LoadData(BusinessLogicObject.MarkUpHTML, mime, encoding);
            }

            buttonTransform.Click += new EventHandler(buttonTransform_Click);

            return;
        }
Exemple #3
0
        private void CallbackCarregarDades()
        {
            Android.Webkit.WebView wc = FindViewById <Android.Webkit.WebView>(Resource.Id.webView1);
            string html = "<html><body>";

            foreach (var titol in carregador.getTitle())
            {
                html += "<h2>" + titol + "</h2>";
            }
            html += "</body></html>";
            wc.LoadData(html, "text/html; charset=UTF-8", "ISO-8859-1");
        }
Exemple #4
0
        void InnerPrint(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string jobName)
        {
            var size    = new Size(8.5, 11);
            var webView = new Android.Webkit.WebView(Android.App.Application.Context);

            webView.Settings.JavaScriptEnabled = true;
            webView.Settings.DomStorageEnabled = true;
#pragma warning disable CS0618 // Type or member is obsolete
            webView.DrawingCacheEnabled = true;
#pragma warning restore CS0618 // Type or member is obsolete
            webView.SetLayerType(LayerType.Software, null);

            webView.Layout(0, 0, (int)((size.Width - 0.5) * 72), (int)((size.Height - 0.5) * 72));

            webView.SetWebViewClient(new WebViewCallBack(taskCompletionSource, jobName, OnPageFinished));
            webView.LoadData(html, "text/html; charset=utf-8", "UTF-8");
        }
Exemple #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.myButton);

            button.Click += delegate { button.Text = $"{count++} clicks!"; };

            Android.Webkit.WebView webView = FindViewById <Android.Webkit.WebView>(Resource.Id.webView1);
            string html = @"<!DOCTYPE html>
<html>
    <head>
        <meta charset=""utf-8"">
        <title>test</title>
        <script src=""https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js""></script>

    </head>
    <body style=""background-color: red;"">
        <h1>测试</h1>
        <button>点击我</button>
        <script type=""text/javascript"">
            function H5Calc() {
                alert(""I'm H5"");
            }

            $(function() {
                $(""button"").click(function() {
                    test(""abc"");
                });
            });
        </script>
    </body>
</html>
";

            webView.LoadData(html, "text/html", "utf-8");
        }
        public void ConvertHTMLtoPDF(PDFToHtml _PDFToHtml)
        {
            try
            {
                var webpage = new Android.Webkit.WebView(Android.App.Application.Context);
                webpage.Settings.JavaScriptEnabled = true;

#pragma warning disable CS0618 // Type or member is obsolete
                webpage.DrawingCacheEnabled = true;
#pragma warning restore CS0618 // Type or member is obsolete

                webpage.SetLayerType(LayerType.Software, null);
                webpage.Layout(0, 0, (int)_PDFToHtml.PageWidth, (int)_PDFToHtml.PageHeight);
                webpage.LoadData(_PDFToHtml.HTMLString, "text/html; charset=utf-8", "UTF-8");
                webpage.SetWebViewClient(new WebViewCallBack(_PDFToHtml));
            }
            catch
            {
                _PDFToHtml.Status = PDFEnum.Failed;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            //if we have a new forms element, we want to update text with font style (as specified in forms-pcl) on native control
            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    //register webview as native control
                    var webView = new Android.Webkit.WebView(Context);
                    webView.VerticalScrollBarEnabled   = false;
                    webView.HorizontalScrollBarEnabled = false;

                    webView.LoadData("<html><body>&nbsp;</body></html>", "text/html; charset=utf-8", "utf-8");
                    SetNativeControl(webView);
                }

                //if we have a new forms element, we want to update text with font style (as specified in forms-pcl) on native control
                UpdateTextOnControl();
            }
        }
        public void print(string content)
        {
            try
            {
                var printManager = (Android.Print.PrintManager) this.ApplicationContext.GetSystemService(Context.PrintService);
                //var browser = new WebView();
                Android.Webkit.WebView s = new Android.Webkit.WebView(this.ApplicationContext);
                //wv.CreatePrintDocumentAdapter()
                //var htmlSource = new HtmlWebViewSource();
                //htmlSource.Html = content;
                //          htmlSource.Html = @"<html><body>
                //<h1>Xamarin.Forms</h1>
                //<p>Welcome to WebView.</p>
                //</body></html>";
                //WebView s = new WebView(this);
                s.LoadData(content, "text/html", "");

                //browser.Source = htmlSource;
                printManager.Print("testm", s.CreatePrintDocumentAdapter("pipi"), null);
            }
            catch (Exception ex)
            {
            }
        }