C# Aspose slides .Net group shapes

145 Views Asked by At

I have a .pptx template with existing textbox with already set alttext name. I'm also trying to generate shapes from a svg file. The textbox should hold the name of the svg file.

After successful generating shapes from the svg file I'd like to group both the svg file and textbox. This the code im currently using to generate shapes from svg file and fill textbox with svg filename.

    using (Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(Application.StartupPath + @"\Templates\Template1.pptx"))
{
    try
    {
        string svgContent1 = File.ReadAllText(dataGridView1.Rows[0].Cells[1].Value.ToString());
        ISvgImage svgImage1 = new SvgImage(svgContent1);                    
        pres.Slides[0].Shapes.AddGroupShape(svgImage1, (float)66.79292, (float)110.5453, (float)52.56, (float)52.56);
        IShape Text0_1 = SearchTextBox.FindShape(pres.Slides[0], "TextBox1");
        if (Text0_1 != null)
        {
            ((IAutoShape)Text0_1).TextFrame.Text = dataGridView1.Rows[0].Cells[1].Value.ToString();
        }                   
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            sfd.Title = "Save PowerPoint Icons";
            sfd.CheckFileExists = false;
            sfd.CheckPathExists = true;
            sfd.DefaultExt = "pptx";
            sfd.Filter = "Powerpoint Files (*.pptx) | *.pptx";
            sfd.FilterIndex = 1;
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                pres.Save(sfd.FileName, SaveFormat.Pptx);
                Cursor = Cursors.Default;
            }
    }
    catch (FileFormatException ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }
}
       
1

There are 1 best solutions below

0
Andrey P. On BEST ANSWER

Please look at the following code snippet. You should create group shapes in PowerPoint documents using Aspose.Slides like this:

var groupShape = pres.Slides[0].Shapes.AddGroupShape(svgImage, x, y, width, height);
groupShape.Shapes.AddClone(textBox);
pres.Slides[0].Shapes.Remove(textBox);

It works.