Ejemplo n.º 1
0
        public override bool PrintDocumentFromWebView(object webView)
        {
            try {
                UIWebView platformWebView = (UIWebView)(webView as CustomWebView).PlatformControl;

                UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;

                printer.ShowsPageRange = true;

                printer.PrintInfo            = UIPrintInfo.PrintInfo;
                printer.PrintInfo.OutputType = UIPrintInfoOutputType.General;
                printer.PrintInfo.JobName    = "BodyReportJob";

                printer.PrintPageRenderer = new UIPrintPageRenderer()
                {
                    HeaderHeight = 40,
                    FooterHeight = 40
                };
                printer.PrintPageRenderer.AddPrintFormatter(platformWebView.ViewPrintFormatter, 0);

                if (Device.Idiom == TargetIdiom.Phone)
                {
                    printer.PresentAsync(true);
                }
                else if (Device.Idiom == TargetIdiom.Tablet)
                {
                    printer.PresentFromRectInViewAsync(new CGRect(200, 200, 0, 0), platformWebView, true);
                }

                return(true);
            } catch (Exception) {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private async Task <bool> PrintUIViewAsync(UIView uiView, PrintJobConfiguration printJobConfiguration)
        {
            bool result = false;

            UIPrintInteractionController printer = await PopulateCommonPrinterDetailsAsync(printJobConfiguration);

            if (!(printer is null))
            {
                printer.PrintPageRenderer = new UIPrintPageRenderer()
                {
                    HeaderHeight = 40,
                    FooterHeight = 40
                };
                printer.PrintPageRenderer.AddPrintFormatter(uiView.ViewPrintFormatter, 0);

                UIPrintInteractionResult interactionResult;

                if (Device.Idiom == TargetIdiom.Tablet) // TODO - move to ApplicationType
                {
                    interactionResult =
                        await printer.PresentFromRectInViewAsync(new CGRect(200, 200, 0, 0), uiView, true);
                }
                else
                {
                    interactionResult = await printer.PresentAsync(true);
                }

                PrintCompletion(
                    interactionResult.PrintInteractionController,
                    interactionResult.Completed,
                    null);
                result = interactionResult.Completed;
                printer.Dispose();
            }

            return(result);
        }