您的位置:首页 > 其它

FlexPaper+SWFTools 实现仿百度文库,在线查看PDF文档

2012-10-18 16:01 696 查看
转载自:http://www.cnblogs.com/qinpeifeng107/archive/2011/08/29/2158879.html

思路:通过pdf2swf.exe将pdf文档转换为swf文件,用FlexPaper播放swf

将Word 转换为Pdf插件下载地址:http://download.csdn.net/detail/tiz198183/4660169

 

通过cmd命令运行pdf2swf.exe将pdf文档转换为swf文件



 

.net 代码

1、.net 中运行cmd命令将pdf,转换为swf

protected void Button1_Click(object sender, EventArgs e)
{
//Asp.net 调用pdf2swf.exe把PDF转换为SWF的用法
if (FileUpload1.HasFile)
{
try{
string fileName = FileUpload1.FileName;
string fileExtention = FileUpload1.FileName.Substring(fileName.LastIndexOf(".") + 1);
string filePath = HttpContext.Current.Server.MapPath("~/TestSWF\\") + fileName;

FileUpload1.SaveAs(filePath);
Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('上传成功')</script>");
//切记,使用pdf2swf.exe 打开的文件名之间不能有空格,否则会失败
string cmdStr = HttpContext.Current.Server.MapPath("~/SWFTools/pdf2swf.exe");
string savePath = HttpContext.Current.Server.MapPath("~/TestSWF/");
string sourcePath=@""""+ savePath + fileName+@"""" ;
string targetPath=@""""+ savePath + fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf"+@"""";
//@"""" 四个双引号得到一个双引号,如果你所存放的文件所在文件夹名有空格的话,要在文件名的路径前后加上双引号,才能够成功
// -t 源文件的路径
// -s 参数化(也就是为pdf2swf.exe 执行添加一些窗外的参数(可省略))
string argsStr = " -t " +sourcePath+ " -s flashversion=9 -o " +targetPath;

ExcutedCmd(cmdStr,argsStr);

ListBox1.Items.Add(new ListItem(fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf", fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf"));
}
catch
{

}
}
}

//调用新进程 进行转换
private static void ExcutedCmd(string cmd, string args)
{
using (Process p = new Process())
{
//cmd是c:\PDFViewer\SWFTools\pdf2swf.exe
//args是 -t "C:\PDFViewer\TestSWF\ce2.pdf" -s flashversion=9 -o "C:\PDFViewer\TestSWF\ce2.swf"
ProcessStartInfo psi = new ProcessStartInfo(cmd,args);
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
}

2、用FlexPaper播放swf

 

代码如下:

http://download.csdn.net/detail/tiz198183/4660428

 

效果:



 

 FlexPaper 参数设置

SwfFile: escape('TestSWF/' + fileURL), //加载的SWF文件
Scale: 0.6, //初始化缩放比例为0.6,即60%
ZoomTransition: 'easeOut', //Flexpaper中缩放样式,它使用和Tweener一样的样式,默认参数值为easeOut.其他可选值包括: easenone, easeout, linear, easeoutquad
ZoomTime: 0.5,//从一个缩放比例变为另外一个缩放比例需要花费的时间,该参数值应该为0或更大。
ZoomInterval: 0.2, //缩放比例之间间隔,默认值为0.1,该值为正数
FitPageOnLoad: false, //加载时自动适应页面
FitWidthOnLoad: false, //加载时自动适应页面宽度
PrintEnabled: true,
FullScreenAsMaxWindow: false,
ProgressiveLoading: false, //当设置为true的时候,展示文档时不会加载完整个文档,而是逐步加载,但是需要将文档转化为9以上的flash版本(使用pdf2swf的时候使用-T 9 标签)。
MinZoomSize: 0.2, //最小的缩放比例
MaxZoomSize: 5, //设置最大的缩放比例
SearchMatchAll: false, //设置为true的时候,单击搜索所有符合条件的地方高亮显示
InitViewMode: 'Portrait', //设置启动模式如"Portrait" or "TwoPage".
ViewModeToolsVisible: true, //工具栏上是否显示样式选择框
ZoomToolsVisible: true, //工具栏上是否显示缩放工具
NavToolsVisible: true, //工具栏上是否显示导航工具
CursorToolsVisible: true, //工具栏上是否显示光标工具
SearchToolsVisible: true, //工具栏上是否显示搜索
localeChain: 'en_US'//设置地区(语言)为en_US


localeChain (String)设置地区(语言),目前支持以下语言。
   en_US (English)

   fr_FR (French)

   zh_CN (Chinese, Simple)

   es_ES (Spanish)

   pt_BR (Brazilian Portugese)

   ru_RU (Russian)

   fi_FN (Finnish)

   de_DE (German)

   nl_NL (Netherlands)

   tr_TR (Turkish)

   se_SE (Swedish)

   pt_PT (Portugese)

   el_EL (Greek)

   da_DN (Danish)

   cz_CS (Czech)

   it_IT (Italian)

   pl_PL (Polish)

   pv_FN (Finnish)

   hu_HU (Hungarian)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