Opening .PPTX file throws an error

Hi,

Currently my application is using Aspose.Slides for opening and updating .ppt files .But I want to upgrade it so that it can handle both .ppt and .pptx files. Currently I am using Aspose.Slides 3.1.1.7 dll version.

When I am opening .pptx file through my C# code.

Presentation presnew = new Presentation("C:\\Sample.pptx");

It is throwing error "Index was outside the bounds of the array."

Am I missing some thing? Please Help.

Thanks,

Romana Tanveer


Hi Romana,

Thanks for your interest in Aspose.Slides.

We apologize for the delayed response. Presentation class is used to open PPT files. However, to work with PPTX file, PresentationEX class is used. Please try using following code line to access PPTX file.

PresentationEx pres = new PresentationEx();

Hi,

Thanks for your response.

Currently I am dealing with 2003 ppt , While upgrading to 2007 PPtx , I am not able to find many of the controls in Aspose.Slide.Pptx namespace like alternative Text property. I am attaching Sample code here which I want to convert. It would be helpful I you tell me where to find detail documentation on dealing with PPtx files or tell me some of the corresponding pptx controls.

for (int j = 2; j <= presnew.Slides.Count; j++)

{

Slide slide = presnew.Slides[j];

Aspose.Slides.Shapes shapes = slide.Shapes;

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

{

Aspose.Slides.Shape shape = shapes[i];

//check if the shape is Picture

if (shape is PictureFrame)

{

PictureFrame pic = shape as PictureFrame;

//match d alternate text on image wid d image name read from xml file

if (pic.AlternativeText != null && pic.AlternativeText != "")

{}

}

}

Thanks & Regards,

Romana Tanveer

Dear Romana,

Thanks for showing keen interest in Aspose.Slides.

I have converted yours provided Aspose.Slides.PPT to Aspose.Slides.PPTX for .NET. Please use the code snippet below:

PresentationEx presnew = new PresentationEx("c:\\aa.pptx");

for (int j = 0; j < presnew.Slides.Count; j++)
{
    SlideEx slide = presnew.Slides[j];
    ShapesEx shapes = slide.Shapes;

    for (int i = 0; i < shapes.Count; i++)
    {
        ShapeEx shape = shapes[i];

        //Check if the shape is Picture
        if (shape is PictureFrameEx)
        {
            PictureFrameEx pic = shape as PictureFrameEx;

            //Match the alternate text on image with the image name
            if (pic.AlternativeText != null && pic.AlternativeText != "")
            { }
        }
    }
}

We will update you with the status of detailed documentation for Aspose.Slides.PPTX. We are extremely sorry for the inconvenience.

Thanks and Regards,

Hi Romana,


Thanks for you interest in Aspose.Slides.

We like to share with you, that the detailed PPTX documentation shall be uploaded by the start of next week.

We apologize for the delay.


Hi,

The Corresponding code that u have provided for working with .pptx is not working.

It can not find Alternative Text property of PictureFrameEx. My logic depends upon finding all the images having alternative text. So I am facing problem while converting .ppt to .pptx version.

Also I have one question : I have open 2003 version ppt in 2007 , doing some changes and saving back as 2003 ppt and using this ppt with Aspose.Slides . But it is giving different result from the ppt saved in 2003 version. Can you suggest some solution for this.

Thanks in advance

Romana Tanveer

Hi Romana,

romana:

1. The Corresponding code that u have provided for working with .pptx is not working.

It can not find Alternative Text property of PictureFrameEx. My logic depends upon finding all the images having alternative text. So I am facing problem while converting .ppt to .pptx version.

I have modified the code snippet for you and its working fine. Please execute the following code snippet again. For your reference, I have also attached the source PPTX file as well. For further details, please visit this link.

PresentationEx presnew = new PresentationEx("d:\\ppt\\Pic_Frame_Test.pptx");

for (int j = 0; j < presnew.Slides.Count; j++)
{
    SlideEx slide = presnew.Slides[j];
    ShapesEx shapes = slide.Shapes;

    for (int i = 0; i < shapes.Count; i++)
    {
        ShapeEx shape = shapes[i];

        //Check if the shape is Picture
        if (shape is PictureFrameEx)
        {
            PictureFrameEx pic = shape as PictureFrameEx;

            //Match the alternate text on image with the image name
            if (pic.AlternativeText != null && pic.AlternativeText != "")
            {
                MessageBox.Show(pic.AlternativeText + " selected");
            }
        }
    }
}

romana:

2. Also I have one question : I have open 2003 version ppt in 2007 , doing some changes and saving back as 2003 ppt and using this ppt with Aspose.Slides . But it is giving different result from the ppt saved in 2003 version. Can you suggest some solution for this.

Unfortunately, this behavior persists and we are working over possibilities of solution. For the time being you may please continue using PowerPoint 2003.

Thanks and Regards,

Hi,

It is still not working. The Error it is showing is 'Aspose.Slides.Pptx.PictureFrameEx' does not contain a definition for 'AlternativeText' .

I am using Aspose.Slides 3.1.1.7 version. Is this property supported in this version.

Thanks & Regards

Romana Tanveer

Hi Romana,

The version of Aspose.Slides for .NET that you have specified does not support the access to "Alternative Text" option. That’s why you are getting error. Please try using the latest version of Aspose.Slides for .NET available here.

Thanks and Regards,

Hi Mudassir,

Thanks for the help. I have downloaded the latest version but still I got stuck up while converting code from ppt to pptx. I am not able to find many properties which are available while working with ppt. I am providing you my code, It will be really nice If you help me in changing it to pptx version.

public ReturnValue UpdatePowerpoint(string fReportID, string fPPTPath, string pptname)
{
string output_file_name = string.Empty;
string[] files = System.IO.Directory.GetFiles(fPPTPath);
string fileName = string.Empty;

//Get the Ptah of the pPt saved in Report folder
String PPTFullPath = fPPTPath + "\\" + pptname;

//Open the PPT
Presentation presnew = new Presentation(PPTFullPath);

//loop through all Slides to replace all images which have Alt Text
for (int j = 2; j <= presnew.Slides.Count; j++)
{
Slide slide = presnew.GetSlideByPosition(j);
Aspose.Slides.Shapes shapes = slide.Shapes;

for (int i = 0; i < shapes.Count; i++)
{
Aspose.Slides.Shape shape = shapes[i];

//check if the shape is Picture
if (shape is PictureFrame)
{
PictureFrame pic = shape as PictureFrame;

//match d alternate text on image wid d image name read from xml file
if (pic.AlternativeText != null && pic.AlternativeText != "")
{
//get d absolute path of newpic
string str = fPPTPath + "\\" + pic.AlternativeText.ToString() + ".jpeg";
if (File.Exists(str))
{
Aspose.Slides.Picture new_pic = new Aspose.Slides.Picture(slide.Parent, str);
int old_pic_id = pic.PictureId,
new_pic_id = slide.Parent.Pictures.Add(new_pic);
pic.PictureId = new_pic_id;

pic.AnimationSettings.AdvanceMode = ShapeAdvanceMode.AdvanceOnClick;

}
}
}

else if (shape.TextFrame != null && shape.TextFrame.AlternativeText != "")
{
TextFrame tf = shape.TextFrame;
if (tf.AlternativeText == "Currency")
{
string CurrencyText = rmBL.GetLiteral("txtInputPrice");
tf.Text = CurrencyText + Currency;
tf.Paragraphs[0].Portions[0].FontBold = true;
tf.Paragraphs[0].Portions[0].FontHeight = 10;
tf.Paragraphs[0].Portions[0].FontColor = Color.Black;
}
}

}
}


//Save the modified PPT
output_file_name = fPPTPath + "\\" + pptname;
presnew.Write(output_file_name);

}

Thanks & Regards,

Romana Tanveer

Hi Romana,

We are working on providing you support for converting PPT code to PPTX. We will respond you ASAP.

We are sorry for the inconvenience,

Hi,

Any Updates on PPTX code.

Thanks & Regards,

Romana Tanveer

Dear Romana,

First of all please accept my apologies for taking time.

Please use the code snippet below for accessing the picture frames and text frames. Remember that in PPTX, text frames are either part of place hodlers or part of autoshapes in shapes.

static void UpdatePowerpoint(string fReportID, string fPPTPath, string pptname)
{
    string output_file_name = string.Empty;
    string[] files = System.IO.Directory.GetFiles(fPPTPath);
    string fileName = string.Empty;

    //Get the Ptah of the pPt saved in Report folder
    String PPTFullPath = fPPTPath + "\\" + pptname;

    //Open the PPT
    PresentationEx presnew = new PresentationEx(PPTFullPath);

    //loop through all Slides to replace all images which have Alt Text
    for (int j = 2; j <= presnew.Slides.Count; j++)
    {
        Aspose.Slides.Pptx.SlideEx slide = presnew.Slides[j - 1];
        Aspose.Slides.Pptx.ShapesEx shapes = slide.Shapes;

        for (int i = 0; i < shapes.Count; i++)
        {
            Aspose.Slides.Pptx.ShapeEx shape = shapes[i];

            //check if the shape is Picture
            if (shape is PictureFrameEx)
            {
                Aspose.Slides.Pptx.PictureFrameEx pic = shape as PictureFrameEx;

                //match d alternate text on image wid d image name read from xml file
                if (pic.AlternativeText != null && pic.AlternativeText != "")
                {
                    //get d absolute path of newpic
                    string str = fPPTPath + "\\" + pic.AlternativeText.ToString() + ".jpg";
                    str = fPPTPath + "\\Winter.jpg";

                    if (File.Exists(str))
                    {
                        //Adding Image to Picture frame
                        System.Drawing.Image img = (System.Drawing.Image)new Bitmap(str);
                        ImageEx imgx = pic.Presentation.Images.AddImage(img);
                        pic.PictureFormat.Picture.Image = imgx;

                        slide.SlideShowTransition.AdvanceOnClick = true;
                    }
                }
            }
            else if (shape is AutoShapeEx)
            {
                AutoShapeEx ashp = (AutoShapeEx)shape;
                if (ashp.AlternativeText == "Currency" && ashp.AlternativeText != "")
                {
                    TextFrameEx tf = ashp.TextFrame;

                    // string CurrencyText = rmBL.GetLiteral("txtInputPrice");

                    string CurrencyText = "txtInputPrice";
                    String Currency = "USD";

                    tf.Text = CurrencyText + Currency;
                    tf.Paragraphs[0].Portions[0].FontBold = Aspose.Slides.Pptx.NullableBool.True;
                    tf.Paragraphs[0].Portions[0].FontHeight = 10;
                    tf.Paragraphs[0].Portions[0].FillFormat.SolidFillColor.Color = System.Drawing.Color.Black;
                }
            }
        }
    }

    //Save the modified PPT
    output_file_name = fPPTPath + "\\12" + pptname;
    presnew.Write(output_file_name);
}

We are sorry for the delay and inconvenience that you might have experinced.