We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to create presentaion back from stream

Hi Team,

Below is the code snippet used to create a ppt file and saved it into stream.

Presentation m_show = new Presentation();
ILayoutSlide layout = m_show.LayoutSlides.GetByType(SlideLayoutType.Blank);
m_show.Slides.Remove(m_show.Slides[0]);
ISlide slide = m_show.Slides.AddEmptySlide(layout);
double[] width = {1000.0};
double[] height = {10.0};
ITable pptTable = slide.Shapes.AddTable(100f,100f,width,height);
ICell pptCell = pptTable[0,0];
string tempString = "some text";
ITextFrame frame = pptCell.TextFrame;
Aspose.Slides.Paragraph graph = new Aspose.Slides.Paragraph();
frame.Paragraphs.Add(graph);
Portion portion = new Portion(tempString);
portion.PortionFormat.FontHeight = (short)12;
FontData fontData = new FontData("Arial");
portion.PortionFormat.LatinFont = fontData;
graph.Portions.Add(portion);
MemoryStream stream = new MemoryStream();
m_show.Save(stream, Aspose.Slides.Export.SaveFormat.Ppt);

Now while trying to get the presentation back from the stream, then receiving error like " Unable to de-serialize input stream "

try
{
Presentation source = null;
//Deserialize presentation from a stream
source = new Presentation(stream);
}
catch(Exception ex)
{
throw;
}

Can you please tell us why presentation class is not able to deserialize the input stream though the stream contains valid content.Also kindly let us know if there is any other way to achieve the same.

Thanks,
Divya

Hi Divya,

I have observed the issue shared by you. Can you please try using following code snippet before loading the presentation from stream on second iteration.

stream.Position=0;


Many Thanks,

Hi Mudassir,

I tried the given snippet and it worked.The presentation was created succesfully. However the text that I wrote in ppt file is not present.

But the same text was present in ppt file when i tried the below code

m_show.Save(@"C:/temp/test_file.ppt", Aspose.Slides.Export.SaveFormat.Ppt);

instead of

m_show.Save(stream, Aspose.Slides.Export.SaveFormat.Ppt); and get the presentation from stream.

Attaching the output files for reference.

Thanks,
Divya

Hi Divya,

I have worked with the sample code shared and have created the sample presentation using Aspose.Slides for .NET 14.4.0. I have not been able to observe the issue of missing text in generated presentation. For your kind reference, the used sample code is attached along with generated presentation.

public static void TestStream()
{
Presentation m_show = new Presentation();
ILayoutSlide layout = m_show.LayoutSlides.GetByType(SlideLayoutType.Blank);
m_show.Slides.Remove(m_show.Slides[0]);
ISlide slide = m_show.Slides.AddEmptySlide(layout);
double[] width = { 1000.0 };
double[] height = { 10.0 };
ITable pptTable = slide.Shapes.AddTable(100f, 100f, width, height);
ICell pptCell = pptTable[0, 0];
string tempString = “some text”;
ITextFrame frame = pptCell.TextFrame;
Aspose.Slides.Paragraph graph = new Aspose.Slides.Paragraph();
frame.Paragraphs.Add(graph);
Portion portion = new Portion(tempString);
portion.PortionFormat.FontHeight = (short)12;
FontData fontData = new FontData(“Arial”);
portion.PortionFormat.LatinFont = fontData;
graph.Portions.Add(portion);

MemoryStream stream = new MemoryStream();


m_show.Save(stream, Aspose.Slides.Export.SaveFormat.Ppt);

stream.Position = 0;

FileStream fileStream = File.Create(“D:\Aspose Data\StreamCreated.ppt”, (int)stream.Length);
// Initialize the bytes array with the stream length and then fill it with data
byte[] bytesInStream = new byte[stream.Length];
stream.Read(bytesInStream, 0, bytesInStream.Length);
// Use write method to write to the file specified above
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
fileStream.Close();
m_show.Save(“D:\Aspose Data\StreamCreated2.ppt”, Aspose.Slides.Export.SaveFormat.Ppt);

}


I hope the shared information will be helpful.

Many Thanks,

Hi Mudassir,

Here the issue is with below code:

