1 Reply Latest reply: Dec 8, 2009 9:09 AM by flex2008 RSS

    AlivePDF:Exporting text in a textinput to pdf.

    flex2008 Community Member

      Hi all,

       

      I am trying to export the text in a textinput to PDF using AlivePDF.This is the code snippet:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
          creationComplete="init()">
      <mx:Script>
          <![CDATA[
              import org.alivepdf.layout.Unit;
              import org.alivepdf.fonts.Style;
              import org.alivepdf.layout.Size;
              import org.alivepdf.layout.Orientation;
              import org.alivepdf.fonts.FontFamily;
              import org.alivepdf.events.ProcessingEvent;
              import org.alivepdf.images.ImageFormat;
              import mx.controls.Alert;
              import org.alivepdf.saving.Method;
              import org.alivepdf.pdf.PDF;
             
              private var pdf:PDF;
              private function init():void
              {
                  pdf = new PDF( Orientation.PORTRAIT, Unit.MM, Size.A4 );
              }   
             
              private function savePDF():void
              {
                  //generate();
                  try
                    {
                      var f:FileStream = new FileStream();
                        var file:File = File.desktopDirectory.resolvePath("pdf/test.pdf");
                        f.open( file, FileMode.WRITE);
                        var bytes:ByteArray = pdf.save(Method.LOCAL);
                        f.writeBytes(bytes);
                        f.close();
                    }
                    catch(error:Error)
                    {
                        Alert.show('Pdf already open');
                    }
              }
              private function generate():void
              {
                  if(pdf.totalPages)
                  {
                      pdf.removeAllPages();
                  }
                  pdf.addPage();
                  pdf.setFont(FontFamily.ARIAL , Style.NORMAL, 12);
                  pdf.addText(txt.text,10,10);
                  savePDF();
                   
              }   
          ]]>
      </mx:Script>
      <mx:VBox>
          <mx:Button id='btn' label="Generate" click="generate()"/>
          <mx:TextInput id='txt'/>   
      </mx:VBox>
      </mx:WindowedApplication>

       

      When i run the application for the first time,i am getting it correctly.But if I run it again,i am getting a blank pdf.Also the pdf content is very small.
      Can someone help me in finding out what is wrong?.