Solved

Generate a Powerpoint presentation in an ASP.NET application

Posted on 2014-12-12
19
467 Views
Last Modified: 2015-01-27
Hi experts,

I have a ASP.NET/VB.NET application and I need that It generate a Powerpoint presentation. It runs on a server that does not have the Office installed.

Basically, the function should create slides, fill them with some text and embed an Excel spreadsheet in a specific slide. Then, save the presentation in .PPTX format, and if possible in .PPSX format too.

Finally, as my budget is small, the suggested solution should be free or low price. Any suggestions?

Thanks in advance,

Marcelo Camarate
0
Comment
Question by:Marcelo Camarate
  • 8
  • 7
  • 3
19 Comments
 
LVL 69

Expert Comment

by:Merete
Comment Utility
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Merete,

Thanks for your reply.

But I didn't understand your suggestion very well.

Do I need to use the Apache OpenOffice Software Development Kit (SDK)? How can I integrate Apache OpenOffice SDK with my ASP.NET/VB.NET application?

Regards,

Marcelo Camarate
0
 
LVL 69

Expert Comment

by:Merete
Comment Utility
Hi Camarate No,
I suggested you to consider using Open Office Impress slideshow creator instead this ASP.NET/VB.NET application? idea as I don't believe it is possible to Generate a Powerpoint presentation in an ASP.NET application as power point doesn't support it and that it also requires that your server have PowerPoint installed
2nd opinion
Is it possible to create a powerpoint file with asp.net?
Suggested 3rd party tool
Aspose.Slides for .NET is a unique PowerPoint® management component that enables .NET applications to read, write and manipulate PowerPoint documents without using Microsoft PowerPoint.
Aspose.Slides for .NET
regards Merete
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Merete,

Thanks for your reply.

Although the Aspose.Slides is a very good product, it is very expensive. There is no other option to generate PowerPoint presentations without using Microsoft PowerPoint?

Regards,

Marcelo Camarate
0
 
LVL 69

Expert Comment

by:Merete
Comment Utility
Well yes there  is if you were to use  CSS /  PHP web language. and embed it in a page.
If there is a script possible I do not know of it since you need to program a Microsoft item such as you said here>Excel spreadsheet in a specific slide. Then, save the presentation in .PPTX format,
Please feel free to ask for assistance using the request attention at the bottom right of your original question
Maybe then we could see if there any experts who know of a way to program such a slideshow outside of office and the web.
regards Merete
0
 
LVL 17

Expert Comment

by:John Gates
Comment Utility
Here is what you are looking for and it is built into the .NET framework:

http://support.microsoft.com/kb/303717

Hope this helps!
-D-
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Dimante,

Thanks for your reply, but I have considerations about your suggestion.

If I using Microsoft PowerPoint Object Library and the Microsoft Graph Object Library will be need that the Microsoft Office is installed on the Web Server, right? And I do not know if my customers will permit it.

I created a small application as suggested in the article that you suggested me, as below:

