Printing arbitrary text via a script

Locked
mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Printing arbitrary text via a script

Post by mark.monroe »

Below is an example script that can be used to send text to a printer. This only works in iX Developer 2.0.

Code: Select all

//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
    using Neo.ApplicationFramework.Common.Printer.Document;
    using Neo.ApplicationFramework.Common.Service;
    using Neo.ApplicationFramework.Interfaces.Printer;

    public partial class Screen1
    {
		
		void Button1_Click(System.Object sender, System.EventArgs e)
		{
			PrintMessage("Test");	
		}
		/// <summary>
		/// Service to print text to the print device
		/// setup by the alarmdistributor settings menu.
		/// </summary>
		void PrintMessage(string text)
		{
			IPrinterServiceCF printerService = ServiceContainerCF.GetServiceSafe<IPrinterServiceCF>();
			if (printerService != null)
			{				
				Paragraph paragraph = new Paragraph(text);
				
				FlowDocument flowDocument = new FlowDocument();
				flowDocument.Blocks.Add(paragraph);
				
				try 
				{	        
					printerService.SendToPrinterAsync(flowDocument);				
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}
			else
			{
				MessageBox.Show("No printer device configured!");
			}
		}
    }
}
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

User avatar
Chris T.
Posts: 109
Joined: Mon Nov 20, 2017 5:29 pm

Re: Printing arbitrary text via a script

Post by Chris T. »

Locked
Best regards,
Christopher
(801) 708-6690
Technical Support
Contact Us

Beijer Electronics AB
http://www.beijerelectronics.us

Locked