2009-07-08 103 views
0

我是一只新的flex软件。 我想要做的是生成并保存在服务器上的PDF格式的布局设计,只有画布。目前,我可以在浏览器中显示PDF(请参阅下面的功能:),但无法将文件保存在服务器上。在服务器上保存PDF时的Flex问题

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

其中layout_cnv是一个画布。我也使用AlivePDF.swc lbrary。 在服务器PHP文件是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.'; 

      ?> 

有人可以帮我请。

+0

有人请帮助。 – 2009-07-08 14:21:21

+0

我很困惑。客户端是flex,服务器端是php。谁需要保存PDF,客户端或服务器? – 2009-07-08 15:58:06

回答

0

终于在几天后我发现了解决上述问题的方法。 这里在服务器本地保存的文件,我只是需要做一些变化,下面的功能:

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

凡create.php在服务器脚本定义如下:

 <?php 

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

    cheers :-) !!!