无法拍摄屏幕截图并在flex 4.1中另存为pdf

时间:2011-09-06 11:48:14

标签: flex actionscript alivepdf

我使用Flex 4.1和AlivePdf生成pdf。我的要求如下:

我有一个xml数据数组。我需要迭代该数组,开发一个图表,拍摄该图表的屏幕截图(使用ImageSnapshot.captureImage)并将其保存为桌面文件夹中的pdf。在这里,我使用以下代码片段,

for(count=0; count<limit; count++) {
   var xml:XML = new XML(xmlDataArr[count]);
   displayChart(xml); // this creates entire chart
   storeReportPDF(count);   
}

private function storeGrowthReportPDF(index:int):void {

   var image:ImageSnapshot = ImageSnapshot.captureImage(growthReportChart, 300, new JPEGEncoder);   

   var fs:FileStream = new FileStream();    
   var file: File = File.documentsDirectory.resolvePath("./GrowthReportBatch/growthReport_"+index+".pdf");  
   fs.open(file, FileMode.WRITE);

   var pdfBytes:ByteArray = createGrowthReportPdf (image.data);                     
    fs.writeBytes(pdfBytes); 
    fs.close();
}

e.g。如果有50 xml则需要将50 pdf存储在该特定位置。问题是它花了太长时间。是否可以最小化到pdf创建时间?

1 个答案:

答案 0 :(得分:0)

为了让ImageSnapshot更快,您可以尝试:

  • 减少DPI(而不是300,可能150就足够了?)
  • 使用PNG编码器,根据我的经验,它比...更快 JPEG编码器