开发者

unable to take screen shot and save as pdf in flex 4.1

I am using Flex 4.1 and AlivePdf for generating pdf. My requirement is like as follows:

I have an array of xml data. I need to iterate that array, develop a chart, take a screen shot of that chart (using ImageSnapshot.captureImage) and save it as pdf in desktop folder. Here, I am using the following code snippet,

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:Im开发者_Go百科ageSnapshot = 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. if there are 50 xml then 50 pdf need to be stored in that particular location. The problem is that it is taking too long time. Is it possible to minimize to pdf creation time?


To make ImageSnapshot faster you may try:

  • reducing the DPI (instead of 300, maybe 150 is sufficient ?)
  • using the PNG encoder, which - in my experience - is faster than the JPEG encoder
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