public override async Task <bool> PrintImageFromByteArrayAsync(byte[] content, PrintJobConfiguration printJobConfiguration) { // based on https://github.com/bushbert/XamarinPCLPrinting/blob/master/PCLPrintExample/PCLPrintExample/PCLPrintExample.Android/Print.cs bool result = false; try { if (PrintImageFromByteArrayAsyncSupported) { //using ( Stream inputStream = new MemoryStream(content); //) { PrintServiceAndroidHelper.PrintImageFromStream(inputStream, printJobConfiguration); result = true; } } } #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); }
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); }
public override void OnPageFinished(Android.Webkit.WebView webView, string url) { // TODO - investigate whether even using OnPageFinished is enough to always avoid getting a blank page output PrintServiceAndroidHelper.PrintFromWebView(webView, _printJobConfiguration); _printJobConfiguration = null; _webView.Dispose(); _webView = null; Dispose(); // is this legitimate? }
public override async Task <bool> PrintImageFromStreamAsync(Stream inputStream, PrintJobConfiguration printJobConfiguration) { bool result = false; try { if (PrintImageFromStreamAsyncSupported) { PrintServiceAndroidHelper.PrintImageFromStream(inputStream, printJobConfiguration); result = true; } } #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); }
public void Run() { _webView = new Android.Webkit.WebView(PrintServiceAndroidHelper.ActivityInstance); _webView.LoadUrl(_url); PrintServiceAndroidHelper.PrintFromWebView(_webView, _printJobConfiguration); }