How to show a slide thumbnail on an aspx page

Hi,

I've been trying to put a thumbnail of a slide on an aspx page. I have seen examples of creating the bitmap with getthumbnail and putting it out to a response stream. I did this using a second aspx page, but the aspx page does not seem to work (or even run). Is there a sample somewhere that shows the best way to do this?

I made but the aspx page does not seem to run (traces in the Load do not show up when debugging).

Thanks.

Hi Brad,

Thanks for considering Aspose.Slides.

Please use the code snippet given below for generating a slide thumbnail and presenting that on .aspx page using response stream.

//Reading presentation file and its first slide
Presentation pres = new Presentation("D://ppt//Temp.ppt");
Slide slide = pres.Slides[0];

//Getting Thumbnail
System.Drawing.Image image = slide.GetThumbnail(1f, 1f);

//Initializing Memory Stream
MemoryStream ImageMs = new MemoryStream();

//Saving image to memory stream
image.Save(ImageMs, System.Drawing.Imaging.ImageFormat.Jpeg);
ImageMs.Position = 0;

//Intializing buffer
byte[] pBuffer;//=new byte[ms.Length];
pBuffer = new byte[(int)ms.Length];

//Memory stream to buffer
ImageMs.Read(pBuffer, 0, (int)ImageMs.Length);

Response.Clear();

//set response content type: image/jpeg, image/gif, image/png, etc…
Response.ContentType = "image/jpeg";

//write the image to the output stream
Response.OutputStream.Write(pBuffer, 0, pBuffer.Length);
Response.End();

Please use the following configuration on your webpage. For reference the output image is also attached.

<%@ Page Language=“C#” AutoEventWireup=“true” CodeFile=“Default2.aspx.cs” Inherits=“Default2” %>

Thanks and Regards,

Hi Mudassir,

Thanks for your response. I converted it to VB and ran it. It did not work, but I think the problem is not in the code itself but in the way I have it wired up.

I have put an asp.Image control on one page and created a link to an aspx page which holds the code that you sent. I trigger the code on the Page_Load event of that aspx page. I put trace statements in both the Init and Load events and they do not print. The img gets built as:

<img id="ctl00_cphPages_dlFound_ctl00_imgPPTx" src="Popups/PPTxImage.aspx" ...

I have turned AutoEventWireup back off as that did not seem to make a difference. The PPTxImage.aspx page is just a shell (which gets created when you use VS to create a new page) with and empty form and the Page_Load event.

Can you tell if there is something wrong in the way I have this wired up?

Thanks

Hi Brad,

Please use the code snippet given below for generating a slide thumbnail and presenting that on .aspx page using response stream. I have converted my code to support VB.NET and it executes successfully. For reference the output image is also attached. Hopefully, things will work for you this time.

'Instantiate a Presentation object that represents a PPT file
Dim pres As Presentation = New Aspose.Slides.Presentation("D://ppt//ImageSlideA.ppt")

'Accessing a slide using its slide position
Dim slide As Aspose.Slides.Slide = pres.GetSlideByPosition(1)

'Getting the thumbnail image of the slide of a specified size
Dim image As Image = slide.GetThumbnail(1.0F, 1.0F)

'Saving the thumbnail image in jpeg format
'Initializing Memory Stream
Dim ImageMs As MemoryStream = New MemoryStream()

'Saving image to memory stream
image.Save(ImageMs, System.Drawing.Imaging.ImageFormat.Jpeg)
ImageMs.Position = 0

'Intializing buffer
Dim pBuffer(ImageMs.Length) As Byte

'Memory stream to buffer
ImageMs.Read(pBuffer, 0, ImageMs.Length)

Response.Clear()

'set response content type: image/jpeg, image/gif, image/png, etc…
Response.ContentType = “image/jpeg”

'write the image to the output stream
Response.OutputStream.Write(pBuffer, 0, pBuffer.Length)
Response.End()

The following settings have been made in aspx page.

<%@ Page Language=“VB” AutoEventWireup=“false” CodeFile=“Default.aspx.vb” Inherits="_Default" %>

Thanks and Regards,

Mudassir,

Thanks for the reply and the translation. That matched what I had in the aspx file, but was still not working. I decided to put the whole thing in a simple site with a single fixed pptx to display. It worked fine (I had suspected in my last post that there was something wrong in the way it was connected).

I then put it in my main site with a fixed pptx; that worked. Eventually I worked all the way back to setting the img src to:

"PPTxImage.aspx?File=" + sPath + "&Width=160"

to display a random pptx in the image. It worked!

I don't know what I had done wrong, but it is now wired up correctly and working. As others have noted on this forum, the thumbnail is not clean, but it is good enough for our application.

Thanks again.