예제 #1
0
        public override async Task <bool> PrintFromURLAsync(string url, PrintJobConfiguration printJobConfiguration)
        {
            bool result = false;

            try
            {
                if (PrintFromURLAsyncSupported)
                {
                    WebViewPrintClientSubclass webViewClientSubclass = new WebViewPrintClientSubclass(url, printJobConfiguration); // TODO - check that this is disposed
                    webViewClientSubclass.Run();
                    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);
        }
예제 #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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pages"></param>
        /// <param name="destination"></param>
        /// <param name="cancellationSignal"></param>
        /// <param name="callback"></param>
        public override async void OnWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback)
        {
            _input  = null;
            _output = null;

            try
            {
                _input  = new FileInputStream(FileToPrint);                 // if we use using on this, we get an ObjectDisposedException // TODO - investigate further
                _output = new FileOutputStream(destination.FileDescriptor); // if we use using on this, we get an ObjectDisposedException // TODO - investigate further

                byte[] buf = new byte[1024];
                int    bytesRead;

                while ((bytesRead = _input.Read(buf)) > 0)
                {
                    _output.Write(buf, 0, bytesRead);
                }

                callback.OnWriteFinished(new PageRange[] { PageRange.AllPages });
            }
            catch (Java.IO.FileNotFoundException ee)
            {
                await PrintStatusReporting.ReportExceptionSilentlyAsync(ee);
            }
            catch (Java.Lang.Exception jlex)
            {
                await PrintStatusReporting.ReportExceptionSilentlyAsync(jlex);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (System.Exception e)
            {
                await PrintStatusReporting.ReportExceptionSilentlyAsync(e);
            }
#pragma warning restore CA1031 // Do not catch general exception types
            finally
            {
                try
                {
                    if (!(_input is null))
                    {
                        _input.Close();
                        _input = null;
                    }

                    if (!(_output is null))
                    {
                        _output.Close();
                        _output = null;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (System.Exception e)
                {
                    await PrintStatusReporting.ReportExceptionSilentlyAsync(e);
                }
#pragma warning restore CA1031 // Do not catch general exception types
            }
        }
예제 #4
0
        /// <summary>
        /// Unwire all events as part of cleanup.
        /// </summary>
        public virtual void UnwireAllEvents() => Xamarin.Forms.Device.BeginInvokeOnMainThread(
            async() =>
        {
            try
            {
                if (_printManager != null)
                {
                    PrintManagerHelper.Instance.ClearPrintTaskRequestedHandler(_printManager);
                    //_printManager.PrintTaskRequested -= PrintTaskRequested;
                    _printManager = null;
                }

                if (_printTask != null)
                {
                    _printTask.Completed -= PrintTaskCompleted;
                    //_printTask.Previewing -= PrintTask_Previewing;
                    //_printTask.Progressing -= PrintTask_Progressing;
                    //_printTask.Submitting -= PrintTask_Submitting;

#if DEBUG
                    DecrementCompletedCount();
                    //DecrementPreviewing();
                    //DecrementProgressing();
                    //DecrementSubmitting();
#endif

                    Windows.Graphics.Printing.OptionDetails.PrintTaskOptionDetails printDetailedOptions
                        = Windows.Graphics.Printing.OptionDetails.PrintTaskOptionDetails.GetFromPrintTaskOptions(_printTask.Options);

                    if (printDetailedOptions != null)
                    {
                        printDetailedOptions.OptionChanged -= PrintDetailedOptions_OptionChanged;
#if DEBUG
                        DecrementOptionChangedCount();
#endif
                    }
                }

                if (_printDocument != null)
                {
                    _printDocument.GetPreviewPage -= GetPrintPreviewPage;
                    _printDocument.Paginate       -= CreatePrintPreviewPages;
                    _printDocument.AddPages       -= AddPrintPages;

#if DEBUG
                    DecrementGetPreviewPageCount();
                    DecrementPaginateCount();
                    DecrementAddPagesCount();
#endif
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                await PrintStatusReporting.ReportExceptionSilentlyAsync(ex);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        });