Is code is there a method with adds a picture to a newly created slide similiar to the presentations AddPicture method in the Powerpoint PIA COM controls? What I'm trying to do is create a new presentation and add an existing picture to it..
Thanks
Is code is there a method with adds a picture to a newly created slide similiar to the presentations AddPicture method in the Powerpoint PIA COM controls? What I'm trying to do is create a new presentation and add an existing picture to it..
Thanks
Hi,
Here is the sample code for adding a picture to the slide:
Presentation pres = new Presentation();
Slide sld = pres.GetSlideByPosition(1);
Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, "dsc.jpg");
int picid = pres.Pictures.Add(pic);
int pictureWidth = Convert.ToInt32((float)pres.Pictures.GetPictureById(picid).Image.Width);
int pictureHeight = Convert.ToInt32((float)pres.Pictures.GetPictureById(picid).Image.Height);
sld.Shapes.AddPictureFrame(picid, pictureWidth / 2, pictureHeight / 2, pictureWidth, pictureHeight);
pres.Write("dscPres.ppt");
Thanks for the snippet.
I applied this code(converting it to VB) and it appeared to run just fine. However after I had saved it after being prompted to save, I opened the presentation and there was an empty presentaion asking me to , "Click to Add first slide". I was expecting a blank slide with the picture that I've saved in a specified directory inserted into the slide.
'Instantiate a Presentation object that represents a PPT file
Dim pictureFileName As String = sessionAdapter.pptImage
Dim pres As Presentation = New Presentation()
Dim sld As Slide = pres.GetSlideByPosition(1)
Dim pic As Aspose.Slides.Picture = New Aspose.Slides.Picture(pres, pictureFileName)
Dim picid As Integer = pres.Pictures.Add(pic)
GetScreenshopBrowserImageDim()
Dim pictureWidth As Integer = _WebsitesScreenshot.ImageWidth
Dim pictureHeight As Integer = _WebsitesScreenshot.ImageHeight
sld.Shapes.AddPictureFrame(picid, pictureWidth, pictureHeight, pictureWidth, pictureHeight)
Try
'Setting the content type of the Http Response
Me.Response.ContentType = "application/vnd.ms-powerpoint"
Me.Response.AppendHeader("Content-Disposition", "attachment;filename=presentation.ppt")
'Flushing the buffers of Http Response
Me.Response.Flush()
'Accessing the output stream of Http Response
Dim st As System.IO.Stream = Me.Response.OutputStream
'Saving the presentation to the output stream of Http Response
pres.Write(st)
'Closing the Http Response
Me.Response.Close()
Catch Err As Exception
Throw Err
End Try
Hi,
I can't understand what is the problem on your end. Attached is the presentation that has been created as a result of the following code in VB (I used Aspose.Slides for .NET 4.1.0 on .NET Framework 3.5).
Dim pres As Presentation = New Presentation()
Dim sld As Slide = pres.GetSlideByPosition(1)
Dim pic As Aspose.Slides.Picture = New Aspose.Slides.Picture(pres, "d:\\ppt\\arun\\dsc.jpg")
Dim picid As Integer = pres.Pictures.Add(pic)
Dim pictureWidth As Integer = pres.Pictures.GetPictureById(picid).Image.Width
Dim pictureHeight As Integer = pres.Pictures.GetPictureById(picid).Image.Height
sld.Shapes.AddPictureFrame(picid, pictureWidth / 2, pictureHeight / 2, pictureWidth, pictureHeight)
'....do some work here.....
Try
'Setting the content type of the Http Response
Me.Response.ContentType = "application/vnd.ms-powerpoint"
'Appending the header of the Http Response to contain the presentation file name
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=demo2.ppt")
'Flushing the buffers of Http Response
Me.Response.Flush()
'Accessing the output stream of Http Response
Dim st As System.IO.Stream = Me.Response.OutputStream
'Saving the presentation to the output stream of Http Response
pres.Write(st)
'Closing the Http Response
'Me.Response.End()
Catch Err As Exception
Throw Err
End Try
After comparing your code with mine. I commented out the line
'Me.Response.Close()
It ran fine after that the only thing now is setting the page orientation snd sizing the image.
I would like to position the pic and resized it. I thought using the same size as th image would do the trick. In the code that's what I'm assigning the height and width values. It appears as though there may be different units used as far as width and height parameters(i.e pixels vs some other unit). Looking at properties of the picframe and pic objects.
I looking throught he object properties trying to find a property that sets page orientation but haven't as of yet.
Hi,
In case of PPT (PowerPoint 2003 format), Aspose.Slides component has measurement unit for x-axis, y-axis, height and width as (pixel size) * 8.
Ok, Thanks. Is there a way to change slide orientation from landscape to portrait?
Hi,
In case of PPTX documents, Aspose.Slides for .NET provide SlideSizeEx.Orientation property to change the slide orientation from Landscape to Portrait or Portrait to Landscape. In case of PPT, an issue has been created with issue id 13264 to provide the same feature. This thread has been associated with this issue, so you will be informed as soon as it is implemented.
As a work around, you can use the following approach to change the orientation.
Presentation pres = new Presentation("hello.ppt");
Size szNew = new Size();
Size szOLD = pres.SlideSize;
szNew.Width = szOLD.Height;
szNew.Height = szOLD.Width;
pres.SlideSize = szNew;
pres.Write("hello1.ppt");