Skip navigation
Currently Being Moderated

AlivePDF:Exporting text in a textinput to pdf.

Dec 7, 2009 11:21 PM

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?.

Attachments:
 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points