Imports Office = Microsoft.Office.Core
Imports Graph = Microsoft.Office.Interop.Graph
Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
Imports System.IO

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim PrincipalWebFolderName As String = System.IO.Path.GetDirectoryName(System.Web.HttpContext.Current.Server.MapPath(HttpContext.Current.Request.Path()))
        Dim PowerPointFilderName As String = PrincipalWebFolderName & "\PowerPoint"

        Dim sTemplate As String = PowerPointFilderName & "\Model.potx"
        Dim sFile As String = PowerPointFilderName & "\Presentation"
        Dim sPic As String = PowerPointFilderName & "\Image.JPG"

        Dim oApp As PowerPoint.Application
        Dim oPres As PowerPoint.Presentation
        Dim oSlide As PowerPoint.Slide
        Dim bAssistantOn As Boolean

        'Start Powerpoint and make its window visible but minimized.
        oApp = New PowerPoint.Application()
        'oApp.Visible = 0
        oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized

        'Create a new presentation based on the specified template.
        oPres = oApp.Presentations.Open(sTemplate, , , 0)

        'Build Slide #1:
        'Add text to the slide, change the font and insert/position a 
        'picture on the first slide.
        oSlide = oPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
        With oSlide.Shapes.Item(1).TextFrame.TextRange
            .Text = "My Sample Presentation"
            .Font.Name = "Comic Sans MS"
            .Font.Size = 48
        End With
        oSlide.Shapes.AddPicture(sPic, False, True, 150, 150, 500, 350)
        oSlide = Nothing

        'Build Slide #2:
        'Add text to the slide title, format the text. Also add a chart to the
        'slide and change the chart type to a 3D pie chart.
        oSlide = oPres.Slides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
        With oSlide.Shapes.Item(1).TextFrame.TextRange
            .Text = "My Chart"
            .Font.Name = "Comic Sans MS"
            .Font.Size = 48
        End With
        Dim oChart As Graph.Chart
        oChart = oSlide.Shapes.AddOLEObject(150, 150, 480, 320, _
                    "MSGraph.Chart.8").OLEFormat.Object
        oChart.ChartType = Graph.XlChartType.xl3DPie
        oChart = Nothing
        oSlide = Nothing

        'Build Slide #3:
        'Add a text effect to the slide and apply shadows to the text effect.
        oSlide = oPres.Slides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
        oSlide.FollowMasterBackground = False
        Dim oShape As PowerPoint.Shape
        oShape = oSlide.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
            "The End", "Impact", 96, False, False, 230, 200)
        oShape.Shadow.ForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
        oShape.Shadow.Visible = True
        oShape.Shadow.OffsetX = 3
        oShape.Shadow.OffsetY = 3
        oShape = Nothing
        oSlide = Nothing

        'Modify the slide show transition settings for all 3 slides in
        'the presentation.
        Dim SlideIdx(3) As Integer
        SlideIdx(0) = 1
        SlideIdx(1) = 2
        SlideIdx(2) = 3
        With oPres.Slides.Range(SlideIdx).SlideShowTransition
            .AdvanceOnTime = True
            .AdvanceTime = 3
            .EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
        End With
        Dim oSettings As PowerPoint.SlideShowSettings
        oSettings = oPres.SlideShowSettings
        oSettings.StartingSlide = 1
        oSettings.EndingSlide = 3

        'Prevent Office Assistant from displaying alert messages.
        'bAssistantOn = oApp.Assistant.On
        'oApp.Assistant.On = False

        'Run the slide show and wait for the slide show to end.
        'oSettings.Run()
        'Do While oApp.SlideShowWindows.Count >= 1
        '    System.Windows.Forms.Application.DoEvents()
        'Loop
        'oSettings = Nothing

        'Reenable Office Assisant, if it was on.
        'If bAssistantOn Then
        '    oApp.Assistant.On = True
        '    oApp.Assistant.Visible = False
        'End If

        'Close the presentation without saving changes and quit PowerPoint.
        If File.Exists(sFile & ".pps") Then
            File.Delete(sFile & ".pps")
        End If

        oPres.SaveAs(sFile, PowerPoint.PpSaveAsFileType.ppSaveAsShow)
        oPres.Saved = False

        oPres.Close()
        oPres = Nothing
        oApp.Quit()
        oApp = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()

    End Sub
End Class

Open in new window


The application runs fine when I run it under the Visual Basic 2013. But, when I publish it and run the web page under the IIS in my laptop (Windows 7 Home Premium), the follow error occurs:

 Web page error
To make sure that was not a Windows 7 Home Premium limitation, I created a virtual machine in Oracle VirtualBox with a Windows Server 2008 R2 installed to test the application too, and the same error occured.

What do I need to do for the application to be published correctly?

Regards,

Marcelo Camarate
0
 
LVL 17

Expert Comment

by:John Gates
Comment Utility
That looks to me to be a permissions issue.  When you publish the web project make sure all dlls are copied to bin.  Also make sure the IUSR account has to appropriate permissions to the folder and files that are in the folder.  You should not need office installed on the target.

-D-
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Dimante,

