We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Generating PowerPoint Slides with Image Is Taking Very Long Time

Hi there, i’m creating ppt with atleast 50 slides which consists of title and one image using c#.net. I’m able to generate ppt but it is taking very long time. Can you please let me know how to optimize it.

@Krishna1278,
Thank you for contacting support.

Please check your results using the latest version of Aspose.Slides if it is possible. If the issue persists, please share the following data and information:

  • code example you used for generating the presentation
  • your time measurement results
  • OS version on which the code was executed
  • .NET target platform in your app
  • hardware description on which the time measurement was performed
  • input and output files (you can zip the files and upload the archive here)

please find the code below and help me to optimize it.

Aspose.Slides.License license = new Aspose.Slides.License();
license.SetLicense("Aspose.Slides.Net.lic");

if (license.IsLicensed())
{
    using (Presentation pres = new Presentation())
    {
        ISlide slide;

        float currentHeight = pres.SlideSize.Size.Height;
        float currentWidth = pres.SlideSize.Size.Width;

        pres.SlideSize.SetSize(currentWidth, currentHeight + 100, SlideSizeScaleType.EnsureFit);

        slide = pres.Slides[0];

        slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);

        ((IAutoShape)slide.Shapes[0]).TextFrame.Text = "Matrix";
        ((IAutoShape)slide.Shapes[1]).TextFrame.Text = MatrixName;
        pres.Slides.RemoveAt(0);

        IPPImage logoimage = pres.Images.AddImage(System.IO.File.ReadAllBytes(logoPath));
        slide.Shapes.AddPictureFrame(ShapeType.Rectangle, currentWidth - 100, currentHeight + 25, logoimage.Width, logoimage.Height, logoimage);

        for (int i = 0; i < ExportList.Count(); i++)
        {
            if (ExportList[i].Filename.Trim() != "")
            {
                ISvgImage svg = new SvgImage(ExportList[i].Svg);

                var emfImage = pres.Images.AddImage(svg);

                // LayoutSlides 2 - only title and object
                slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[5]);

                //Set the title text and formatting
                ((IAutoShape)slide.Shapes[0]).Height = 50;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Text = ExportList[i].Title.Trim();
                ((IAutoShape)slide.Shapes[0]).TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 25;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Left;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.SpaceAfter = 10;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.SpaceBefore = 10;
                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontUnderline = TextUnderlineType.Single;

                slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 125, 75, emfImage.Width, emfImage.Height, emfImage);

                slide.Shapes.AddPictureFrame(ShapeType.Rectangle, currentWidth - 100, currentHeight + 25, logoimage.Width, logoimage.Height, logoimage);
            }
        }

        pres.HeaderFooterManager.SetAllFootersText("\u00a9 -patent pending");

        pres.HeaderFooterManager.SetAllFootersVisibility(true);

        pres.Save(dataDir + "/" + pptname + ".pptx", SaveFormat.Pptx);
    }
}

@Krishna1278,
Thank you for the code example. Unfortunately, I can’t help you because I don’t have enough information. Please share the rest of the data and information mentioned above, including images. Also, note that your sample code does not compile (it contains an unknown ExportList property). It would be great if you could share a simple project.

Not able to upload the project due to big size , so please refer the code and the details below.

My development machine details:
Os Version : Windows 10 pro
Processor: Intel® Core™ i5-4200U CPU @ 1.60GHz 2.30 GHz
Time taken to generate ppt with 10 slides - 25 to 30 seconds

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Aspose.Slides;
using Aspose.Slides.Export;
using System.Drawing;

namespace AsposeSlides
{
    public class ExportMatrixModel
    {
        public string Filename { get; set; }
        public string Title { get; set; }
        public string Sequence { get; set; }
        public string Svg { get; set; }
        
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<ExportMatrixModel> ExportList = new List<ExportMatrixModel>();


