Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Printing arbitrary text via a script
PostPosted: Fri Mar 15, 2013 8:00 am 

Joined: Tue Mar 13, 2012 9:53 am
Posts: 824

Offline
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!");
         }
      }
    }
}

_________________
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron