コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 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?
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void Run()
 {
     _webView = new Android.Webkit.WebView(PrintServiceAndroidHelper.ActivityInstance);
     _webView.LoadUrl(_url);
     PrintServiceAndroidHelper.PrintFromWebView(_webView, _printJobConfiguration);
 }