2 Replies Latest reply on Oct 9, 2007 11:26 PM by ErnIvan

    print from dinamic TextArea

    ErnIvan Level 1
      Hi

      I'm try to print "all text" from a dinamc textArea with no success:

      this is the code:

      ---------------------------------------
      <?xml version="1.0"?>
      <!-- printing\DGPrint.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[
      import mx.printing.*;


      private function test():void
      {

      var i:int;

      for(i= 0; i< 10; i++){
      myTxt.text += "riga"+i+" \n"
      }
      }
      // Create a PrintJob instance.
      private function doPrint():void {
      // Create an instance of the FlexPrintJob class.
      var printJob:FlexPrintJob = new FlexPrintJob();

      // Start the print job.
      if (printJob.start() != true) return;

      // Add the object to print. Do not scale it.
      printJob.addObject(myTxt, FlexPrintJobScaleType.NONE);

      // Send the job to the printer.
      printJob.send();
      }
      ]]>
      </mx:Script>
      <mx:TextArea width="286" height="62" id="myTxt" wordWrap="true"/>
      <mx:Button label="Button" id="popola" click="test()"/>

      <mx:VBox id="myVBox">
      <mx:Button id="myButton"
      label="Print"
      click="doPrint();"/>
      </mx:VBox>
      </mx:Application>

      -------------------------------------------

      I'm able to print only the visible text.

      I find an example on flex doc for dataGrid but it can't help me

      some idea ????

      thanks
        • 1. Re: print from dinamic TextArea
          AaffordableWeb
          You need to change the width of the text area to be the width of the page you are trying to print to. Here is your <script> section modified to change the width of the text area at the time of printing to the width and height of the page.

          <mx:Script>
          <![CDATA[
          import mx.printing.*;

          // You will need to change the path to match your environment
          import DGPrint;

          private function test():void
          {
          var i:int;

          for(i= 0; i< 10; i++){
          myTxt.text += "riga"+i+" \n"
          }
          }
          // Create a PrintJob instance.
          private function doPrint():void {
          // Create an instance of the FlexPrintJob class.
          var printJob:FlexPrintJob = new FlexPrintJob();

          // Start the print job.
          if (printJob.start() != true) return;

          // Create a copy of the page that can be formatted for printing
          var tmp:DGPrint = new DGPrint();

          // Put the object on the page
          addChild(tmp);

          // Make the tmp object as big as the page to print to
          tmp.myTxt.width = printJob.pageWidth;
          tmp.myTxt.height = printJob.pageHeight;

          // Assign the text to the tmp object
          tmp.myTxt.text = myTxt.text;

          // Add the object to print. Do not scale it.
          printJob.addObject(tmp.myTxt, FlexPrintJobScaleType.NONE);

          // Remove the tmp object
          removeChild(tmp);

          // Send the job to the printer.
          printJob.send();
          }
          ]]>
          </mx:Script>
          • 2. Re: print from dinamic TextArea
            ErnIvan Level 1
            hi

            I have an error 1040 and 1180 on your script at --> "var tmp:DGPrint = new DGPrint();"<--

            what is "import DGPrint " ?

            I need to print textArea content non datagrig :(