天天看点

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,如需转载请自行联系原作者

继续阅读