Free Support Forum - aspose.com

Adding a slide to a powerpoint template

I am trying to add an image (.png) to a prexisting powerpoint template.

this is the code that i'm using:

I keep getting an error on the last line.

---------------------------------------------------------------------------

string CustomerPowerPointPath = HttpContext.Current.Server.MapPath("~") + "\\Templates\\" + "PlanningTemplate.ppt";

string CustomerSnapShotPath = HttpContext.Current.Server.MapPath("~") + "\\Templates\\" + "test.png";

// create powerpoint object

Presentation objPresentation = new Presentation(CustomerPowerPointPath);

Picture objPicture = new Picture(objPresentation, CustomerSnapShotPath);

int count = objPresentation.Pictures.Count;

int objPictureID = objPresentation.Pictures.Add(objPicture);

count = objPresentation.Pictures.Count;

int pictureWidth = objPresentation.Pictures[count-1].Image.Width;

int pictureHeight = objPresentation.Pictures[count-1].Image.Height;

Slide objSlide = objPresentation.GetSlideByPosition(10);

int slideWidth = objSlide.Background.Width;

int slideHeight = objSlide.Background.Height;

int pictureFrameWidth = Convert.ToInt32(slideWidth/2 - pictureWidth/2);

int pictureFrameHeight = Convert.ToInt32(slideHeight/2 - pictureHeight/2);

PictureFrame objPictureFrame = objSlide.Shapes.AddPictureFrame(objPictureID, pictureFrameWidth, pictureFrameHeight, pictureWidth, pictureHeight);

HttpContext.Current.Response.ContentType = "application/vnd.ms-powerpoint";

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=demo.ppt");

HttpContext.Current.Response.Flush();

System.IO.Stream objStream = HttpContext.Current.Response.OutputStream;

objPresentation.Write(objStream);

HttpContext.Current.Response.End();

Probably Response.Flush() will be enough in your case.

this doesn't seem to work.

am i using the right code? can you please send me a small snippet that i can use to insert an image to an existing powerpoint presentation?

Try it without response stream. Just save it to disk and check result.

Presentation objPresentation = new Presentation(“PlanningTemplate.ppt”);
Picture objPicture = new Picture(objPresentation, “test.png”);

int objPictureID = objPresentation.Pictures.Add(objPicture);
int pictureWidth = objPicture.Image.Width;
int pictureHeight = objPicture.Image.Height;

Slide objSlide = objPresentation.GetSlideByPosition(1);
PictureFrame objPictureFrame =
objSlide.Shapes.AddPictureFrame(objPictureID, 500, 500, pictureWidth * 8, pictureHeight * 8);
objPresentation.Write(“result.ppt”);

this still doesn't seem to work.

can i please to talk to you or someone on your support team by phone? i am on a tight deadline and I cannot wait a hour or two between each response. I tried calling the support number, but I was unable to reach anyone. can you please leave a direct number at richardtirado.com.

I purchased a licensed copy of your product and would appreciate a prompt response.

thank you

i’m sorry that was richardtirado@hotmail.com

Could you explain what you mean “doesn’t seem to work” ? What result you have? Exception?
Did you try to save presentation and open it with MS PowerPoint?

Check LiveSupport: http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactTyumen.html
I will be available next 2 hours.

I need to add an image to a new slide in an existing powerpoint template.

Can i use this code in a business object? (test.cs)

// create powerpoint object

Presentation objPresentation = new Presentation(CustomerPowerPointPath);

Slide objSlide = objPresentation.AddEmptySlide();

Picture objPicture = new Picture(objPresentation, CustomerSnapShotPath);

int objPictureID = objPresentation.Pictures.Add(objPicture);

int pictureWidth = objPicture.Image.Width;

int pictureHeight = objPicture.Image.Height;

PictureFrame objPictureFrame = objSlide.Shapes.AddPictureFrame(objPictureID, 500, 500, pictureWidth * 8, pictureHeight * 8);

HttpContext.Current.Response.ContentType = "application/vnd.ms-powerpoint";

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=PlanningTemplate.ppt");

HttpContext.Current.Response.Flush();

System.IO.Stream objStream = HttpContext.Current.Response.OutputStream;

objPresentation.Write(objStream);

Yes, you can. But don’t forget to set corect position and size of PictureFrame.

I keep getting access denied when using the component.

here is more detailed version of the error.

Access is denied: 'Aspose.Slides'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Access is denied: 'Aspose.Slides'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Aspose.Slides' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Aspose.Slides, Version=2.4.5.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/My Documents/CVS Workspace/RyanMarketingManager
LOG: Initial PrivatePath = bin
Calling assembly : Campbells, Version=1.0.2287.20382, Culture=neutral, PublicKeyToken=null.
===

LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/campbells/52bdf800/6c9d2b9d/Aspose.Slides.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/campbells/52bdf800/6c9d2b9d/Aspose.Slides/Aspose.Slides.DLL.
LOG: Attempting download of new URL file:///C:/Documents and Settings/Administrator/My Documents/CVS Workspace/RyanMarketingManager/bin/Aspose.Slides.DLL.


Stack Trace:

[FileLoadException: Access is denied: 'Aspose.Slides'.]
   Campbells.Planner.CustomerPlanner.Page_Load(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

In such cases google suggest granting ASP.NET account full access to Aspose.Slides.dll.
Another possible solution is delete everything in VSWebCache and rebuild you app.