Windows服务-Office转PDF服务部署到服务器一系列问

2020-05-03  本文已影响0人  zxws1009

在我的上一篇文章中介绍到如何创建一个windows 服务- 用于将office文件转化为pdf文件;
上一篇文章详情请关注 Windows服务-Office转PDF文件

上次介绍到本地成功测试,接下到服务器上测试,就发生了一些错误,接下来我就介绍一些遇到的问题以及解决方案。
服务器: windows service 2012 R2

问题: PowerPoint could not open the file.

2020-05-02 11:40:34:386 Info [Thread9] 开始转换:d65bea632f874108bbf58379e49e906c.pptx
2020-05-02 11:40:34:464 Exception [Thread5] ConvertPptToPdf: d65bea632f874108bbf58379e49e906c.pptx出现异常 Exception:
System.Runtime.InteropServices.COMException (0x80004005): See inner exception(s) for details. ---> System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.Runtime.InteropServices.COMException: PowerPoint could not open the file.
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   在 NetOffice.Invoker.MethodReturn(COMObject comObject, String name, Object[] paramsArray)
   在 NetOffice.Invoker.MethodReturn(COMObject comObject, String name, Object[] paramsArray)
   在 NetOffice.PowerPointApi.Presentations.Open(String fileName, Object readOnly, Object untitled, Object withWindow)
   在 LMS.DocumentConvertService.ConvertHelper.<>c__DisplayClass1_0.<ConvertPptToPdf>b__0() 位置 F:\Projects\LMS.DocumentConvertService\Service\ConvertHelper.cs:行号 75

2020-05-02 11:40:34:480 Info [Thread9] 转换失败:d65bea632f874108bbf58379e49e906c.pptx

首先我确定我是在服务器安装了office2010;并且我可以直接在服务器上打开office文档;
发生这个错误的我猜想应该是服务没有权限打开office,因此我在网上查了一些资料;

如何解决Windows Server 2008 服务启动不能调用Office Word的问题
服务器上不能使用office,com组件配置不成功

按照以上方案尝试以后,还是一直报那个错误,在国内网站上就找不到相关问题,因此只能翻墙查查了。

很幸运很快就找到了解决方案,附上参考链接。

PowerPoint-could-not-open-the-file
https://stackoverflow.com/questions/2653740/problems-with-office-automation-in-asp-net-i-can-use-alternatives-such-as-open

解决方案就是占到这个目录C:\Windows\SysWOW64\config\systemprofile\Desktop
新建一个Desktop的文件夹即可完美解决。

如果是32位则在这个目录:C:\Windows\System32\config\systemprofile\Desktop

至此,测试服务器上的问题全部解决。接下来将在Staging和PROD服务器上待检。

附源码地址:https://gitee.com/zxws1009/LMS.DocumentConvert.git

欢迎一起留言探讨!

上一篇下一篇

猜你喜欢

热点阅读