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

前端 未结 1 338
再見小時候
再見小時候 2021-01-16 19:18

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

Application pptAppli         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 19:38

    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 files = new List();
    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.

    0 讨论(0)
提交回复
热议问题