private void CallPrint()
        {
            var printInfo = UIPrintInfo.PrintInfo;

            printInfo.OutputType = UIPrintInfoOutputType.General;
            printInfo.JobName    = "Chart";

            var textFormatter = new UISimpleTextPrintFormatter("Once upon a time...")
            {
                StartPage           = 0,
                ContentInsets       = new UIEdgeInsets(72, 72, 72, 72),
                MaximumContentWidth = 6 * 72,
            };

            var printer = UIPrintInteractionController.SharedPrintController;

            printer.PrintInfo      = printInfo;
            printer.PrintFormatter = textFormatter;
            printer.ShowsPageRange = true;
            printer.Present(true, (handler, completed, err) => {
                if (!completed && err != null)
                {
                    Console.WriteLine("error");
                }
            });
        }
Пример #2
0
        partial void Print(UIButton sender)
        {
            var printInfo = UIPrintInfo.PrintInfo;

            printInfo.JobName    = "My first Print Job";
            printInfo.OutputType = UIPrintInfoOutputType.General;

            var textFormatter = new UISimpleTextPrintFormatter("Once upon a time...")
            {
                StartPage            = 0,
                MaximumContentWidth  = 6 * 72,
                PerPageContentInsets = new UIEdgeInsets(72, 72, 72, 72),
            };

            var printer = UIPrintInteractionController.SharedPrintController;

            printer.PrintInfo      = printInfo;
            printer.PrintFormatter = textFormatter;
            printer.ShowsPageRange = true;
            printer.Present(true, (handler, completed, error) =>
            {
                if (!completed && error != null)
                {
                    Console.WriteLine($"Error: {error.LocalizedDescription ?? ""}");
                }
            });

            printInfo.Dispose();
            textFormatter.Dispose();
        }
 public void DefaultCtor()
 {
     using (var stpf = new UISimpleTextPrintFormatter()) {
         Assert.That(stpf.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
         if (TestRuntime.CheckXcodeVersion(11, 0))
         {
             Assert.NotNull(stpf.Color, "Color");
             Assert.Null(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
         {
             Assert.Null(stpf.Color, "Color");
             Assert.Null(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else
         {
             Assert.That(stpf.Color, Is.EqualTo(UIColor.Black), "Color");
             Assert.NotNull(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Left), "TextAlignment");
         }
         Assert.That(stpf.Text, Is.Empty, "Text");
     }
 }
        public void Print(string text)
        {
            var printInfo = UIPrintInfo.PrintInfo;

            printInfo.OutputType = UIPrintInfoOutputType.General;
            printInfo.JobName    = "Print Job " + DateTime.Now.ToString();

            var textFormatter = new UISimpleTextPrintFormatter(text)
            {
                StartPage           = 0,
                ContentInsets       = new UIEdgeInsets(72, 72, 72, 72),
                MaximumContentWidth = 6 * 72,
            };

            var printer = UIPrintInteractionController.SharedPrintController;

            printer.PrintInfo      = printInfo;
            printer.PrintFormatter = textFormatter;
            printer.ShowsPageRange = true;
            printer.Present(true, (handler, completed, err) => {
                if (!completed && err != null)
                {
                    Console.WriteLine("error");
                }
            });
        }
		public void Print (object sender, EventArgs args)
		{
			UIPrintInteractionController controller = UIPrintInteractionController.SharedPrintController;
			if (controller == null) {
				Console.WriteLine ("Couldn't get shared UIPrintInteractionController");
				return;
			}

			controller.CutLengthForPaper = delegate (UIPrintInteractionController printController, UIPrintPaper paper) {
				// Create a font with arbitrary size so that you can calculate the approximate
  				// font points per screen point for the height of the text.
				UIFont font = textformatter.Font;

				NSString str = new NSString (textField.Text);
				UIStringAttributes attributes = new UIStringAttributes ();
				attributes.Font = font;
				CGSize size = str.GetSizeUsingAttributes (attributes);

				nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height;

				// Create a new font using a size  that will fill the width of the paper
				font = SelectFont ((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint));

				// Calculate the height and width of the text with the final font size
				attributes.Font = font;
				CGSize finalTextSize = str.GetSizeUsingAttributes (attributes);

				// Set the UISimpleTextFormatter font to the font with the size calculated
				textformatter.Font = font;

				// Calculate the margins of the roll. Roll printers may have unprintable areas
			    // before and after the cut.  We must add this to our cut length to ensure the
			    // printable area has enough room for our text.
				nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height;

				// The cut length is the width of the text, plus margins, plus some padding
				return finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor;
			};

			UIPrintInfo printInfo = UIPrintInfo.PrintInfo;
			printInfo.OutputType = UIPrintInfoOutputType.General;
			printInfo.Orientation = UIPrintInfoOrientation.Landscape;
			printInfo.JobName = textField.Text;

			textformatter = new UISimpleTextPrintFormatter (textField.Text) {
				Color = SelectedColor,
				Font = SelectFont ()
			};

			controller.PrintInfo = printInfo;
			controller.PrintFormatter = textformatter;

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
				controller.PresentFromRectInView (printButton.Frame, View, true, PrintingComplete);
			else
				controller.Present (true, PrintingComplete);
		}
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (textFormatter != null)
     {
         textFormatter.Dispose();
         textFormatter = null;
     }
 }
        partial void Print(UIButton sender)
        {
            var controller = UIPrintInteractionController.SharedPrintController;

            controller.CutLengthForPaper = delegate(UIPrintInteractionController printController, UIPrintPaper paper)
            {
                // Create a font with arbitrary size so that you can calculate the approximate
                // font points per screen point for the height of the text.
                var font = textFormatter.Font;

                var text       = new NSString(textField.Text);
                var attributes = new UIStringAttributes {
                    Font = font
                };
                var size = text.GetSizeUsingAttributes(attributes);

                nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height;

                // Create a new font using a size  that will fill the width of the paper
                font = GetSelectedFont((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint));

                // Calculate the height and width of the text with the final font size
                attributes.Font = font;
                var finalTextSize = text.GetSizeUsingAttributes(attributes);

                // Set the UISimpleTextFormatter font to the font with the size calculated
                textFormatter.Font = font;

                // Calculate the margins of the roll. Roll printers may have unprintable areas
                // before and after the cut.  We must add this to our cut length to ensure the
                // printable area has enough room for our text.
                nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height;

                // The cut length is the width of the text, plus margins, plus some padding
                return(finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor);
            };

            var printInfo = UIPrintInfo.PrintInfo;

            printInfo.OutputType  = UIPrintInfoOutputType.General;
            printInfo.Orientation = UIPrintInfoOrientation.Landscape;
            printInfo.JobName     = textField.Text;

            textFormatter = new UISimpleTextPrintFormatter(textField.Text)
            {
                Color = GetSelectedColor(),
                Font  = GetSelectedFont()
            };

            controller.PrintInfo      = printInfo;
            controller.PrintFormatter = textFormatter;
            controller.Present(true, OnPrintingComplete);

            printInfo.Dispose();
            printInfo = null;
        }
 public void StringCtor()
 {
     using (var stpf = new UISimpleTextPrintFormatter("Xamarin")) {
         if (TestRuntime.CheckSystemAndSDKVersion(7, 0))
         {
             Assert.Null(stpf.Color, "Color");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else
         {
             Assert.That(stpf.Color, Is.EqualTo(UIColor.Black), "Color");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Left), "TextAlignment");
         }
         Assert.NotNull(stpf.Font, "Font");
         Assert.That(stpf.Text, Is.EqualTo("Xamarin"), "Text");
     }
 }
 public void DefaultCtor()
 {
     using (var stpf = new UISimpleTextPrintFormatter()) {
         Assert.That(stpf.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
         if (TestRuntime.CheckSystemAndSDKVersion(7, 0))
         {
             Assert.Null(stpf.Color, "Color");
             Assert.Null(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else
         {
             Assert.That(stpf.Color, Is.EqualTo(UIColor.Black), "Color");
             Assert.NotNull(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Left), "TextAlignment");
         }
         Assert.That(stpf.Text, Is.Empty, "Text");
     }
 }
Пример #10
0
		void Print ()
		{
			var printInfo = UIPrintInfo.PrintInfo;
			printInfo.OutputType = UIPrintInfoOutputType.General;
			printInfo.JobName = "My first Print Job";
			
			var textFormatter = new UISimpleTextPrintFormatter ("Once upon a time...") {
				StartPage = 0,
				ContentInsets = new UIEdgeInsets (72, 72, 72, 72),
				MaximumContentWidth = 6 * 72,
			};
			
			var printer = UIPrintInteractionController.SharedPrintController;
			printer.PrintInfo = printInfo;
			printer.PrintFormatter = textFormatter;
			printer.ShowsPageRange = true;
			printer.Present (true, (handler, completed, err) => {
				if (!completed && err != null){
					Console.WriteLine ("error");
				}
			});
		}
 public void StringCtor()
 {
     using (var stpf = new UISimpleTextPrintFormatter("Xamarin")) {
         if (TestRuntime.CheckXcodeVersion(11, 0))
         {
             Assert.NotNull(stpf.Color, "Color");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
         {
             Assert.Null(stpf.Color, "Color");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else
         {
             Assert.That(stpf.Color, Is.EqualTo(UIColor.Black), "Color");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Left), "TextAlignment");
         }
         Assert.NotNull(stpf.Font, "Font");
         Assert.That(stpf.Text, Is.EqualTo("Xamarin"), "Text");
     }
 }
        public void Print(object sender, EventArgs args)
        {
            UIPrintInteractionController controller = UIPrintInteractionController.SharedPrintController;

            if (controller == null)
            {
                Console.WriteLine("Couldn't get shared UIPrintInteractionController");
                return;
            }

            controller.CutLengthForPaper = delegate(UIPrintInteractionController printController, UIPrintPaper paper) {
                // Create a font with arbitrary size so that you can calculate the approximate
                // font points per screen point for the height of the text.
                UIFont font = textformatter.Font;

                NSString           str        = new NSString(textField.Text);
                UIStringAttributes attributes = new UIStringAttributes();
                attributes.Font = font;
                CGSize size = str.GetSizeUsingAttributes(attributes);

                nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height;

                // Create a new font using a size  that will fill the width of the paper
                font = SelectFont((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint));

                // Calculate the height and width of the text with the final font size
                attributes.Font = font;
                CGSize finalTextSize = str.GetSizeUsingAttributes(attributes);

                // Set the UISimpleTextFormatter font to the font with the size calculated
                textformatter.Font = font;

                // Calculate the margins of the roll. Roll printers may have unprintable areas
                // before and after the cut.  We must add this to our cut length to ensure the
                // printable area has enough room for our text.
                nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height;

                // The cut length is the width of the text, plus margins, plus some padding
                return(finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor);
            };

            UIPrintInfo printInfo = UIPrintInfo.PrintInfo;

            printInfo.OutputType  = UIPrintInfoOutputType.General;
            printInfo.Orientation = UIPrintInfoOrientation.Landscape;
            printInfo.JobName     = textField.Text;

            textformatter = new UISimpleTextPrintFormatter(textField.Text)
            {
                Color = SelectedColor,
                Font  = SelectFont()
            };

            controller.PrintInfo      = printInfo;
            controller.PrintFormatter = textformatter;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                controller.PresentFromRectInView(printButton.Frame, View, true, PrintingComplete);
            }
            else
            {
                controller.Present(true, PrintingComplete);
            }
        }