Beispiel #1
0
        public void ToPng(string html, string fileName, Action <string> onComplete)
        {
            if (CanWriteExternalStorage())
            {
                var size         = new Size(8.5, 11);
                var externalPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
                var dir          = new Java.IO.File(externalPath);
                var file         = new Java.IO.File(dir + "/" + fileName + ".png");
                if (!dir.Exists())
                {
                    dir.Mkdir();
                }
                if (file.Exists())
                {
                    file.Delete();
                }

                var webView = new CustomWebView(Android.App.Application.Context);
                webView.Settings.JavaScriptEnabled = true;
                webView.DrawingCacheEnabled        = true;

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

                webView.LoadData(html, "text/html; charset=utf-8", "UTF-8");
                webView.SetWebViewClient(new WebViewCallBack(fileName, onComplete));
            }
            else
            {
                onComplete.Invoke(null);
            }
        }
Beispiel #2
0
        /*
         * private void RequestPermission(Android.App.Activity context)
         * {
         *  var hasPermission = (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(context, Android.Manifest.Permission.WriteExternalStorage) == Android.Content.PM.Permission.Granted);
         *  if (!hasPermission)
         *  {
         *      Android.Support.V4.App.ActivityCompat.RequestPermissions(context,
         *          new string[] { Android.Manifest.Permission.WriteExternalStorage },
         *                                                               007);// REQUEST_WRITE_STORAGE);
         *  }
         *  else
         *  {
         *      // You are allowed to write external storage:
         *      var path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/new_folder";
         *      var storageDir = new Java.IO.File(path);
         *      if (!storageDir.Exists() && !storageDir.Mkdirs())
         *      {
         *          // This should never happen - log handled exception!
         *      }
         *  }
         * }
         */

        public override void OnPageFinished(Android.Webkit.WebView view, string url)
        {
            webView = view as CustomWebView;
            webView.EvaluateJavascript("Math.max( document.body.scrollHeight, document.body.offsetHeight)", this);
        }