FlexPaper二次開發問題及搜索高亮顯示


最近有個需求,做一個IT知識庫,類似於文庫,說到文庫肯定會用到在線瀏覽文檔了,所有在網上翻閱了一下類似豆丁的在線瀏覽器插件的資料,將其進行了二次開發,在這跟需要用到的朋友分享一下,下面部分內容用到有些前輩的博客內容,首次寫博,寫的不好之處請見諒。。。高手勿噴,O(∩_∩)O謝謝

1.前期准備工作

1.首先二次開發,當然前提是需要一份FlexPaper的源碼。源碼下載地址:

http://files.cnblogs.com/yimiao/FlexPaper.rar

2.由於開發需要Adobe Flash Builder,我用的版本是4.5的

在這里貼一篇關於Adobe Flash Builder4.5的下載及安裝方面的博客供大伙參閱一下。博客:

http://blog.csdn.net/buptdavid/article/details/6880497

提供個key:1499-4181-9296-6452-2998-3656

准備工作做完之后,接着往下看:

2.源碼修改

首先在flash builder中新建一個flex項目,第一步填寫項目名稱FlexPaperViewer,第二步直接默認,最后一步也無需更改。

1.1然后把你1步下載下來的源碼解壓。

1.2將這個文件直接拷貝到FlexPaperView項目中,如下圖顯示:

2. 1將項目下FlexPaperViewer/src/默認包/FlexPaperViewer.mxml文件內容換成:

  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             //初始化參數  
 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                 //注冊事件監聽  
 64                 this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);  
 65                 this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);  
 66                 
 67                 //開放給外部(javascript)調用  
 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類型參數 
 99              * 如果沒有,則返回默認值 
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替換內容之后,運行程序,會出現如下一個錯誤:

點擊這個錯誤,跳到錯誤語句那里,然后將其刪除,不會影響程序

2.3

再運行程序,瀏覽器就能顯示出來了

3.樣式修改

3.1:去除右上角Logo,以及右下角logo

--1.去右上角logo,首先打開FlexPaperViewer.mxml文件,搜索bttnInfo,一共就三句,全部注釋掉。然后再運行,就會發現右上角的logo就沒了

--2.右下角Logo

打開Viewer.as文件,找到createDisplayContainer這個函數。在addChild(_skinImgDo);后面加入_skinImgDo.visible = false;(雖然不懂,但是這些看看也都能知道個大概),再運行的時候發現右下角的Logo也不見了

--3:去打印按鈕

去右上角logo,首先打開FlexPaperViewer.mxml文件,搜索print,將這行注釋或者刪除,打印按鈕也消失了

3.2:修改樣式或者刪除工具欄里面的按鈕都可以在FlexPaperViewer.mxml文件里進行相應的操作

感覺工具欄里面的圖標不好看的話,可以在網上down一些小圖標然后拷貝到assets這個文件夾里面,然后將原來的圖標的名字換到你的圖標里面就行了

這是我換過圖標的樣子,大家也都可以更換一下,根據自己的喜好換換。原先的感覺太死板不怎么好看

3.3:當鼠標移到工具欄上的圖標時,上面顯示英文提示:如果想換成中文的話,找到文件夾路徑locale/en_Us/FlexPaper.properties的這個文件,修改對應的提示如下所示:

 1 # locale/en_US/FlexPaper.properties
 2 Print=打印
 3 FitWidth=自適應寬度 
 4 FitPage=自適應高度
 5 Scale=縮放 
 6 ThumbView=多頁顯示 
 7 CurrentPage=當前頁 
 8 Search=搜索 
 9 NextPage=下一頁
10 PreviousPage=上一頁
11 Fullscreen=全屏顯示
12 About=About 
13 Finishedsearching=文檔搜索完成,沒有找到更多的匹配項!
14 Searchfinished=搜索完成
15 Selectprintrange=Select print range 
16 All=All
17 CurrentPage=當前頁 
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.高亮顯示問題:

修改之后的瀏覽器搜索內容時,不會出現高亮顯示,這是為什么呢,有的朋友可能發現,自帶的文件Paper.swf就可以,為什么自己生成的swf文件不可以呢?

這個原因是因為你使用SWFTools里面這個轉換工具pdf2swf.exe時,參數沒給,  string argsStr = PDFFilePath + " -o " + targetPath + " -T 9 -f";,加上-f就可以查找時高亮顯示了

 

另附上pdf2swf.exe詳細參數:

其中把pdf轉成swf的工具就是pdf2swf了。在命令行中運行pdf2swf src.pdf des.swf一般能滿足需求。而命令行參數可以通過pdf2swf -f得到:

-h , –help                      Print short help message and exit              打印幫助信息
-V , –version                Print version info and exit                        打印版本號
-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

指定轉換的頁面范圍,使用的頁碼描述方法與打印機打印文件時候的選頁一樣

-P , –password password       Use password for deciphering the pdf.指定打開pdf的密碼
-v , –verbose                 Be verbose. Use more than one -v for greater effect.轉換時輸出詳細的內容
-z , –zlib                    Use Flash 6 (MX) zlib compression.使用Flash 6的zlib壓縮機制
-i , –ignore                  Allows pdf2swf to change the draw order of the pdf. This may make the generated允許程序修改pdf的繪制順序,可能會導致結果與原來有差異
-j , –jpegquality quality     Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)設置轉換其中的jpeg圖片的質量,從0到100,默認值是85。
-s , –set param=value         Set a SWF encoder specific parameter.  See pdf2swf -s help for more information.  設置SWF轉碼時候的參數,具體參數可以用pdf2swf -s help獲取
-w , –samewindow              When converting pdf hyperlinks, don’t make the links open a new window.        設置轉換后的swf打開原pdf中的連接時使用相同的窗口
-t , –stop                    Insert a stop() command in each page.            在每頁結尾添加一個stop()命令
-T , –flashversion num        Set Flash Version in the SWF header to num.         設置SWF所使用的flash版本號
-F , –fontdir directory       Add directory to the font search path.                    指定字體文件所在路徑
-b , –defaultviewer           Link a standard viewer to the swf file.             指定默認的swf導航文件,用來翻頁、放大縮小等等
-l , –defaultloader           Link a standard preloader to the swf file which will be displayed while the main swf is loading.     指定默認的swf加載文件,用來顯示加載進程效果
-B , –viewer filename         Link viewer filename to the swf file.   指定swf導航文件,作用同-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. 不使用字體,所有都轉為形狀。
-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. 不做實際轉換,僅顯示PDF的信息。
-Q , –maxtime n               Abort conversion after n seconds. Only available on Unix. 如果運行時間超時則退出。

 

基本上這個小插件的的二次開發就到這里了,寫了這么多,感覺有點啰嗦。不過能幫助到大家還是很好的 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM