PPTX to Image conversion doesn't work on windows server 2012 production

醉酒当歌 提交于 2019-12-02 14:44:27

问题


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();

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

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. Install office on server - not make any sense to have office on server :( well I installed and still getting same issue.

  2. 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.

  3. Tried this solution https://stackoverflow.com/a/30117146 as well

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

Any help on this thread is highly appreciated. Thanks.


回答1:


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

  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.

Source Code

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();

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

Hope this helps you to save your time.



来源:https://stackoverflow.com/questions/36059617/pptx-to-image-conversion-doesnt-work-on-windows-server-2012-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!