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
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.
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.
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?
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.
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?
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.