public void ToPdf(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string fileName, PageSize pageSize, PageMargin margin) { var externalPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; using (var dir = new Java.IO.File(externalPath)) using (var file = new Java.IO.File(dir + "/" + fileName + ".pdf")) { if (!dir.Exists()) { dir.Mkdir(); } if (file.Exists()) { file.Delete(); } var webView = new Android.Webkit.WebView(Android.App.Application.Context); webView.Settings.JavaScriptEnabled = 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(0, 0, (int)System.Math.Ceiling(pageSize.Width), (int)System.Math.Ceiling(pageSize.Height)); webView.LoadData(html, "text/html; charset=utf-8", "UTF-8"); webView.SetWebViewClient(new WebViewCallBack(taskCompletionSource, fileName, pageSize, margin, OnPageFinished)); } }
public void ToPng(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string fileName, int width) { //var size = new Size(8.5, 11); //var externalPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; //using (var dir = new Java.IO.File(externalPath)) //using (var file = new Java.IO.File(dir + "/" + fileName + ".png")) //{ // if (!dir.Exists()) // dir.Mkdir(); // if (file.Exists()) // file.Delete(); var webView = new Android.Webkit.WebView(Android.App.Application.Context); webView.Settings.JavaScriptEnabled = 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(0, 0, width, width); webView.SetWebViewClient(new WebViewCallBack(taskCompletionSource, fileName, new PageSize { Width = width }, null, OnPageFinished)); webView.LoadData(html, "text/html; charset=utf-8", "UTF-8"); //} }
partial void NavigateToStringPartial(string text) { if (!this.VerifyWebViewAvailability()) { return; } _wasLoadedFromString = true; _webView.LoadData(text, "text/html; charset=utf-8", "utf-8"); }