Esempio n. 1
0
        /// <summary>
        /// Creates a PNG from the contents of a Xamarin.Forms.WebView
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static async Task <ToFileResult> ToPngAsync(this Xamarin.Forms.WebView webView, string fileName)
        {
            _platformToPngService = _platformToPngService ?? DependencyService.Get <IToPngService>();
            if (_platformToPngService == null)
            {
                throw new NotSupportedException("Cannot get HtmlService: must not be supported on this platform.");
            }
            ToFileResult result = null;

            using (var indicator = ActivityIndicatorPopup.Create())
            {
                result = await _platformToPngService.ToPngAsync(webView, fileName);
            }
            await Task.Delay(50);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a PNG from the contents of a Xamarin.Forms.WebView
        /// </summary>
        /// <param name="webView">Xamarin.Forms.WebView</param>
        /// <param name="fileName">Name (not path), excluding suffix, of PNG file</param>
        /// <param name="width">Width of resulting PNG (in pixels).</param>
        /// <returns></returns>
        public static async Task <ToFileResult> ToPngAsync(this Xamarin.Forms.WebView webView, string fileName, int width = -1)
        {
            _platformToPngService = _platformToPngService ?? DependencyService.Get <IToPngService>();
            if (_platformToPngService == null)
            {
                throw new NotSupportedException("Cannot get HtmlService: must not be supported on this platform.");
            }
            ToFileResult result = null;

            using (var indicator = ActivityIndicatorPopup.Create())
            {
                if (width <= 0)
                {
                    width = (int)Math.Ceiling((PageSize.Default.Width - (12 * 25.4)) * 4);
                }
                result = await _platformToPngService.ToPngAsync(webView, fileName, width);
            }
            await Task.Delay(50);

            return(result);
        }