PPTX到图像的转换在Windows Server 2012生产环境中不起作用 [英] PPTX to Image conversion doesn't work on windows server 2012 production

查看:117
本文介绍了PPTX到图像的转换在Windows Server 2012生产环境中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要将上载的PPT或PPTX文件转换为图像文件.我们使用以下(POC代码)在本地开发了此工作:

We have requirement to convert uploaded PPT or PPTX files into image files. We developed this working locally with following (POC code):

Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Open2007(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
List<string> files = new List<string>();
for (int i = 1; i <= pptPresentation.Slides.Count; i++)
{
    pptPresentation.SaveCopyAs(serverPath + randomId, PpSaveAsFileType.ppSaveAsPNG, MsoTriState.msoTrue);
    files.Add(root + "Uploads/Slide" + i + ".PNG");
}
pptPresentation.Close();

现在在Windows Server 2012 R2上部署此代码时,出现以下错误:

Now when this code is deployed on Windows Server 2012 R2, I receive following error:

此错误看起来像是一些访问权限问题,当我用Google搜索时,发现了一些我运气不好的解决方案,其中有一些:

This error looks like some access permissions issue and when I googled I found several solutions which I tried with no luck, here's some of them:

  1. 在服务器上安装Office-在服务器上安装Office毫无意义:(我已经安装好了,但仍然遇到同样的问题.

  1. Install office on server - not make any sense to have office on server :( well I installed and still getting same issue.

在服务器上安装Office Interop程序集-我在Windows Server 2012上找不到此程序集,我在这里找到的该程序集

Install office Interop Assemblies on server - i can't find this assembly for windows server 2012, the one i found here https://www.microsoft.com/en-us/download/details.aspx?id=3508 is not supported for 2012 and when I installed it doesn't work.

也尝试过此解决方案 https://stackoverflow.com/a/30117146

我们无法切换到Aspose,Spire等付费解决方案

We can't switch to paid solutions like Aspose, Spire etc

对此线程的任何帮助都将受到高度赞赏. 谢谢.

Any help on this thread is highly appreciated. Thanks.

推荐答案

以下是适用于所有服务器的缩小范围的解决方案,我将在7个月的成熟研究后发布此解决方案.

Here's the narrowed down solution which worked on all the servers, i'm posting this solution after 7 months mature research.

  1. 在每台服务器上安装Office并激活了产品
  2. 在C:\ Windows \ SysWOW64 \ config \ systemprofile \ Desktop(64位OS)上创建文件夹"Desktop"
  3. 在IIS中,将ApplicationPool标识从"ApplicationPoolIdentity"更改为"LocalSystem".
  1. Installed Office and activated the product on every servers
  2. Created a folder 'Desktop' at C:\Windows\SysWOW64\config\systemprofile\Desktop (64 bit OS)
  3. In IIS changed ApplicationPool identity from 'ApplicationPoolIdentity' to 'LocalSystem'.

就是这样,我能够将幻灯片转换为图像.

That's it and i was able to convert slides into images.

源代码

如果您对我使用的代码感兴趣:

In case you are interested in code that I was using:

Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Open2007(Server.MapPath("~/tempslides/pptfilename.pptx"), MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
List<string> files = new List<string>();
for (int i = 1; i <= pptPresentation.Slides.Count; i++)
{
    pptPresentation.SaveCopyAs(serverPath + randomId, PpSaveAsFileType.ppSaveAsPNG, MsoTriState.msoTrue);
    files.Add(Server.MapPath("~/tempslides") + "/slide" + i + ".PNG");
}
pptPresentation.Close();

要运行以上代码,您需要在项目中添加对interop lib的引用.

To run above code, you need to add reference to interop lib in your project.

希望这可以帮助您节省时间.

Hope this helps you to save your time.

这篇关于PPTX到图像的转换在Windows Server 2012生产环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