网页flash文本抓取器( ASP.NET中如何将word文档转换为swf格式的文件显示在网页中)

优采云 发布时间: 2022-01-27 03:08

  网页flash文本抓取器(

ASP.NET中如何将word文档转换为swf格式的文件显示在网页中)

  将word文档转换为swf格式文件并在网页上以flash的形式显示

  在OA系统中,我们经常需要在网页上阅读上传的word文档。一般以html的形式查看上传的文档会造成布局混乱。这次我将介绍如何在ASP.NET中转换上传的word文档。swf 格式的文件显示在网页上。首先介绍一下我的安装和更换过程。我先是在office的com界面用save as直接把word安装改成pdf文件,然后用swftool工具把pdf安装改成swf格式文件,最后在网页中显示使用柔性纸。首先是将代码转换为pdf如下:

  public static bool wordToPdf2(string wordPath,string pdfPath){

bool result = false;

Microsoft.Office.Interop.Word.Applicationapplication=Microsoft.Office.Interop.Word.Application();

Document document = null;

try {

application.Visible = false;

document = application.Documents.Open(wordPath);

document.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);

result = true;

}

catch (Exception e)

{

Log4NetHelp.Error(e);

result = false;

}

finally

{

document.Close();

}

return result;

}

  接下来是将pdf转换为swf格式文件的代码

  public static bool ChangeToSwf(string pdfPath, string swfPath)

{

#region

try

{

bool isStart = false;

string cmd = @"C:\Program Files (x86)\SWFTools\pdf2swf.exe";

ProcessStartInfo startInfo = new ProcessStartInfo(cmd);

startInfo.Arguments = string.Concat(pdfPath, " -o ", swfPath, " -f -T 9 -t -s storeallcharacters");

Process process = new Process();

process.StartInfo = startInfo;

process.StartInfo.WorkingDirectory = pdfPath;

process.StartInfo.CreateNoWindow = true;

process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

isStart = process.Start();

process.WaitForExit();

process.Close();

return isStart;

}

catch (Exception ex)

{

return false;

}

#endregion

}

  最后是显示swf格式文件的代码

  

  

显示swf格式文件  

 

function GetQueryString(name) {

var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");

var r = window.location.search.substr(1).match(reg);

if (r != null) return (r[2]); return null;

}

var fp = $('#documentViewer').FlexPaperViewer(

{

config: {

SwfFile:'/swf/'+GetQueryString('id') + '.swf',

Scale:0.8,

ZoomTransition: 'easeOut',

ZoomTime: 0.5,

ZoomInterval: 0.2,

FitPageOnLoad: true,

FitWidthOnLoad: true,

FullScreenAsMaxWindow: true,

ProgressiveLoading: true,

MinZoomSize: 0.2,

MaxZoomSize: 5,

SearchMatchAll: false,

InitViewMode: 'Portrait',

ViewModeToolsVisible: true,

ZoomToolsVisible: true,

NavToolsVisible: true,

CursorToolsVisible: true,

SearchToolsVisible: true,

localeChain: 'zh_CN',

jsDirectory:'/FlexPaper/js/', /*设置FlexPaper的js文件目录,包含FlexPaperVier.swf文件,否则默认在flex目录下.*/

cssDirectory: '/FlexPaper/css/'

}

}

);

  几个问题

  1. 在使用另存为功能时需要测试的机器上安装Office 2007或更高版本

  2. 我在使用swftool工具的时候直接默认了,程序中也使用了绝对路径。使用这个工具的时候,最好像我的一样填写参数。为了解决转换,弹出黑框,找不到错误。文件路径错误的进程配置信息可以按照我的代码解决。

  3. 使用flexpaper显示时,会出现右上角已经加载,但是我添加的参数在转换的时候没有填写。

  4. 下载的Flexpaper中的FlexPaperVier.swf需要放在js文件目录下。至于配置config的json字符串中各个参数的含义,大家自己去摸索,基本上填这个参数就好了。

  5. 上面的代码在VS自带的应用服务器上测试是没有问题的。部署在IIS上时,会报错。解决方法之一就是把IIS中的应用程序池的标识改成localsystem,权限问题基本解决了,除非你在你的配置文件中加入类似的代码,然后你认为问题解决了,是错误的,或者是报错,这次是说document = application.Documents.Open(wordPath); 这个代码问题 报文档对象为空,导致空引用异常,还是找到了解决办法。至于为什么会这样,我也不知道,在一个只有64位系统的文件夹中添加一个名为Desktop的文件夹,“C:\Windows\SysWOW64\config\systemprofile\”就在这个目录下。

  6. 这是我能找到的可以轻松解决问题的过程。可以直接将word转换为flash的工具print2Flash,需要付费。至于开裂,好像不是很好。Flashprint 尚未更新。在 32 位系统上使用。

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线