public static void TestStream()
{
Presentation m_show = new Presentation();
ILayoutSlide layout = m_show.LayoutSlides.GetByType(SlideLayoutType.Blank);
m_show.Slides.Remove(m_show.Slides[0]);
ISlide slide = m_show.Slides.AddEmptySlide(layout);
double[] width = { 1000.0 };
double[] height = { 10.0 };
ITable pptTable = slide.Shapes.AddTable(100f, 100f, width, height);
ICell pptCell = pptTable[0, 0];
string tempString = "some text";
ITextFrame frame = pptCell.TextFrame;
Aspose.Slides.Paragraph graph = new Aspose.Slides.Paragraph();
frame.Paragraphs.Add(graph);
Portion portion = new Portion(tempString);
portion.PortionFormat.FontHeight = (short)12;
FontData fontData = new FontData("Arial");
portion.PortionFormat.LatinFont = fontData;
graph.Portions.Add(portion);

MemoryStream stream = new MemoryStream();


m_show.Save(stream, Aspose.Slides.Export.SaveFormat.Ppt);//saved to stream

stream.Position = 0;
Presentation source = = new Presentation(stream); // getting back the presentation from stream
and stored the content in presentation to @C:\UploadDir\test_stream.ppt file

}

After retrieving the presentation back from stream there is empty slide but no content in test_stream.ppt. Whereas with below snippet:

public static void TestStream()
{
Presentation m_show = new Presentation();
ILayoutSlide layout = m_show.LayoutSlides.GetByType(SlideLayoutType.Blank);
m_show.Slides.Remove(m_show.Slides[0]);
ISlide slide = m_show.Slides.AddEmptySlide(layout);
double[] width = { 1000.0 };
double[] height = { 10.0 };
ITable pptTable = slide.Shapes.AddTable(100f, 100f, width, height);
ICell pptCell = pptTable[0, 0];
string tempString = "some text";
ITextFrame frame = pptCell.TextFrame;
Aspose.Slides.Paragraph graph = new Aspose.Slides.Paragraph();
frame.Paragraphs.Add(graph);
Portion portion = new Portion(tempString);
portion.PortionFormat.FontHeight = (short)12;
FontData fontData = new FontData("Arial");
portion.PortionFormat.LatinFont = fontData;
graph.Portions.Add(portion);

MemoryStream stream = new MemoryStream();


m_show.Save((@"C:/temp/test_file.ppt", Aspose.Slides.Export.SaveFormat.Ppt); // content written to test_file.pt
}
we observed that the text content was available in test_file.ppt. But its unsure why when recreating the presentation from stream displays an empty slide into which content was written correctly. Kindly provide your help.

Thanks,
Divya

Hi Divya,

I have worked with the following sample code shared by you using Aspose.Slides for .NET 14.4.0 on my end. I am getting the proper presentation. For your kind reference the generated presentation is also attached. Can you please make sure that you are use the specified version on your end.

public static void TestStream2()
{
Presentation m_show = new Presentation();
ILayoutSlide layout = m_show.LayoutSlides.GetByType(SlideLayoutType.Blank);
m_show.Slides.Remove(m_show.Slides[0]);
ISlide slide = m_show.Slides.AddEmptySlide(layout);
double[] width = { 1000.0 };
double[] height = { 10.0 };
ITable pptTable = slide.Shapes.AddTable(100f, 100f, width, height);
ICell pptCell = pptTable[0, 0];
string tempString = “some text”;
ITextFrame frame = pptCell.TextFrame;
Aspose.Slides.Paragraph graph = new Aspose.Slides.Paragraph();
frame.Paragraphs.Add(graph);
Portion portion = new Portion(tempString);
portion.PortionFormat.FontHeight = (short)12;
FontData fontData = new FontData(“Arial”);
portion.PortionFormat.LatinFont = fontData;
graph.Portions.Add(portion);

MemoryStream stream = new MemoryStream();


m_show.Save(stream, Aspose.Slides.Export.SaveFormat.Ppt);//saved to stream

stream.Position = 0;
Presentation source = new Presentation(stream); // getting back the presentation from stream
source.Save(@“D:\Aspose Data\test_stream.ppt”,SaveFormat.Ppt);
}


Many Thanks,

Hi Mudassir,

Below are the .Net Versions in which the application is running:

  • Microsoft Visual Studio 2008 V9.0.30729.1
  • Microsoft .Net Framework V3.5 SP1.

With the provided code , I'm getting the empty content in the file saved in local disk after deserializing the stream to presentation.Whereas before deserializing the content was present in the stream and saved file.

Attaching the used solution and output.

Thanks,
Divya

Hi Divya,

Thanks for sharing the sample project. I have used the project as it is and have been able to reproduce the issue. I have seen that you are using Aspose.Slides for .NET 14.2.0 on your. However, when I used Aspose.Slides for .NET 14.4.0 on my with your sample project there is no issue. For your kind reference, I have attached the generated presentations. As suggested earlier, please try using Aspose.Slides for .NET 14.4.0 on your end and share with us if there is any issue incurring.

Many Thanks,

Hi Mudassir,

I tried the same code snippet with Aspose Slides .Net 14.4.0 dll and was able to get the presentation successful. Thanks for the help offered.

Thanks,
Divya