Liinking an image into a PPTX file

Do any versions of your “Slides” or “Total” software support the linking of images into PPTX (PowerPoint 2007) files?

We are confused because Aspose.Total for .NET|Documentation does not list “PPTX” as a supported format.

If you do support this type of action on PPTX files, please tell me what version of the “Slides” or “Total” software for .NET that I need, and a hyperlink to the correct function/method in your documentation.


This message was posted using Aspose.Live 2 Forum

Hi Valery,

Thanks for your interest in Aspose.Slides.

We are very sorry for the inconvenience. The topic that you have just pointed from our online documentation of Aspose.Slides for .NET will be updated within few hours to include PowerPoint 2007 (PPTX) file format support. Actually, Aspose.Slides for .NET provides a separate set of classes packaged in Aspose.Slides.Pptx namespace. The API reference for this namespace can be found in Aspose.Slides for .NET online documentation here. The latest versions of Aspose.Slides for .NET support PowerPoint 2007 (PPTX) files.

I have prepared a sample code to create a PPTX presentation and add an image on its first slide.

byte[] buff = null;

FileStream fs = new FileStream("d:\\ppt\\neoteny\\result.png", FileMode.Open, FileAccess.Read);

BinaryReader br = new BinaryReader(fs);

long numBytes = new FileInfo("d:\\ppt\\neoteny\\result.png").Length;

buff = br.ReadBytes((int)numBytes);

MemoryStream st = new MemoryStream(buff);

System.Drawing.Image img;

img = System.Drawing.Bitmap.FromStream(st);

PresentationEx pres = new PresentationEx();

SlideEx sld = pres.Slides[0];

ImageEx img1 = pres.Images.AddImage(img);

sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 25, 25, 500, 500, img1);

pres.Write("d:\\ppt\\jan\\pres1.pptx");

Hope this will help you. In case of further inquiry / confusion, please feel free to share with us.

Best Regards

Hi,

Adding more to Sabir's comments, you can also use the following code snippet to insert an image as PictureFrame inside PPTX file.

[C# .NET]

//Read the source presentation which has a single blank slide
PresentationEx pres = new PresentationEx();

//Get the first slide which is Master slide added by default when Presentation object is created
SlideEx sld = pres.Slides[0];

//Read the image from disk
System.Drawing.Image img = Bitmap.FromFile(@"c:/test/Blue+hills.jpg");

//Add the image inside the presentation
//and save the extendend image object for later use
ImageEx imgEx = pres.Images.AddImage(img);

//Add the picture frame with extended image
sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 60, 70, 600, 400, imgEx);

//Write the presentation on disk
pres.Write(@"c:\\test\\PPTXwithImage_output.pptx");

You can also use PictureFrameEx class object to load the picture and add it to presentation slide. When using PictureFrameEx object, you can also add a linked image or import it from another pptx file. For that reason, Just create normal PictureFrameEx with null instead of image and set Url property for it's PictureEx object later on. Please have a look over the following code snippet.

[C# .NET]

//Read the source presentation which has a single blank slide
PresentationEx pres = new PresentationEx();

//Get the first slide which is Master slide added by default when Presentation object is created
SlideEx sld = pres.Slides[0];

int index = sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 60, 70, 600, 400, null);
PictureFrameEx picf = sld.Shapes[index] as PictureFrameEx;
picf.PictureFormat.Picture.Url = @"c:/test/Blue+hills.jpg";

//Write the presentation on disk
pres.Write(@"c:\\test\\PPTXwithImage_output.pptx");

The image file "Blue+hills.jpg" and resultant PPTX "PPTXwithImage_output.pptx" are also in attachment. I hope it can resolve your problem.

Hi, thank you for your quick answer. It’s work fine.
But I have another question.
I can add linked image into doc file, but I can’t add into docx file.

Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
wb.Open(textBoxDoc.Text);
//Get the first worksheet in the book
Aspose.Cells.Worksheet sheet = wb.Worksheets[wb.Worksheets.ActiveSheetIndex];
sheet.Shapes.AddLinkedPicture(4, 4, 100, 100, "http://www.aspose.com/Images/aspose-logo.jpg");

I tryed to use FileFormatType ff = FileFormatType.Excel2007Xlsx;
when I create wb, but it doesn’t work
Could you give me suggestion?

Hi Valery,

Thanks for your interest in Aspose.

Well, from the code snippet you posted, you need support regarding Aspose.Cells component. Therefore, your post is being moved to Aspose.Cells Support Forum so that you can get your required issue solved.

Thanks and Best Regards