如果想要在flex加载pdf,虽然pdf格式是开源的,但是自己去解析太麻烦了,pdf还要分页之类的,现在网上各种文档上传可以在线看很多都是pdf,当然也有word,excel之类,其实很多都是转了swf,flex加载swf,这次只说加载pdf,首先先下载一个swftools,这个工具有命令行可以转pdf 到dwg 简单命令是 pdf2swf -o 1.swf -s flashversion=9 1.pdf,其中flashversion最好选9以上 ,低版本有时候导出swf flex加载不出来。github上有flexpaper这个组件,flexpaper这个组件就不不细说了,还要结合flex-iframe.swc这个组件来用,flexpapaer和flex-iframe.swc地址http://files.cnblogs.com/files/haibalai/FlexPaper.rar。
这里做成一个组件,熟悉flexview开发的都知道widget模式,这里xml格式
1 <?xml version="1.0" encoding="utf-8" ?> 2 <data> 3 <pdf name="aaa" url="http://locahost/FlexPaper/index.html?fileSrc=aaa.pdf"></pdf> 4 <pdf name="bbb" url="http://locahost/FlexPaper/index.html?fileSrc=bbb.pdf"></pdf> 5 </data>
组件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <viewer:BaseWidget xmlns:esri="http://www.esri.com/2008/ags" 3 xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark" 5 xmlns:mx="library://ns.adobe.com/flex/mx" 6 xmlns:viewer="com.esri.viewer.*" 7 xmlns:components="com.esri.viewer.components.*" 8 x="600" y="300" 9 xmlns:code="http://code.google.com/p/flex-iframe/" 10 widgetConfigLoaded="basewidget_widgetConfigLoaded()"> 11 12 13 <fx:Script> 14 <![CDATA[ 15 import com.esri.ags.layers.ArcGISDynamicMapServiceLayer; 16 import com.esri.viewer.managers.EventBus; 17 import com.szpl.extension.base.impl.AccessPoint; 18 import com.szpl.extension.tools.config.ILayerConfig; 19 import com.szpl.extension.tools.layer.ILayer; 20 import com.szpl.extension.tools.layer.LayerVisibleChangeEvent; 21 import flash.events.MouseEvent; 22 import flash.utils.ByteArray; 23 import mx.collections.ArrayCollection; 24 import mx.core.FlexGlobals; 25 import mx.rpc.events.FaultEvent; 26 import mx.rpc.events.ResultEvent; 27 import mx.utils.UIDUtil; 28 import spark.events.IndexChangeEvent; 29 30 31 32 33 34 35 var arr:ArrayCollection = new ArrayCollection(); 36 protected function basewidget_widgetConfigLoaded():void 37 { 38 if (configXML) 39 { 40 41 var pdfxmls:XMLList = configXML.pdf; 42 for each(var pdfxml:XML in pdfxmls) 43 { 44 var obj:Object = new Object(); 45 obj.name = String(pdfxml.@name); 46 obj.url = String(pdfxml.@url); 47 arr.addItem(obj); 48 } 49 list.dataProvider = arr; 50 } 51 if (arr.length > 0) 52 { 53 list.selectedIndex = 0; 54 OfficeProject.source = (list.selectedItem as Object).url; 55 } 56 } 57 58 59 private function listChangeHandle(event:IndexChangeEvent):void 60 { 61 OfficeProject.source = (list.selectedItem as Object).url; 62 } 63 64 65 66 ]]> 67 </fx:Script> 68 69 <viewer:WidgetTemplate id="LocateWT" width="980" height="100%" 70 enableMinimizeButton="false" > 71 72 <s:HGroup height="100%" width = "100%"> 73 <s:List id="list" height="100%" width="150" change="listChangeHandle(event)" labelField="name"> 74 75 </s:List> 76 77 <code:IFrame id="OfficeProject" width="790" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off"/> 78 79 </s:HGroup> 80 </viewer:WidgetTemplate> 81 82 </viewer:BaseWidget>
所有评论(0)