Office 文件转换为SWF文件

第一步先将Office文件转换为PDF文件,第二步将PDF文件转换为SWF文件.
Office文件转为PDF文件使用微软的插件 saveaspdf,(此插件应用于office2007下).
PDF文件转换为SWF文件使用SWFTOOLS下的pdf2swf.exe

举 例Word文件转换为SWF文件,代码如下:

Office 文件转换为SWF文件 - aijun980204 - 学习空间Office 文件转换为SWF文件 - aijun980204 - 学习空间Code
using Microsoft.Office.Interop.Word;

private Application _wordApp = null;
private Object Nothing = System.Reflection.Missing.Value;
//实例化App
try
{
_wordApp = (Microsoft.Office.Interop.Word.Application)
Microsoft.VisualBasic.Interaction.GetObject(null, "Word.Application");
}
catch
{
_wordApp = new Microsoft.Office.Interop.Word.Application();
}
/// <summary>
/// 释放所有资源
/// </summary>
public void Close()
{
if (_wordApp != null)
{
if (_wordApp.Documents.Count != 0)
{
_wordApp.ActiveDocument.Close(ref Nothing, ref Nothing, ref Nothing);
}
_wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
_wordApp = null;
}
}
/// <summary>
/// 将DOC转为HTML
/// </summary>
/// <param name="docFilePath">DOC文件路径</param>
/// <param name="pdfFilePath">PDF文件路径</param>
public void DocConvertPDF(string docFilePath,string pdfFilePath)
{
this.ReadTemplate(docFilePath);
Type wordType = _wordApp.GetType();
Type docType = _wordApp.ActiveDocument.GetType();
object saveFileName = pdfFilePath;
Object objFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
_wordApp.ActiveDocument.SaveAs(ref saveFileName, ref objFormat, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
}

/// <summary>
/// 将DOC转为SWF
/// </summary>
/// <param name="docFilePath">DOC文件路径</param>
/// <param name="swfFilePath">SWF文件路径</param>
public bool DocConvertSWF(string docFilePath, string swfFilePath)
{
string strfilePath = @"C:\temp\";
if (docFilePath.Contains(@"\"))
{
strfilePath = docFilePath.Substring(0,docFilePath.LastIndexOf(@"\")+1);
}
strfilePath += DateTime.Now.ToString("yyyyMMddHHmmssfff")+".pdf";
this.DocConvertPDF(docFilePath, strfilePath);
_wordApp.ActiveDocument.Close(ref Nothing, ref Nothing, ref Nothing);
System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"D:\Program Files\SWFTools\pdf2swf.exe",strfilePath + " -s flashversion=9 " + swfFilePath + " -t");
bool flag = false;
try
{
p.Start();
flag = true;
}
catch
{
flag = false;
}
try
{
if (p.HasExited)
{
p.Kill();
}
}
catch
{

}
return flag;
}
转换过程需要注意的几点:
1.一定得是在安装了 Office2007的机器上运行,并安装了saveaspdfandxps插件.
2.转换完成PDF后,记得关闭Word文档,否则文件会一直 占用,无法打开转换为SWF.
3.转换SWF文件时要加上"-s flashversion=9",否则在Flex里使用swfloader加载swf后,无法将其转换为MovieClip.
4.pdf2swf.exe 有很多参数,这里使用"-t"代表转换后的swf文件每一帧后都会加上stop()停止播放.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值