FlexPaper二次开发问题及搜索高亮显示
最近有個(gè)需求,做一個(gè)IT知識(shí)庫,類似于文庫,說到文庫肯定會(huì)用到在線瀏覽文檔了,所有在網(wǎng)上翻閱了一下類似豆丁的在線瀏覽器插件的資料,將其進(jìn)行了二次開發(fā),在這跟需要用到的朋友分享一下,下面部分內(nèi)容用到有些前輩的博客內(nèi)容,首次寫博,寫的不好之處請(qǐng)見諒。。。高手勿噴,O(∩_∩)O謝謝
1.前期準(zhǔn)備工作
1.首先二次開發(fā),當(dāng)然前提是需要一份FlexPaper的源碼。源碼下載地址:
http://files.cnblogs.com/yimiao/FlexPaper.rar
2.由于開發(fā)需要Adobe Flash Builder,我用的版本是4.5的
在這里貼一篇關(guān)于Adobe Flash Builder4.5的下載及安裝方面的博客供大伙參閱一下。博客:
http://blog.csdn.net/buptdavid/article/details/6880497
提供個(gè)key:1499-4181-9296-6452-2998-3656
準(zhǔn)備工作做完之后,接著往下看:
2.源碼修改
首先在flash builder中新建一個(gè)flex項(xiàng)目,第一步填寫項(xiàng)目名稱FlexPaperViewer,第二步直接默認(rèn),最后一步也無需更改。
1.1然后把你1步下載下來的源碼解壓。
1.2將這個(gè)文件直接拷貝到FlexPaperView項(xiàng)目中,如下圖顯示:
2. 1將項(xiàng)目下FlexPaperViewer/src/默認(rèn)包/FlexPaperViewer.mxml文件內(nèi)容換成:
1 <?xml version="1.0" encoding="utf-8"?> 2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 3 xmlns:fp="com.devaldi.controls.flexpaper.*" 4 layout="absolute" width="100%" height="100%" 5 applicationComplete="initApp();"> 6 7 <mx:Script> 8 <![CDATA[ 9 import mx.controls.Alert; 10 11 public var _aid = 0;//文檔ID 12 13 [Bindable] 14 public var _Scale:Number = 1;//縮放比例 15 16 [Bindable] 17 public var _SwfFile:String = "";//SWF文件路徑 18 19 [Bindable] 20 public var _ZoomTransition:String = "easeOut"; 21 22 [Bindable] 23 public var _ZoomTime:Number = 0.6; 24 25 [Bindable] 26 public var _ZoomInterval:Number = 0.1; 27 28 [Bindable] 29 public var _FitPageOnLoad:Boolean = false;//加載后適合高度 30 31 [Bindable] 32 public var _FitWidthOnLoad:Boolean = false;//加載后適合寬度 33 34 [Bindable] 35 public var _PrintEnabled:Boolean = false;//是否支持打印 36 37 [Bindable] 38 public var _FullScreenAsMaxWindow:Boolean = true;//是否支付全屏 39 40 [Bindable] 41 public var _ProgressiveLoading:Boolean = true;//是否延遲加載 42 43 [Bindable] 44 public var _localeChain:String = "zh_CN";//語言 45 46 private var isFocus:Boolean = false; 47 48 //初始化參數(shù) 49 private function initApp():void{ 50 var params:Object = Application.application.parameters; 51 _Scale = getNumber(params, "Scale", 1); 52 _SwfFile = getString(params, "SwfFile", "Paper.swf"); 53 _ZoomTransition = getString(params, "ZoomTransition", "easeOut"); 54 _ZoomTime = getNumber(params, "ZoomTime", 0.8); 55 _ZoomInterval = getNumber(params, "ZoomInterval", 0.1); 56 _FitPageOnLoad = getBoolean(params, "FitPageOnLoad", false); 57 _FitWidthOnLoad = getBoolean(params, "FitWidthOnLoad", false); 58 _PrintEnabled = getBoolean(params, "PrintEnabled", true); 59 _FullScreenAsMaxWindow = getBoolean(params, "FullScreenAsMaxWindow", false); 60 _ProgressiveLoading = getBoolean(params, "ProgressiveLoading", true); 61 _localeChain = params["localeChain"]; 62 63 //注冊(cè)事件監(jiān)聽 64 this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); 65 this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); 66 67 //開放給外部(javascript)調(diào)用 68 ExternalInterface.addCallback("hasFocus", hasFocus); 69 //ExternalInterface.addCallback("focus", focus); 70 ExternalInterface.addCallback("setViewerFocus", setViewerFocus); 71 ExternalInterface.addCallback("gotoPage", gotoPage); 72 } 73 74 75 76 private function onMouseOver(event:MouseEvent):void{ 77 this.isFocus = true; 78 } 79 80 private function onMouseOut(event:MouseEvent):void{ 81 this.isFocus = false; 82 } 83 84 public function hasFocus():Boolean{ 85 //Alert.show("hasFocus"); 86 return isFocus; 87 } 88 89 public function setViewerFocus(isFocus:Boolean):void{ 90 //Alert.show("setViewerFocus"); 91 this.paperViewer.setViewerFocus(); 92 } 93 public function gotoPage(p:Number):void{ 94 this.paperViewer.gotoPage(p); 95 } 96 /** 97 * 98 * 獲取String類型參數(shù) 99 * 如果沒有,則返回默認(rèn)值 100 **/ 101 private function getString(params:Object, name:String, def:String):String{ 102 if(params[name] != null){ 103 return params[name]; 104 } 105 return def; 106 } 107 108 private function getNumber(params:Object, name:String, def:Number):Number{ 109 if(params[name] != null){ 110 return params[name]; 111 } 112 return def; 113 } 114 115 private function getBoolean(params:Object, name:String, def:Boolean):Boolean{ 116 //Alert.show("比較:"+name); 117 if(params[name] != null){ 118 return params[name] == "true"; 119 } 120 return def; 121 } 122 ]]> 123 </mx:Script> 124 125 <fp:FlexPaperViewer id="paperViewer" 126 width="100%" 127 height="100%" 128 Scale="{_Scale}" 129 SwfFile="{_SwfFile}" 130 ZoomTransition="{_ZoomTransition}" 131 ZoomTime="{_ZoomTime}" 132 ZoomInterval="{_ZoomInterval}" 133 FitPageOnLoad="{_FitPageOnLoad}" 134 FitWidthOnLoad="{_FitWidthOnLoad}" 135 PrintEnabled="{_PrintEnabled}" 136 FullScreenAsMaxWindow="{_FullScreenAsMaxWindow}" 137 ProgressiveLoading="{_ProgressiveLoading}" /> 138 </mx:Application>2.2替換內(nèi)容之后,運(yùn)行程序,會(huì)出現(xiàn)如下一個(gè)錯(cuò)誤:
點(diǎn)擊這個(gè)錯(cuò)誤,跳到錯(cuò)誤語句那里,然后將其刪除,不會(huì)影響程序
2.3
再運(yùn)行程序,瀏覽器就能顯示出來了
3.樣式修改
3.1:去除右上角Logo,以及右下角logo
--1.去右上角logo,首先打開FlexPaperViewer.mxml文件,搜索bttnInfo,一共就三句,全部注釋掉。然后再運(yùn)行,就會(huì)發(fā)現(xiàn)右上角的logo就沒了
--2.右下角Logo
打開Viewer.as文件,找到createDisplayContainer這個(gè)函數(shù)。在addChild(_skinImgDo);后面加入_skinImgDo.visible = false;(雖然不懂,但是這些看看也都能知道個(gè)大概),再運(yùn)行的時(shí)候發(fā)現(xiàn)右下角的Logo也不見了
--3:去打印按鈕
去右上角logo,首先打開FlexPaperViewer.mxml文件,搜索print,將這行注釋或者刪除,打印按鈕也消失了
3.2:修改樣式或者刪除工具欄里面的按鈕都可以在FlexPaperViewer.mxml文件里進(jìn)行相應(yīng)的操作
感覺工具欄里面的圖標(biāo)不好看的話,可以在網(wǎng)上down一些小圖標(biāo)然后拷貝到assets這個(gè)文件夾里面,然后將原來的圖標(biāo)的名字換到你的圖標(biāo)里面就行了
這是我換過圖標(biāo)的樣子,大家也都可以更換一下,根據(jù)自己的喜好換換。原先的感覺太死板不怎么好看
3.3:當(dāng)鼠標(biāo)移到工具欄上的圖標(biāo)時(shí),上面顯示英文提示:如果想換成中文的話,找到文件夾路徑locale/en_Us/FlexPaper.properties的這個(gè)文件,修改對(duì)應(yīng)的提示如下所示:
1 # locale/en_US/FlexPaper.properties 2 Print=打印 3 FitWidth=自適應(yīng)寬度 4 FitPage=自適應(yīng)高度 5 Scale=縮放 6 ThumbView=多頁顯示 7 CurrentPage=當(dāng)前頁 8 Search=搜索 9 NextPage=下一頁 10 PreviousPage=上一頁 11 Fullscreen=全屏顯示 12 About=About 13 Finishedsearching=文檔搜索完成,沒有找到更多的匹配項(xiàng)! 14 Searchfinished=搜索完成 15 Selectprintrange=Select print range 16 All=All 17 CurrentPage=當(dāng)前頁 18 Pages=Pages: 19 Enterpagenumbers=Enter page numbers and/or page ranges separated by commas. For example 1,3,5-12 20 Cancel=Cancel 21 IncorrectRange=Incorrect Range 22 Incorrectrangespecified=Incorrect range specified 23 About=About 24 Developedby=Developed by Devaldi. 25 Formoreinformation=For more information, see 26 CopyText=Copy Text 27 TwoPage=兩頁顯示 28 SinglePage=單頁顯示 29 FirstPage=首頁 30 LastPage=尾頁4.高亮顯示問題:
修改之后的瀏覽器搜索內(nèi)容時(shí),不會(huì)出現(xiàn)高亮顯示,這是為什么呢,有的朋友可能發(fā)現(xiàn),自帶的文件Paper.swf就可以,為什么自己生成的swf文件不可以呢?
這個(gè)原因是因?yàn)槟闶褂肧WFTools里面這個(gè)轉(zhuǎn)換工具pdf2swf.exe時(shí),參數(shù)沒給,? string argsStr = PDFFilePath + " -o " + targetPath + " -T 9 -f";,加上-f就可以查找時(shí)高亮顯示了
?
另附上pdf2swf.exe詳細(xì)參數(shù):
其中把pdf轉(zhuǎn)成swf的工具就是pdf2swf了。在命令行中運(yùn)行pdf2swf src.pdf des.swf一般能滿足需求。而命令行參數(shù)可以通過pdf2swf -f得到:
-h , –help????????????????????? Print short help message and exit????????????? 打印幫助信息
-V , –version??????????????? Print version info and exit??????????????????????? 打印版本號(hào)
-o , –output file.swf???????? Direct output to file.swf. If file.swf contains ‘13568621′ (file13568630.swf), then each page指定輸出的swf文件名
-p , –pages range???????????? Convert only pages in range with range e.g. 1-20
or 1,4,6,9-11 or
指定轉(zhuǎn)換的頁面范圍,使用的頁碼描述方法與打印機(jī)打印文件時(shí)候的選頁一樣
-P , –password password?????? Use password for deciphering the pdf.指定打開pdf的密碼
-v , –verbose???????????????? Be verbose. Use more than one -v for greater effect.轉(zhuǎn)換時(shí)輸出詳細(xì)的內(nèi)容
-z , –zlib??????????????????? Use Flash 6 (MX) zlib compression.使用Flash 6的zlib壓縮機(jī)制
-i , –ignore????????????????? Allows pdf2swf to change the draw order of the pdf. This may make the generated允許程序修改pdf的繪制順序,可能會(huì)導(dǎo)致結(jié)果與原來有差異
-j , –jpegquality quality???? Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)設(shè)置轉(zhuǎn)換其中的jpeg圖片的質(zhì)量,從0到100,默認(rèn)值是85。
-s , –set param=value???????? Set a SWF encoder specific parameter.? See pdf2swf -s help for more information.? 設(shè)置SWF轉(zhuǎn)碼時(shí)候的參數(shù),具體參數(shù)可以用pdf2swf -s help獲取
-w , –samewindow????????????? When converting pdf hyperlinks, don’t make the links open a new window.??????? 設(shè)置轉(zhuǎn)換后的swf打開原pdf中的連接時(shí)使用相同的窗口
-t , –stop??????????????????? Insert a stop() command in each page.??????????? 在每頁結(jié)尾添加一個(gè)stop()命令
-T , –flashversion num??????? Set Flash Version in the SWF header to num.???????? 設(shè)置SWF所使用的flash版本號(hào)
-F , –fontdir directory?????? Add directory to the font search path.??????????????????? 指定字體文件所在路徑
-b , –defaultviewer?????????? Link a standard viewer to the swf file.???????????? 指定默認(rèn)的swf導(dǎo)航文件,用來翻頁、放大縮小等等
-l , –defaultloader?????????? Link a standard preloader to the swf file which will be displayed while the main swf is loading.???? 指定默認(rèn)的swf加載文件,用來顯示加載進(jìn)程效果
-B , –viewer filename???????? Link viewer filename to the swf file.?? 指定swf導(dǎo)航文件,作用同-b
-L , –preloader filename????? Link preloader filename to the swf file.????? 指定swf加載文件,作用同-l
-q , –quiet?????????????????? Suppress normal messages.? Use -qq to suppress warnings, also.? 不打印普通信息,用-qq就不打印警告信息。
-S , –shapes????????????????? Don’t use SWF Fonts, but store everything as shape. 不使用字體,所有都轉(zhuǎn)為形狀。
-f , –fonts?????????????????? Store full fonts in SWF. (Don’t reduce to used characters). 在swf中保存全部字體。
-G , –flatten???????????????? Remove as many clip layers from file as possible. 在文件中盡量去除影片層,合并它們
-I , –info??????????????????? Don’t do actual conversion, just display a list of all pages in the PDF. 不做實(shí)際轉(zhuǎn)換,僅顯示PDF的信息。
-Q , –maxtime n?????????????? Abort conversion after n seconds. Only available on Unix. 如果運(yùn)行時(shí)間超時(shí)則退出。
?
基本上這個(gè)小插件的的二次開發(fā)就到這里了,寫了這么多,感覺有點(diǎn)啰嗦。不過能幫助到大家還是很好的?
總結(jié)
以上是生活随笔為你收集整理的FlexPaper二次开发问题及搜索高亮显示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 传真故障排除示例--编码不一致导致传真失
- 下一篇: 学习:erlang开源项目。