iX Talk
http://beijerinc.com/support/ix/forum/

Printing arbitrary text via a script
http://beijerinc.com/support/ix/forum/viewtopic.php?f=9&t=1307
Page 1 of 1

Author:  mark.monroe [ Fri Mar 15, 2013 8:00 am ]
Post subject:  Printing arbitrary text via a script

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

Code:
//--------------------------------------------------------------
// 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!");
         }
      }
    }
}

Page 1 of 1 All times are UTC - 7 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/