PPTX file corrupted after save (doc saved as PDF and should be PPTX)

Hi Aspose team,

I am opening document (ole.pptx) which is attached with a project, loop through hyperlinks and then save document after reading SourceFormat. Nothing is changed in document.
In debug I see that doc.SourceFormat = PPtx{1}

When I try to open newly created document I am getting message that document is corrupted.

Further debugging I see that doc.Save(“output.pptx”, exportFormat) shows that exportFormat is Pdf {1}???

Of course, document is saved as PDF.

Can you please check why is this changed?

Coding is simple:

Dim exportFormat As Export.SaveFormat
exportFormat = doc.SourceFormat
If chkSave.Checked Then
    doc.Save("output.pptx", exportFormat)
End If

Thanks,
Oliver

Hi,

can you please move this topic to Aspose.Slides, this is wrong forum :(.

Thx,
Oliver

Hi Oliver,

Sorry for a bit delayed response. We have now moved this thread to appropriate forums, that is; Aspose.Slides support forum.

Hi Oliver,

I have replied to your same query in Aspose.Slides forum, over this thread created by you. Please follow up in the respective thread.

Best Regards,

Hi Adnan,

can you please process this post?
Here is different problem described (see code provided in first post).

Ticket that you referenced is for more URL’s then really in the document.

Thanks,
Oliver

Hi Oliver,

Thank you for getting back to us.

I have observed your comments and like to share with you that I am unable to download the attachments shared by you in your first post. Please upload it once again so that I may proceed further to help you out.

Best Regards,

Hi,

file attached again.

Btw. it is not about file but about coding:

Dim exportFormat As Export.SaveFormat
exportFormat = doc.SourceFormat
If chkSave.Checked Then
    doc.Save("output.pptx", exportFormat)
End If

I open PPTX document and read doc.SourceFormat which is reporting PPTX but later in line doc.save(…,…) exportFormat is replaced with PDF.

BR,
Oliver

Hi Oliver,

I have observed the sample project shared b you. There is an issue of understanding and wrong enumerations used in presentation. When you using Presentation.SourceFormat , it will return presentation format using Enumeration SourceFormat . Where as when you are saving presentation, Aspose.Slides use SaveFormat enumeration. You are trying to assign the numeric value of SourceFormat enumeration to SaveFormat enumeration, which is wrong and cause of issue. Please use correct enumerators on your end to serve the purpose.

Many Thanks,

Hi Mudassir,

my idea was to read document format (SourceFormat) and later to use it during saving changes.

We are enforced to provide SaveFormat when saving Powerpoint document so it make sense that we read SourceFormat and use it later to save the document.

It make sense that enumeration in both cases is the same and all additional SaveFormats to come at the end of list.

Now with differences I’ll need to write case structure which will “convert” SourceFormat to SaveFormat or you have any other tip?

Thanks,

Oliver

Hi Oliver,

I have observed your requirements and like to request you to please try using following sample code on your end to serve the purpose. This code ensures that if you read a pptx file then that file could only be saved as pptx and if source file is a ppt file then it is saved as ppt file.

Presentation pres = new Presentation(@"D:\chart.pptx");

IPresentationInfo info;
info = PresentationFactory.Instance.GetPresentationInfo(@"D:\chart.pptx");

switch (info.LoadFormat)
{
    case LoadFormat.Pptx:
        {
            pres.Save(@"D:\test.pptx", SaveFormat.Pptx);
            break;
        }
    case LoadFormat.Ppt:
        {
            pres.Save(@"D:\test.ppt", SaveFormat.Ppt);
            break;
        }
    case LoadFormat.Unknown:
        {
            break;
        }
}

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi Adnan,

yes this is an option but check this code:

Dim extension As String
extension = System.IO.Path.GetExtension(path)

Dim exportFormat As Export.SaveFormat = Export.SaveFormat.Pptx

Select Case LCase(extension)
    Case “.potm” : exportFormat = Export.SaveFormat.Potm
    Case “.potx” : exportFormat = Export.SaveFormat.Potx
    Case “.pps” : exportFormat = Export.SaveFormat.Pps
    Case “.ppsm” : exportFormat = Export.SaveFormat.Ppsm
    Case “.ppsx” : exportFormat = Export.SaveFormat.Ppsx
    Case “.ppt” : exportFormat = Export.SaveFormat.Ppt
    Case “.pptm” : exportFormat = Export.SaveFormat.Pptm
    Case “.pptx” : exportFormat = Export.SaveFormat.Pptx
End Select

'document.Save(path, exportFormat)
document.Save(path, exportFormat)

It does not work in case of Case “.ppt” : exportFormat = Export.SaveFormat.Ppt as when I try to save document by using exportFormat variable due to same enum number document is saved as a PPS.

This looks to me as a bug in enumeration. Is there any particular reason to setup enum in a way how it is done?

Thx,
Oliver

Hi Oliver,

I have observed your comments and the code shared by you. I have replied you regarding this issue in this thread. However, to deal with this problem for now, you may try using the code sample shared by me earlier, over here or the code sample shared below.

Dim pres As New Presentation("D:\chart.pptx")
Dim fi As New FileInfo("D:\chart.pptx")

Select Case fi.Extension.ToLower()
    Case ".ppt"
        If True Then
            pres.Save("D:\test.ppt", SaveFormat.Ppt)
            Exit Select
        End If
    Case ".pptx"
        If True Then
            pres.Save("D:\test.pptx", SaveFormat.Pptx)
            Exit Select
        End If
End Select

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi,

I adjusted my code so this ticket can be closed.

BR,
Oliver

Hi Oliver,

We are glad to know that things have started working on your end.

Please feel free to contact us if we could be of any help to you.

Best Regards,