Thanks for your reply, but is not working fine yet.

I checked all the application folder permissions and everything was OK. Then, I changed the anonymous user of the IIS transaction, and granted the privileges in the application folder, as can see below:

T1.pngT2.png
Even so, the same error occurred.

To confirm that was really a privilege problem in the application folder, I modified the application to record a text file before begin the Powerpoint file create. As you can see below, this routine is between lines 27 to 33.

Imports Office = Microsoft.Office.Core
Imports Graph = Microsoft.Office.Interop.Graph
Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
Imports System.IO

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim PrincipalWebFolderName As String = System.IO.Path.GetDirectoryName(System.Web.HttpContext.Current.Server.MapPath(HttpContext.Current.Request.Path()))
        Dim PowerPointFilderName As String = PrincipalWebFolderName & "\PowerPoint"

        Dim sTemplate As String = PowerPointFilderName & "\Model.potx"
        Dim sFile As String = PowerPointFilderName & "\Presentation"
        Dim sPic As String = PowerPointFilderName & "\Image.JPG"

        Dim oApp As PowerPoint.Application
        Dim oPres As PowerPoint.Presentation
        Dim oSlide As PowerPoint.Slide
        Dim bAssistantOn As Boolean

        Dim tFile As String = PowerPointFilderName & "\PermissionTest.txt"
        If File.Exists(tFile) Then
            File.Delete(tFile)
        End If
        Dim fText As New StreamWriter(tFile)
        fText.WriteLine("I had permission to record this file")
        fText.Close()

        'Start Powerpoint and make its window visible but minimized.
        oApp = New PowerPoint.Application()
        'oApp.Visible = 0
        oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized

        'Create a new presentation based on the specified template.
        oPres = oApp.Presentations.Open(sTemplate, , , 0)

        'Build Slide #1:
        'Add text to the slide, change the font and insert/position a 
        'picture on the first slide.
        oSlide = oPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
        With oSlide.Shapes.Item(1).TextFrame.TextRange
            .Text = "My Sample Presentation"
            .Font.Name = "Comic Sans MS"
            .Font.Size = 48
        End With
        oSlide.Shapes.AddPicture(sPic, False, True, 150, 150, 500, 350)
        oSlide = Nothing

        'Build Slide #2:
        'Add text to the slide title, format the text. Also add a chart to the
        'slide and change the chart type to a 3D pie chart.
        oSlide = oPres.Slides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
        With oSlide.Shapes.Item(1).TextFrame.TextRange
            .Text = "My Chart"
            .Font.Name = "Comic Sans MS"
            .Font.Size = 48
        End With
        Dim oChart As Graph.Chart
        oChart = oSlide.Shapes.AddOLEObject(150, 150, 480, 320, _
                    "MSGraph.Chart.8").OLEFormat.Object
        oChart.ChartType = Graph.XlChartType.xl3DPie
        oChart = Nothing
        oSlide = Nothing

        'Build Slide #3:
        'Add a text effect to the slide and apply shadows to the text effect.
        oSlide = oPres.Slides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
        oSlide.FollowMasterBackground = False
        Dim oShape As PowerPoint.Shape
        oShape = oSlide.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
            "The End", "Impact", 96, False, False, 230, 200)
        oShape.Shadow.ForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
        oShape.Shadow.Visible = True
        oShape.Shadow.OffsetX = 3
        oShape.Shadow.OffsetY = 3
        oShape = Nothing
        oSlide = Nothing

        'Modify the slide show transition settings for all 3 slides in
        'the presentation.
        Dim SlideIdx(3) As Integer
        SlideIdx(0) = 1
        SlideIdx(1) = 2
        SlideIdx(2) = 3
        With oPres.Slides.Range(SlideIdx).SlideShowTransition
            .AdvanceOnTime = True
            .AdvanceTime = 3
            .EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
        End With
        Dim oSettings As PowerPoint.SlideShowSettings
        oSettings = oPres.SlideShowSettings
        oSettings.StartingSlide = 1
        oSettings.EndingSlide = 3

        'Prevent Office Assistant from displaying alert messages.
        'bAssistantOn = oApp.Assistant.On
        'oApp.Assistant.On = False

        'Run the slide show and wait for the slide show to end.
        'oSettings.Run()
        'Do While oApp.SlideShowWindows.Count >= 1
        '    System.Windows.Forms.Application.DoEvents()
        'Loop
        'oSettings = Nothing

        'Reenable Office Assisant, if it was on.
        'If bAssistantOn Then
        '    oApp.Assistant.On = True
        '    oApp.Assistant.Visible = False
        'End If

        'Close the presentation without saving changes and quit PowerPoint.
        If File.Exists(sFile & ".pps") Then
            File.Delete(sFile & ".pps")
        End If

        oPres.SaveAs(sFile, PowerPoint.PpSaveAsFileType.ppSaveAsShow)
        oPres.Saved = False

        oPres.Close()
        oPres = Nothing
        oApp.Quit()
        oApp = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()

    End Sub
