天天看點

FlexPaper_1.2.1.swc——Flex線上顯示PDF文檔(使用FlexPaper)感悟

      自己的也在逐漸完善和改進中,下面是我項目中的最終版:

  一直希望在項目結束後,分享我的代碼和心得。前天碰巧看到有外國網友,将該功能封裝成SWC,實作技術路線都是相同的,現在大家可以學習一下,很友善地實作自己的PDF線上浏覽功能了。(功能還不錯,但有待提高!如下:)

網站位址:

介紹轉載:

FlexPaper is an open source light weight document viewer component designed to work together with libraries such as PDF2SWF, making it possible to display PDF files in Adobe Flex and other Flash based applications.

To make it possible for your users to view your PDF documents without using Acrobat Reader, documents first needs to be converted to the SWF file format. There is a range of available converters, both commercial and free. The following example uses the open source tool SwfTools and can be automated if needed.

Convert your PDF to SWF. This is preferrably done from the command prompt. Make sure you set your options (Edit->Options) to "No viewer" if you are converting your PDF using the UI from SwfTools before exporting your PDF to SWF. This example converts a PDF file called "Paper3.pdf" to the output file "Paper3.swf":

C:\SWFTools\pdf2swf.exe Paper3.pdf -o Paper3.swf

The pre-compiled version of FlexPaper is most useful if you just want to use FlexPaper on any of your web pages.

Copy the SWF you created with PDF2SWF to the same directory as your extracted files

Using the viewer in Adobe Flex is as easy a using the flash version.

Download the FlexPaper SWC from Google Code and add the FlexPaper library to your Flex project.

Copy the SWF you created with PDF2SWF to your bin-debug directory and add the FlexPaper component to your flex application as in the following example (update the SwfFile property on the component to point to your SWF file):

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" xmlns:fp="com.devaldi.controls.flexpaper.*">      <fp:FlexPaperViewer width="520" height="450" Scale="0.6" SwfFile="Paper3.swf" /> </mx:Application>

國内介紹該控件庫的先驅:

<a href="http://wangcheng.javaeye.com/blog/549074" target="_blank">http://wangcheng.javaeye.com/blog/549074</a>

轉載其部落格内容:

<a href="http://www.cnblogs.com/blog/549074" target="_blank">Flex:使用FlexPaper顯示PDF文檔</a>

FlexPaper是一個開源的輕量級文檔顯示元件,被設計用來與PDF2SWF一起使用,使在Flex中顯示PDF成為可能。它可以被當做Flex的library來使用。

一. 使用PDF2SWF準備好你的文檔

首先要将PDF轉成SWF,這步可以使用開源的SwfTools自動完成

1.下載下傳安裝 SwfTools,目前最新版本是0.9

2. 轉換PDF到SWF,可以通過指令行的方式,例如将Paper3.pdf轉換成Paper3.swf

C:\SWFTools\pdf2swf Paper3.pdf -o Paper3.swf

二. 使用已經編譯好的FlexPaper的flash版本浏覽你的文檔

下載下傳并解壓出已經編譯好的FlexPaper

zip檔案包含一個例子檔案叫做FlexPaperViewer.html,它向你展示了需要傳給FlexPaper的基本參數

var params = {   

SwfFile : "Paper.swf",   

Scale : 0.6   

}   

swfobject.embedSWF("FlexPaperViewer.swf","cb","500","500","9.0.0","js/swfobject/expressInstall.swf", params);   

//SwfFile參數是你想顯示的檔案,Scale是0-1之間的數,表示顯示的放大參數  

複制你建立出來的swf和PDF2SWF到解壓縮出的相同目錄

确定你添加了FlexPaperViewer.swf

三. 在Flex中使用FlexPaper

1. 下載下傳FlexPaper SWC,添加到你的Flex項目libs中

2. 複制你用PDF2SWF建立的SWF到你的bin-debug目錄,如Paper3.swf,添加FlexPaper元件到你的flex代碼中

&lt;?xml version="1.0" encoding="utf-8"?&gt;  

&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"    

    layout="absolute"  

    width="800" height="500"  

    xmlns:flexpaper="com.devaldi.controls.flexpaper.*"&gt;  

    &lt;flexpaper:FlexPaperViewer width="800" height="500"    

        Scale="1" SwfFile="Paper3.swf" /&gt;  

&lt;/mx:Application&gt;  

本文轉自農夫山泉别墅部落格園部落格,原文連結:http://www.cnblogs.com/yaowen/p/4203005.html,如需轉載請自行聯系原作者

繼續閱讀