views:

629

answers:

2

Hi All. I am a new bee to flex. What i am trying to do is to generate and save the layout design which nothing but canvas to a pdf format at the server. Currently i am able to display the pdf in browser (see the function below:) but cannot save the file at the server.

  private function continueToPdf():void{
   myPDF = new PDF(  Orientation.LANDSCAPE, Unit.MM, Size.A4 );
   myPDF.setDisplayMode ( Display.FULL_WIDTH ); 
   myPDF.addPage();
   myPDF.addImage(layout_cnv);
   myPDF.save( Method.REMOTE, "http://flexindia.org/designtool/upload/create.php",Download.INLINE ,"drawing.pdf" );
     }

where layout_cnv is a canvas.Also i am using AlivePDF.swc lbrary for this. The php file at server is create.php

                   <?php
                 $method = $_GET['method'];
                 $name = $_GET['name'];

                 if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {

// get bytearray
$pdf = $GLOBALS["HTTP_RAW_POST_DATA"];

// add headers for download dialog-box
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($pdf));
header('Content-disposition:'.$method.'; filename="'.$name.'"');
echo $pdf;

     }  else echo 'An error occured.';

           ?>

Can someone help me please.

+1  A: 

I'm not familiar with the AlivePDF library, but the WebORB PDF Generator is excellent for this task (I'm not affiliated with The Midnight Coders or WebORB, just making a recommendation.)

http://www.themidnightcoders.com/products/pdf-generator/overview.html

Thanks for the help lukesh.
Piyush Giri
A: 

Finally after few days I've discovered the solution for the aforesaid problem. Here for saving the file locally at server i just need to do some changes in the following function as:

      private function continueToPdf():void{
                    myPDF = new PDF(  Orientation.LANDSCAPE, Unit.MM, Size.A4 );
                    myPDF.setDisplayMode ( Display.FULL_WIDTH ); 
                    myPDF.addPage();
                    myPDF.addImage(layout_cnv);
                    myPDF.save( Method.REMOTE, "create.php",Download.INLINE ,"drawing.pdf" );
                 }

Where create.php is the server script defined as follows:

     <?php

      $fp = fopen( 'upload/drawing.pdf', 'wb' );
       fwrite( $fp, $GLOBALS['HTTP_RAW_POST_DATA' ] );
       fclose( $fp ); 
       ?>

    cheers :-) !!!
Piyush Giri