FormatException Is Thrown when Adding SVG Image to Group Shape in PPTX in C#

Hello @andrey.potapov
I’m in need of your help in solving FileFormatException ‘Input was not in correct format’ while creating PowerPoint shapes from svg file. I already have a PowerPoint template file that I’m using to add the shapes from svg files.

  1. I’m using Windows 10 Pro, build 19045.2486.
  2. Visual studio 2019.
  3. .NETFramewor 4.8
  4. Aspose.Slides.Net 23.2.0

I’ve attached both template and svg files. Here’s my code.

using (Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(Application.StartupPath + @"\Templates\Template5.pptx"))
{
    try
    {
        string svgContent1 = File.ReadAllText(dataGridView1.Rows[0].Cells[0].Value.ToString());
        ISvgImage svgImage1 = new SvgImage(svgContent1);
        var groupshape0_1 = 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();
        }
        groupshape0_1.Shapes.AddClone(Text0_1);
        pres.Slides[0].Shapes.Remove(Text0_1);

        string svgContent2 = File.ReadAllText(dataGridView1.Rows[1].Cells[0].Value.ToString());
        ISvgImage svgImage2 = new SvgImage(svgContent2);
        var groupshape0_2 = pres.Slides[0].Shapes.AddGroupShape(svgImage2, (float)254.5669, (float)110.751, (float)52.56, (float)52.56);
        IShape Text0_2 = SearchTextBox.FindShape(pres.Slides[0], "TextBox2");
        if (Text0_2 != null)
            ((IAutoShape)Text0_2).TextFrame.Text = dataGridView1.Rows[1].Cells[1].Value.ToString();
        groupshape0_2.Shapes.AddClone(Text0_2);
        pres.Slides[0].Shapes.Remove(Text0_2);

        string svgContent3 = File.ReadAllText(dataGridView1.Rows[2].Cells[0].Value.ToString());
        ISvgImage svgImage3 = new SvgImage(svgContent3);
        var groupshape0_3 = pres.Slides[0].Shapes.AddGroupShape(svgImage3, (float)442.3408, (float)110.1687, (float)52.56, (float)52.56);
        IShape Text0_3 = SearchTextBox.FindShape(pres.Slides[0], "TextBox3");
        if (Text0_3 != null)
            ((IAutoShape)Text0_3).TextFrame.Text = dataGridView1.Rows[2].Cells[1].Value.ToString();
        groupshape0_3.Shapes.AddClone(Text0_3);
        pres.Slides[0].Shapes.Remove(Text0_3);

        string svgContent4 = File.ReadAllText(dataGridView1.Rows[3].Cells[0].Value.ToString());
        ISvgImage svgImage4 = new SvgImage(svgContent4);
        var groupshape0_4 = pres.Slides[0].Shapes.AddGroupShape(svgImage4, (float)630.1146, (float)110.751, (float)52.56, (float)52.56);
        IShape Text0_4 = SearchTextBox.FindShape(pres.Slides[0], "TextBox4");
        if (Text0_4 != null)
            ((IAutoShape)Text0_4).TextFrame.Text = dataGridView1.Rows[3].Cells[1].Value.ToString();
        groupshape0_4.Shapes.AddClone(Text0_4);
        pres.Slides[0].Shapes.Remove(Text0_4);

        string svgContent5 = File.ReadAllText(dataGridView1.Rows[4].Cells[0].Value.ToString());
        ISvgImage svgImage5 = new SvgImage(svgContent5);
        var groupshape0_5 = pres.Slides[0].Shapes.AddGroupShape(svgImage5, (float)817.8885, (float)110.1687, (float)52.56, (float)52.56);
        IShape Text0_5 = SearchTextBox.FindShape(pres.Slides[0], "TextBox5");
        if (Text0_5 != null)
            ((IAutoShape)Text0_5).TextFrame.Text = dataGridView1.Rows[4].Cells[1].Value.ToString();
        groupshape0_5.Shapes.AddClone(Text0_5);
        pres.Slides[0].Shapes.Remove(Text0_5);

        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;
        }
        Cursor = Cursors.Default;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }
}

Template and files.zip (114.1 KB)

@Charles_Kamweti,
Thank you for reporting on the issue. I reproduced the problem with grouping the SVG images with text boxes.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-43841

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you found earlier (filed as SLIDESNET-43841) have been fixed in Aspose.Slides for .NET 23.5 (ZIP, MSI).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.