Aspose.Slides.UnsupportedFormatException was unhandled - Message=Unknown file format

Hi

I am converting a powerpoint presentation to PDF and I get the following error.

Aspose.Slides.UnsupportedFormatException was unhandled
Message=Unknown file format.
Source=Aspose.Slides
StackTrace:
at ..()
at .…ctor(Stream inStream)
at ..a()
at ..()
at .…ctor(Stream inStream)
at ..(Stream inputStream)
at .…ctor(Stream inputStream)
at Aspose.Slides.Pptx.PresentationEx.(Stream inputStream)
at Aspose.Slides.Pptx.PresentationEx.a(Stream stream)
at Aspose.Slides.Pptx.PresentationEx.(Stream stream, LoadOptions loadOptions)
at Aspose.Slides.Pptx.PresentationEx…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Slides.Pptx.PresentationEx…ctor(Stream stream)
at ConsoleNetwork.Program.CreatePresentationPdf(MailMessage newMsg, MemoryStream att, MemoryStream pdfStream) in D:\source\PdfConverter\ConsoleNetwork\Program.cs:line 216
at ConsoleNetwork.Program.Main(String[] args) in D:\source\PdfConverter\ConsoleNetwork\Program.cs:line 133
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

This happens when I unpack a zip file and try to convert the MemoryStream to PresentationEx. When I try to convert a word or excel file to a pdf that is in the same or different zip files it works fine.

PresentationEx pres = new PresentationEx(att);

It works fine when it is an mail attachement being converted to PresentationEx.

I checked the bytes and they are the same when it converts a mail attachment and when it is a Memory stream from a zip file.

Ive attached screen grabs from the mail attachment conversion and the MemoryStream conversion.






Hi Joe,


I have investigated the stack trace shared. It will be really appreciable if you may please share the source presentation with us for further investigation.

Thanks and Regards,

I found out what the problem was. I had to set the Content stream at 0. i.e. I had to add the line that is in bold below.

private static void CreatePresentationPdf(MailMessage newMsg, Stream contentStream, string filename)
{

MemoryStream pdfStream1 = new MemoryStream();
contentStream.Seek(0, SeekOrigin.Begin);
PresentationEx pres = new PresentationEx(contentStream);
pres.Save(pdfStream1, Aspose.Slides.Export.SaveFormat.Pdf);
Attachment slideAttachment = new Attachment(pdfStream1, ExtractfileName(filename), “application/vnd.ms-powerpoint”);
newMsg.AddAttachment(slideAttachment);

}

Hi Joe,


That is really nice that you have been able to figure out the issue. Please share, if I may help you further.

Many Thanks,