            for (int i = 1; i <= 10; i++)
            {
                ExportMatrixModel data = new ExportMatrixModel();
                data.Filename = "test";
                data.Title = "test title";
                data.Sequence = i+"";
                data.Svg = "<svg xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' class='highcharts-root' style='font-family: &quot;Lucida Grande&quot;, &quot;Lucida Sans Unicode&quot;, Arial, Helvetica, sans-serif; font-size: 12px;' xmlns='http://www.w3.org/2000/svg' width='600' height='662' viewBox='0 0 600 662' role='img' aria-label=''><desc>Created with Highcharts 10.3.2</desc><defs><clipPath id='highcharts-t9su3nl-33-'><rect x='0' y='0' width='550' height='502' fill='none'></rect></clipPath><clipPath id='highcharts-t9su3nl-34-'><rect x='0' y='0' width='550' height='502' fill='none'></rect></clipPath></defs><rect fill='#ffffff' class='highcharts-background' stroke='#EBBA95' stroke-width='1' x='0.5' y='0.5' width='598' height='660' rx='0' ry='0'></rect><rect fill='none' class='highcharts-plot-background' x='25' y='25' width='550' height='502'></rect><g class='highcharts-label' transform='translate(293,5)'><text x='3' data-z-index='1' y='15'>T</text></g><g class='highcharts-label' transform='translate(294,527)'><text x='3' data-z-index='1' y='15'>B</text></g><g class='highcharts-label' transform='translate(25,276)'><text x='3' data-z-index='1' y='15'>L</text></g><g class='highcharts-label' transform='translate(561,276)'><text x='3' data-z-index='1' y='15'>R</text></g><g class='highcharts-plot-lines-0' data-z-index='0'><path fill='none' class='highcharts-plot-line ' stroke='blue' stroke-width='2' d='M 300 25 L 300 527'></path></g><g class='highcharts-plot-lines-0' data-z-index='0'><path fill='none' class='highcharts-plot-line ' stroke='blue' stroke-width='2' d='M 25 276 L 575 276'></path></g><g class='highcharts-grid highcharts-xaxis-grid' data-z-index='1'><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 24.5 25 L 24.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 93.5 25 L 93.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 162.5 25 L 162.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 230.5 25 L 230.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 299.5 25 L 299.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 368.5 25 L 368.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 437.5 25 L 437.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 505.5 25 L 505.5 527' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='0' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 574.5 25 L 574.5 527' opacity='1'></path></g><g class='highcharts-grid highcharts-yaxis-grid' data-z-index='1'><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 527.5 L 575 527.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 464.5 L 575 464.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 402.5 L 575 402.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 339.5 L 575 339.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 276.5 L 575 276.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 213.5 L 575 213.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 151.5 L 575 151.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 88.5 L 575 88.5' opacity='1'></path><path fill='none' stroke='#e6e6e6' stroke-width='1' stroke-dasharray='none' data-z-index='1' class='highcharts-grid-line' d='M 25 24.5 L 575 24.5' opacity='1'></path></g><rect fill='none' class='highcharts-plot-border' data-z-index='1' stroke='#cccccc' stroke-width='0' x='25' y='25' width='550' height='502'></rect><g class='highcharts-axis highcharts-xaxis' data-z-index='2'><path fill='none' class='highcharts-axis-line' stroke='#ccc' stroke-width='0' data-z-index='7' d='M 25 577 L 575 577'></path></g><g class='highcharts-axis highcharts-yaxis' data-z-index='2'><path fill='none' class='highcharts-axis-line' stroke='#ccc' stroke-width='0' data-z-index='7' d='M 25 25 L 25 527'></path></g><g class='highcharts-series-group' data-z-index='3'><g class='highcharts-series highcharts-series-0 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-0 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g><g class='highcharts-series highcharts-series-1 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-1 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g><g class='highcharts-series highcharts-series-2 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-2 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g><g class='highcharts-series highcharts-series-3 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-3 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g><g class='highcharts-series highcharts-series-4 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-4 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g><g class='highcharts-series highcharts-series-5 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='url(#highcharts-t9su3nl-34-)'></g><g class='highcharts-markers highcharts-series-5 highcharts-scatter-series' visibility='hidden' data-z-index='0.1' opacity='1' transform='translate(25,25) scale(1 1)' clip-path='none'></g></g><text x='300' text-anchor='middle' class='highcharts-title' data-z-index='4' style='color: rgb(51, 51, 51); font-size: 18px; fill: rgb(51, 51, 51);' y='24'></text><text x='300' text-anchor='middle' class='highcharts-subtitle' data-z-index='4' style='color: rgb(102, 102, 102); fill: rgb(102, 102, 102);' y='24'></text><text x='10' text-anchor='start' class='highcharts-caption' data-z-index='4' style='color: rgb(102, 102, 102); fill: rgb(102, 102, 102);' y='659'></text><g class='highcharts-legend highcharts-no-tooltip' data-z-index='7' transform='translate(75,595)'><rect fill='none' class='highcharts-legend-box' rx='0' ry='0' stroke='#999999' stroke-width='0' x='0' y='0' width='444' height='56'></rect><g data-z-index='1'><g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-0 highcharts-legend-item-hidden' data-z-index='1' transform='translate(8,3)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' text-anchor='start' data-z-index='2' y='15' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>Where you think you are</text></g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-1 highcharts-legend-item-hidden' data-z-index='1' transform='translate(232.33984375,3)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' y='15' text-anchor='start' data-z-index='2' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>Average (Everybody Current)</text></g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-2 highcharts-legend-item-hidden' data-z-index='1' transform='translate(8,18)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' y='15' text-anchor='start' data-z-index='2' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>Where you would like to be</text></g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-3 highcharts-legend-item-hidden' data-z-index='1' transform='translate(232.33984375,18)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' y='15' text-anchor='start' data-z-index='2' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>Average (Everybody Desired)</text></g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-4 highcharts-legend-item-hidden' data-z-index='1' transform='translate(8,33)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' y='15' text-anchor='start' data-z-index='2' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>How Others Rated Me</text></g><g class='highcharts-legend-item highcharts-scatter-series highcharts-color-undefined highcharts-series-5 highcharts-legend-item-hidden' data-z-index='1' transform='translate(232.33984375,33)'><path fill='none' d='M 0 11 L 12 11' class='highcharts-graph' stroke-width='0' stroke='#cccccc'></path><path fill='#cccccc' d='M 6 17 A 6 6 0 1 1 6.005999999000004 16.99999700000025 Z' class='highcharts-point' stroke='#cccccc' stroke-width='0' opacity='1'></path><text x='17' y='15' text-anchor='start' data-z-index='2' style='color: rgb(204, 204, 204); cursor: pointer; font-size: 12px; font-weight: bold; fill: rgb(204, 204, 204);'>Average (How Others Rated Me)</text></g></g></g></g><g class='highcharts-axis-labels highcharts-xaxis-labels' data-z-index='7'></g><g class='highcharts-axis-labels highcharts-yaxis-labels' data-z-index='7'></g></svg>";

                ExportList.Add(data);
            }


