FlexPaper+SwfTools实现的在线文档功能
最近一个项目需要实现一个在线浏览文档的功能。准备使用FlexPaper配合Pdf2Swf实现。
主要需求在于: ??? ? 文档页数很多,少则几百页,多则上千页。 根据需求,将该功能拆分成了三部分: ??? ? 上传:支持大文件,断点续传。 其中文件上传部分是我同事实现的,这里主要讲下后台服务和在线浏览部分。 文件转换服务 大体思路是: ??? 这里使用了SwfTools套件中的Pdf2Swf工具:下载 主要代码: //PDF转换成SWF
private void ConvertPDFtoSWF(string pdfFile)
{
using (Process p = new Process())
{
SystemLog.CurrentLogger.Debug(string.Format("正在处理 {0} ...",pdfFile));
string pdf2swfExe = "pdf2swf.exe";
string savePath = GetSavePathFromName(pdfFile);
string cmd = pdf2swfExe;
string args = " -t "" + pdfFile + "" -o "" + savePath + pdfFile.Split('').Last().Replace(".pdf","")
+ "%.swf" -s drawonlyshapes -s flashversion=9";
p.StartInfo.FileName = cmd;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
//此类提供的标准output流只有2k,不要重定向
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.PriorityClass = ProcessPriorityClass.High;
p.WaitForExit();
SystemLog.CurrentLogger.Debug(string.Format("{0} 处理完成。",pdfFile));
if (AppConfiguration.DeleteConvertedPdf)
{
//转换完成后删除Pdf
File.Delete(pdfFile);
SystemLog.CurrentLogger.Debug(string.Format("{0} 已删除。",pdfFile));
}
else
{
//重命名Pdf
File.Move(pdfFile,pdfFile + ".bak");
SystemLog.CurrentLogger.Debug(string.Format("{0} 已重命名。",pdfFile));
}
}
}
??? 之前在测试的时候,发现转换过程中会出现文字丢失的现象。这里使用了-s drawonlyshapes 这个参数,将Pdf全部作为图片转换的。这样虽然保证了兼容性,但是牺牲了空间。作为图片生成的Swf比文本格式的Swf要大不少,不知道大家有没有什么好的解决方法。 在线浏览 ??? FlexPaper支持分页加载,采用{filename[*,padding],total pages}这种语法即可。 主要代码: <a id="viewerPlaceHolder" style="width: 800px; height: 600px; display: block"></a>
<script type="text/javascript">
var fp = new FlexPaperViewer(
'FlexPaperViewer','viewerPlaceHolder',{ config: {
SwfFile: 'SwfFolder/<%=Folder %>/{<%=Folder %>[*,0].swf,<%=PageNum %>}',localeChain: "zh_CN",//中文
Scale: 1,ZoomTransition: 'eaSEOut',ZoomTime: 0.5,ZoomInterval: 0.2,FitPageOnLoad: false,FitWidthOnLoad: false,PrintEnabled: true,FullScreenAsMaxWindow: false,ProgressiveLoading: false,MinZoomSize: 0.2,MaxZoomSize: 5,SearchMatchAll: false,InitViewMode: 'Portrait',ViewModeToolsVisible: true,ZoomToolsVisible: true,NavToolsVisible: true,CursorToolsVisible: true,SearchToolsVisible: true
}
});
</script>
参考文章 c# System.Diagnostics.Process 调用外部程序时WaitForExit锁死问题分析及解决方案 FlexPaper+SWFTools 实现仿百度文库及一些小问题 Pdf2Swf命令行参数 解决FlexPaper分页分段加载问题 源码 分页加载:FlexPaper.zip 文件转换服务:PDFtoSWFService.zip http://www.cnblogs.com/penbox/archive/2011/09/02/2163646.html(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |