flex打印pdf(调用本地打印机)

原文:http://flexpearls.blogspot.com/2007/05/flex-components-to-pdf.html

Printing Flex components or converting them to PDF is very easy. Here is a sample code which shows how to print a column chart. If you want to generate a PDF you need to have ADOBE PDF printer(安装adobe pdf printer) driver installed on the machine. In the print dialog instead choosing a printer you can choose ADOBE PDF printer listed and you get a PDF as output. Sunil has more info about printing charts with data tips here. More about Flex Printing can be found here too.


chartToPrint.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3. <mx:Script>
  4.     <![CDATA[
  5.     import mx.printing.FlexPrintJobScaleType;
  6.     import mx.printing.FlexPrintJob;
  7.     private function printChart():void
  8.     {
  9.         var fpj:FlexPrintJob = new FlexPrintJob();
  10.         if (fpj.start())
  11.         {
  12.              fpj.addObject(ChartContainer,FlexPrintJobScaleType.MATCH_WIDTH);
  13.                 fpj.send();
  14.         }
  15.     }
  16.     
  17.     private var chartData:Array = [ 
  18.     
  19.     { bugCount:20, date:"05/20/07" },
  20.     { bugCount:14, date:"05/21/07" },
  21.     { bugCount:17, date:"05/22/07" },
  22.     { bugCount:10, date:"05/23/07" },
  23.     { bugCount:2, date:"05/24/07" }
  24.     ];
  25.     ]]>
  26.     
  27. </mx:Script>
  28. <mx:Canvas id="ChartContainer" backgroundColor="white" width="433" height="431">
  29. <mx:ColumnChart id="myChart" x="31" y="10" width="353" height="357" dataProvider="{chartData}">
  30.  
  31.  <mx:series>
  32.    <mx:ColumnSeries yField="bugCount" />
  33.  </mx:series>
  34.  
  35.  <mx:horizontalAxis>
  36.   <mx:CategoryAxis categoryField="date" />
  37.  </mx:horizontalAxis>
  38. </mx:ColumnChart>
  39.     
  40. </mx:Canvas>
  41. <mx:Button label="Print" click="printChart()" x="174" y="399"/>
  42.     
  43. </mx:Application>

关于只能打印出一部分图片,有人说:
The reason why it was just printing a part of the graph is because, it seems the resizing used to take some time. Hence, the chart wasn't resized when it went to the printer. Even though the size of the chart was changed before fpj.addObject(), as in your example. May be because the canvas is the container which is being resized and it has two charts and couple of text boxes. I got around the problem by adding an event hadler for resize on canvas. When this occurs I do a addObject and send. So, printing works fine now.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值