            string dataDir = "../";
            /////////////string logoPath = "../logo.jpg";
            //string pptname = Guid.NewGuid() + "";
            string pptname = "test" + "_" + DateTime.Now.ToString("MMddyyyyHHMMss");

            string MatrixName = "test";


            if (!string.IsNullOrEmpty(MatrixName) && ExportList.Count() > 0)           
            {
                ExportList = ExportList.ToList().OrderBy(x => x.Sequence).ToList();
                
                Aspose.Slides.License license = new Aspose.Slides.License();

                license.SetLicense("Aspose.Slides.Net.lic");



                if (license.IsLicensed())
                {
                    using (Presentation pres = new Presentation())
                    {
                        ISlide slide;

                        float currentHeight = pres.SlideSize.Size.Height;
                        float currentWidth = pres.SlideSize.Size.Width;

                        pres.SlideSize.SetSize(currentWidth, currentHeight + 100, SlideSizeScaleType.EnsureFit);

                        slide = pres.Slides[0];

                        slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);

                        ((IAutoShape)slide.Shapes[0]).TextFrame.Text = "Keyhubs Matrix";
                        ((IAutoShape)slide.Shapes[1]).TextFrame.Text = MatrixName;
                        pres.Slides.RemoveAt(0);

                        ////IPPImage logoimage = pres.Images.AddImage(System.IO.File.ReadAllBytes(logoPath));
                        //slide.Shapes.AddPictureFrame(ShapeType.Rectangle, currentWidth - 100, currentHeight + 25, logoimage.Width, logoimage.Height, logoimage);

                        for (int i = 0; i < ExportList.Count(); i++)
                        {

                            if (ExportList[i].Filename.Trim() != "")
                            {

                                ISvgImage svg = new SvgImage(ExportList[i].Svg);

                                var emfImage = pres.Images.AddImage(svg);

                                // LayoutSlides 2 - only title and object
                                slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[5]);


                                //Set the title text and formatting
                                ((IAutoShape)slide.Shapes[0]).Height = 50;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Text = ExportList[i].Title.Trim();
                                ((IAutoShape)slide.Shapes[0]).TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 25;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Left;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.SpaceAfter = 10;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].ParagraphFormat.SpaceBefore = 10;
                                ((IAutoShape)slide.Shapes[0]).TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontUnderline = TextUnderlineType.Single;



                                slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 125, 75, emfImage.Width, emfImage.Height, emfImage);


                              //  slide.Shapes.AddPictureFrame(ShapeType.Rectangle, currentWidth - 100, currentHeight + 25, logoimage.Width, logoimage.Height, logoimage);



                            }
                        }

                        pres.HeaderFooterManager.SetAllFootersText("\u00a9 keyhubs-patent pending");

                        pres.HeaderFooterManager.SetAllFootersVisibility(true);

                        pres.Save(dataDir + "/" + pptname + ".pptx", SaveFormat.Pptx);

                    }


                }




            }
            else
            {

               
            }

            Console.WriteLine("Finished...");
            Console.ReadLine();
        }
    }
}

it is taking very long time even in my production server. Prod server details
Os: Windows (Windows Server 2016 Datacenter),
Size: Standard D11 v2 Promo (2 vcpus, 14 GiB memory)
Time taken for generating 75 slides 20 s

@Krishna1278,
I am working on the issue and will get back to you soon.

@Krishna1278,
Unfortunately, I have not managed to reproduce the problem you described. Please try to isolate the problem and share more details to reproduce it.

Were you to execute the code using c# console app and please let me know your execution time to generate the ppt. So that i will dig deeper from my end. Thanks!

@Krishna1278,
The code example above takes 3 seconds to generate the presentation on my end.

ok. thank you!.Let me dig in deeper

@Krishna1278,
We will be waiting for your new results or new information on the issue.