
如果想要在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格式
<?xml version="1.0" encoding="utf-8" ?>
<data>
<pdf name="aaa" url="http://locahost/FlexPaper/index.html?fileSrc=aaa.pdf"></pdf>
<pdf name="bbb" url="http://locahost/FlexPaper/index.html?fileSrc=bbb.pdf"></pdf>
</data>
组件:
<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:esri="http://www.esri.com/2008/ags"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:viewer="com.esri.viewer.*"
xmlns:components="com.esri.viewer.components.*"
x="600" y="300"
xmlns:code="http://code.google.com/p/flex-iframe/"
widgetConfigLoaded="basewidget_widgetConfigLoaded()"> <fx:Script>
<![CDATA[
import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
import com.esri.viewer.managers.EventBus;
import com.szpl.extension.base.impl.AccessPoint;
import com.szpl.extension.tools.config.ILayerConfig;
import com.szpl.extension.tools.layer.ILayer;
import com.szpl.extension.tools.layer.LayerVisibleChangeEvent;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.UIDUtil;
import spark.events.IndexChangeEvent; var arr:ArrayCollection = new ArrayCollection();
protected function basewidget_widgetConfigLoaded():void
{
if (configXML)
{ var pdfxmls:XMLList = configXML.pdf;
for each(var pdfxml:XML in pdfxmls)
{
var obj:Object = new Object();
obj.name = String(pdfxml.@name);
obj.url = String(pdfxml.@url);
arr.addItem(obj);
}
list.dataProvider = arr;
}
if (arr.length > 0)
{
list.selectedIndex = 0;
OfficeProject.source = (list.selectedItem as Object).url;
}
} private function listChangeHandle(event:IndexChangeEvent):void
{
OfficeProject.source = (list.selectedItem as Object).url;
} ]]>
</fx:Script> <viewer:WidgetTemplate id="LocateWT" width="980" height="100%"
enableMinimizeButton="false" > <s:HGroup height="100%" width = "100%">
<s:List id="list" height="100%" width="150" change="listChangeHandle(event)" labelField="name"> </s:List> <code:IFrame id="OfficeProject" width="790" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off"/> </s:HGroup>
</viewer:WidgetTemplate> </viewer:BaseWidget>