public override async Task <bool> PrintWebViewAsync( Page parentPage, WebView webView, IWebViewAdditionalFunctions webViewAdditionFunctions, PrintJobConfiguration printJobConfiguration) { bool result = false; try { if (PrintWebViewAsyncSupported && (webViewAdditionFunctions?.NativeControl is Android.Webkit.WebView nativeWebView)) { PrintServiceAndroidHelper.PrintFromWebView(nativeWebView, printJobConfiguration); result = true; } } catch (Java.Lang.Exception jlex) { await PrintStatusReporting.ReportExceptionSilentlyAsync(jlex); } #pragma warning disable CA1031 // Do not catch general exception types catch (System.Exception ex) { await PrintStatusReporting.ReportExceptionAsync(ex); } #pragma warning restore CA1031 // Do not catch general exception types return(result); }
/// <summary> /// Print the contents of a WebView /// </summary> /// <param name="parentPage">The page that the WebView is shown on.</param> /// <param name="webView">The Xamarin.Forms WebView.</param> /// <param name="webViewAdditionFunctions">Additional functions</param> /// <param name="printJobConfiguration">Configuration information for the print job.</param> /// <returns>true if attempting print, false otherwise.</returns> public override async Task <bool> PrintWebViewAsync( Page parentPage, WebView webView, IWebViewAdditionalFunctions webViewAdditionFunctions, PrintJobConfiguration printJobConfiguration) { bool result = false; try { // TODO - get rid of use of UIWebView as deprecated by Apple // See https://forums.xamarin.com/discussion/168620/itms-90338-non-public-api-usage-apple-rejected-my-app-xamarin#latest if (PrintWebViewAsyncSupported && (webViewAdditionFunctions?.NativeControl is UIWebView nativeWebView)) { using (nativeWebView) { result = await PrintUIViewAsync(nativeWebView, printJobConfiguration); } } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { await PrintStatusReporting.ReportExceptionAsync(ex); } #pragma warning restore CA1031 // Do not catch general exception types return(result); }
public override async Task <bool> PrintWebViewAsync( Page page, WebView webView, IWebViewAdditionalFunctions webViewAdditionFunctions, PrintJobConfiguration config) { bool result = false; try { if (PrintWebViewAsyncSupported) { if (!(webViewAdditionFunctions is null)) { await webViewAdditionFunctions.WaitForViewToBeInNativeLayout(page, 10, 100); WebViewPrintJob printJob = new WebViewPrintJob(config, webViewAdditionFunctions); //WebViewPrintJob printJob = new WebViewPrintJob(config, html); await printJob.PrintAsync(); result = true; } } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { await PrintStatusReporting.ReportExceptionAsync(ex); result = false; } #pragma warning restore CA1031 // Do not catch general exception types // TODO - does this want to be here??? printJob?.UnwireAllEvents(); return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="printJobConfiguration">Configuration information for the print job</param> /// <param name="webViewAdditionalFunctions">Interface that provides access to functionality required by this class. Typically, this interface will be implemented by a subclass of Xamarin.Forms.WebView</param> public WebViewPrintJob( PrintJobConfiguration printJobConfiguration, IWebViewAdditionalFunctions webViewAdditionalFunctions) : base(printJobConfiguration) { if (webViewAdditionalFunctions is null) { throw new PrintJobException( "EXCEPTION:PRN003 Invalid interface to native WebView", new ArgumentNullException(nameof(webViewAdditionalFunctions))); } else if (webViewAdditionalFunctions.NativeControl is null) { throw new PrintJobException( "EXCEPTION:PRN004 Invalid (null) native WebView"); } else if (!(webViewAdditionalFunctions.NativeControl is Windows.UI.Xaml.Controls.WebView)) { throw new PrintJobException( "EXCEPTION:PRN006 Invalid native WebView"); } _nativeWebView = (Windows.UI.Xaml.Controls.WebView)webViewAdditionalFunctions.NativeControl; }
public abstract Task <bool> PrintWebViewAsync(Page parentPage, WebView webView, IWebViewAdditionalFunctions webViewAdditionFunctions, PrintJobConfiguration config);