End Class

Open in new window


Then, to my surprise, the routine to create the text file executed OK, as you can see below:

T3.png
Because the error line shifted to 36 ...

T4.png
... that is exactly the command "oApp = New PowerPoint.Application ()", to starts the Powerpoint.

Can you (or someone) help me, please?

Regards,

Marcelo Camarate
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Expert Comment

by:John Gates
Comment Utility
The next step is to install powerpoint on the web server to see if it does need to be installed.
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Dimante,

Thanks for your reply, but I forgot to mention in my last post that I've installed the Microsoft Office, as you see below.

T5.png
Regards,

Marcelo Camarate
0
 
LVL 17

Expert Comment

by:John Gates
Comment Utility
Please take a look at the following:

http://www.vbforums.com/showthread.php?657928-failed-due-to-the-following-error-80070005-Access-is-denied

That error you are receiving is permissions related.  In this case it is looking like it is complus.  Just use the above link as a guide.  Look for Powerpoint object where is specifies Word.

-D-
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Dimante,

Sorry, but I was in a business travel in the last days of last week. Only today I came back to normal life.

I will check your suggestion and reply to you as soon as possible.

Regards,

Marcelo Camarate
0
 
LVL 17

Expert Comment

by:John Gates
Comment Utility
Sounds good.  Let me know and we can go from there!
0
 

Author Comment

by:Marcelo Camarate
Comment Utility
Hi Dimante,

Only today could check your suggestion and I'm more confused than before.

When I run the Component Services in my windows server 2013, appears the window below that hasn't any reference to Powerpoint. Has only one reference to Excel (red outline) and a to "Office Licensing COM Server 15" (red arrow).

Component-Services.png
As the Office version installed was 2010, I decided uninstall it and install an Office 2013 in the server, but this did not change the scenario.

For your knowledge, my environment has a Windows Server 2008 R2 installed into an Oracle VM VirtualBox section. The Office 2013 package is installed on the Windows Server, as below:

Office-2013.png
Can you help me, please?

Regards,

Marcelo Camarate
0
 
LVL 17

Expert Comment

by:John Gates
Comment Utility
In that case let's simplify this.  Here is the API you need to leverage:

https://powerpoint.codeplex.com/

Hope this helps!
-D-
0
 
LVL 17

Accepted Solution

by:
John Gates earned 500 total points
Comment Utility
The API will NOT require office to be installed on the server.
0
 

Author Closing Comment

by:Marcelo Camarate
Comment Utility
Hi dimante,

Excuse me the delay but I was testing your suggestion.

The Spire.Presentation that you suggested has a free version limited to up to 10 slides per presentation. As this limit is low for me, I will need to purchase the product, which will represent a high value that was not budgeted. I needed something less expensive.

But, as Spire.Presentation worked satisfactorily in my tests, your suggestion was good. So, I'm considering the topic closed.

Regards,

Marcelo Camarate
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In all recent versions of PowerPoint it is possible to trigger animations. This means the animation takes place when a certain shape is clicked. This allows you to run animation “on demand” and outwith the normal sequence of mouse cl…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now