示例#1
0
        /// <summary>
        /// Creates the web print job.
        /// </summary>
        /// <param name="webView">The web view to print.</param>
        private void CreateWebPrintJob(WebView webView)
        {
            // Create the printing resources
            PrintManager printManager = (PrintManager)activity.GetSystemService(Context.PrintService);

            if (printManager != null)
            {
                // Create the print job with the name and adapter
                string jobName = activity.GetString(Resource.String.print_name);
                PrintDocumentAdapter printAdapter = webView.CreatePrintDocumentAdapter(jobName);

                MAMPrintManagement.Print(printManager, jobName, printAdapter, null);
            }
            else
            {
                Toast.MakeText(activity, Resource.String.print_failure, ToastLength.Long).Show();
            }
        }
        /// <summary>
        /// Creates the web print job.
        /// </summary>
        /// <param name="webView">The web view to print.</param>
        private void CreateWebPrintJob(WebView webView)
        {
            // Create the printing resources
            PrintManager printManager = (PrintManager)Xamarin.Forms.Forms.Context.GetSystemService(Context.PrintService);

            if (printManager == null)
            {
                Toast.MakeText(Application.Context, Resource.String.print_failure, ToastLength.Long).Show();
                return;
            }

            try
            {
                // Create the print job with the name and adapter
                PrintDocumentAdapter printAdapter = webView.CreatePrintDocumentAdapter(Application.Context.GetString(Resource.String.print_name));
                MAMPrintManagement.Print(printManager, Application.Context.GetString(Resource.String.print_name), printAdapter, null);
            }
            catch (Exception ex)
            {
                Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show();
            }
        }