Example #1
0
        private static void LinkAssemblies()
        {
            if (false.Equals(true))
            {
#pragma warning disable IDE0067 // Dispose objects before losing scope
#pragma warning disable IDE0059 // Unnecessary assignment of a value
                var r1 = new ColorGradientBoxRenderer();
                var r2 = new EnhancedListViewRenderer();
                var r3 = new HardwareKeyPageRenderer();
                var r4 = new LabelRenderer();
                var r5 = new PopupBaseRenderer();

                var e1 = new EmbeddedResourceFontEffect();
                var e2 = new PopupLayerEffect();
                var e3 = new SliderStepSizeEffect();

                var c1 = new ClipboardService();
                var c2 = new MimeItemCollection();
                var c3 = new NSDataItem();
                var c4 = new LazyMimeItem();
                var c5 = new SharingService();

                var s1 = new ApplicationInfoService();
                var s2 = new AudioService();
                var s3 = new DescendentBounds();
                var s4 = new FontService();
                var s5 = new HapticService();
                var s6 = new ToPngService();
                var s7 = new KeyboardService();
                var s8 = new OsInfoService();
                var s9 = new PrintService();
#pragma warning restore IDE0059 // Unnecessary assignment of a value
#pragma warning restore IDE0067 // Dispose objects before losing scope
            }
        }
Example #2
0
        async Task NavigationComplete(WKWebView webView, string filename, PageSize pageSize, PageMargin margin, TaskCompletionSource <ToFileResult> taskCompletionSource)
        {
            try
            {
                var widthString = await webView.EvaluateJavaScriptAsync("document.documentElement.offsetWidth");

                var width = double.Parse(widthString.ToString());

                var heightString = await webView.EvaluateJavaScriptAsync("document.documentElement.offsetHeight");

                var height = double.Parse(heightString.ToString());

                if (width < 1 || height < 1)
                {
                    taskCompletionSource.SetResult(new ToFileResult(true, "WebView has zero width or height"));
                    return;
                }

                webView.ClipsToBounds            = false;
                webView.ScrollView.ClipsToBounds = false;

                var bounds = webView.Bounds;
                webView.Bounds = new CGRect(0, 0, (nfloat)width, (nfloat)height);

                var scale = pageSize.Width / width;


                var snapshotConfig = new WKSnapshotConfiguration
                {
                    SnapshotWidth = pageSize.Width / Display.Scale
                };

                var image = await webView.TakeSnapshotAsync(snapshotConfig);

                if (image.AsPNG() is NSData data)
                {
                    var path = Path.Combine(ToPngService.FolderPath(), filename + ".png");
                    File.WriteAllBytes(path, data.ToArray());
                    taskCompletionSource.SetResult(new ToFileResult(false, path));
                    return;
                }
                webView.Bounds = bounds;
                taskCompletionSource.SetResult(new ToFileResult(true, "No data returned."));
            }
            catch (Exception e)
            {
                taskCompletionSource.SetResult(new ToFileResult(true, "Exception: " + e.Message + (e.InnerException != null
                    ? "Inner exception: " + e.InnerException.Message
                    : null)));
            }
            finally
            {
                webView.Dispose();
            }
        }
Example #3
0
        /*
         * public void ToPdf(TaskCompletionSource<ToFileResult> taskCompletionSource, WebView xfWebView, string fileName)
         * {
         *  if (xfWebView.Effects.Any(e=>e is Forms9Patch.WebViewPrintEffect))
         *  {
         *
         *  }
         * }
         */

        async Task NavigationComplete(WKWebView webView, string filename, PageSize pageSize, PageMargin margin, TaskCompletionSource <ToFileResult> taskCompletionSource)
        {
            try
            {
                var widthString = await webView.EvaluateJavaScriptAsync("document.documentElement.offsetWidth");

                var width = double.Parse(widthString.ToString());

                var heightString = await webView.EvaluateJavaScriptAsync("document.documentElement.offsetHeight");

                var height = double.Parse(heightString.ToString());

                if (width < 1 || height < 1)
                {
                    taskCompletionSource.SetResult(new ToFileResult(true, "WebView has zero width or height"));
                    return;
                }

                webView.ClipsToBounds            = false;
                webView.ScrollView.ClipsToBounds = false;

                if (webView.CreatePdfFile(webView.ViewPrintFormatter, pageSize, margin) is NSMutableData data)
                {
                    var path = System.IO.Path.Combine(ToPngService.FolderPath(), filename + ".pdf");
                    System.IO.File.WriteAllBytes(path, data.ToArray());
                    taskCompletionSource.SetResult(new ToFileResult(false, path));
                    data.Dispose();
                    return;
                }
                taskCompletionSource.SetResult(new ToFileResult(true, "No data returned."));
            }
            catch (Exception e)
            {
                taskCompletionSource.SetResult(new ToFileResult(true, "Exception: " + e.Message + (e.InnerException != null
                    ? "Inner exception: " + e.InnerException.Message
                    : null)));
            }
            finally
            {
                webView.Dispose();
            }
        }