Adding Images in Template with Image Place Holder

When I create a slide master with two place holders for images, then go about adding the images, the image place holders are still there even though the images are added as fills. Is there a way to add the images to the placeholders more directly?

I am using Java code that looks like this:
/* //ImageEx */
pptxAutoShape1 = sl2Shapes.get(0);
pptxAutoShape2 = sl2Shapes.get(1);
//Set the fill type to Picture

/**/
pptxAutoShape1.getFillFormat().setFillType(fillType.PICTURE);
pptxAutoShape2.getFillFormat().setFillType(fillType.PICTURE);
//Set the picture fill mode
pptxAutoShape1.getFillFormat().getPictureFillFormat().setPictureFillMode(pictFillMode.STRETCH);
pptxAutoShape2.getFillFormat().getPictureFillFormat().setPictureFillMode(pictFillMode.STRETCH);
temp = pptxAutoShape1.getFillFormat().getPictureFillFormat();
temp2 = pptxAutoShape2.getFillFormat().getPictureFillFormat();
//Create a buffered image object
imgIO = CreateObject(“java”,“javax.imageio.ImageIO”);
//Set the picture
//BufferedImage
URLobj = CreateObject(“java”,“java.net.URL”).init("http://127.0.0.1:8500/presTemplate/Chart.jpg");
image = imgIO.read(URLobj);

pptxImage = pres.getImages().addImage(image);
pptxAutoShape1.getFillFormat().getPictureFillFormat().getPicture().setImage(pptxImage);
pptxAutoShape2.getFillFormat().getPictureFillFormat().getPicture().setImage(pptxImage);

The code is used with ColdFusion so it is a bit different than straight Java. The main question is about a way of attaching images to the place holders without them being fills.

Hi Keivn,


I have worked with the presentation file shared by you. Actually, the template picture frames shared by you are AutoShapeEx. I have used the following code snippet with the shared presentation and have been able to update the image. Please share if I may help you further in this regard. I would suggest that it will be better to add the picture frame instead of AutoShapeEx in layout slide.

String path=“C:/”;
//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pres = new PresentationEx(path+“template_image.pptx”);

//Get the first slide
SlideEx sld = pres.getSlides().get(1);

//Instantiate the ImageEx class
BufferedImage img= ImageIO.read(new File(“C:\Users\Public\Pictures\Sample Pictures\Desert.jpg”));
ImageEx imgx = pres.getImages().addImage(img);
ShapeEx shape;
for(int i=0;i<sld.getShapes ().size();i++)
{
shape=sld.getShapes ().get(i);
if(shape instanceof PictureFrameEx)
{
PictureFrameEx picFrame=(PictureFrameEx)shape;
picFrame.getPictureFormat().getPicture ().setImage(imgx);
}
else if (shape instanceof AutoShapeEx )
{
AutoShapeEx autoShape = (AutoShapeEx)shape;
autoShape.getFillFormat().setFillType(FillTypeEx.PICTURE);
autoShape.getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
}
}

//Write the PPTX file to disk
pres.write(path+“RectPicFrameJ.pptx”);

Thanks and Regards,

Mudassir,
I am working with you code and will send you an update on what I find. Although the shapes do show as AutoShapeEx even in coldfusion, when I added them to the templates they were image place holders. If you do a toString() on the place holder type you will see that it is of type picture.

Hi Keivn,


I agree with your point of view that Placeholder type is read as Picture but we are concerned with ShapeTypeEx when dealing with shape. The shape type is read as AutoShapeEx instead of picture frame and that is where I have shared the code snippet with you to add the image in auto shape rather. Please share, if I may help you further in this regard.

Many Thanks,

Mussadir,
Ok let me just keep my questions in order to know what I have to give to my superiors so they can choose to buy or not buy the product.

Is there a way to add the images to the placeholders more directly? The answer is NO

I understand this now that it is better to just create and add images and the autoshapes they are attached to dynamically, because you cannot set up image place holders to add images to, if you have created a template presentation to work with.

Ok so now I am working on embedding OLE objects. I have embedded a PDF, but it only shows up as a picture that says “OLE EMBEDDED OBJECT”. I see that if I do the same thing directly in powerpoint it does not work either, so that is really the wrong way for me to embed the PDF.

So the question is: How do I embed the PDF and display it as an icon for someone to click on and open the file, but the PDF should be embedded not linked.

This is the line of code I use to embed it:
OOF = sld.getShapes().addOleObjectFrame(0,0, DIM.getWidth(), DIM.getHeight(),“AcroPDF.PDF.1”, ByteBuffer);

This might be good for an image or something small but not the PDF file. So I want to embed it and just show an icon, so I can click the icon and open the file. I have attached two files.

Hi Keivn,

I have worked over the requirements shared by you. Your query consist of two parts so I will share my response separately for both accordingly.

caci2:

Mussadir,
Ok let me just keep my questions in order to know what I have to give to my superiors so they can choose to buy or not buy the product.

Is there a way to add the images to the placeholders more directly? The answer is NO

I understand this now that it is better to just create and add images and the autoshapes they are attached to dynamically, because you cannot set up image place holders to add images to, if you have created a template presentation to work with.

I have devised the work around for adding different shapes in placeholder. Now, you can add PictureFrame in placeholder as well using the sample code shared by me. You can use the given code and may tailor it for your requirement. I generated the presentation with placeholder of PictureFrame type and subsequently adding the images in picture placeholders of slide shapes. Alternatively, you can also use AutoShapes or directly add PictureFrame in presentation slides. Please also visit the link 1 and link 2 for your reference as well.

caci2:

Ok so now I am working on embedding OLE objects. I have embedded a PDF, but it only shows up as a picture that says “OLE EMBEDDED OBJECT”. I see that if I do the same thing directly in powerpoint it does not work either, so that is really the wrong way for me to embed the PDF.

So the question is: How do I embed the PDF and display it as an icon for someone to click on and open the file, but the PDF should be embedded not linked.

This is the line of code I use to embed it:

OOF = sld.getShapes().addOleObjectFrame(0,0, DIM.getWidth(), DIM.getHeight(),“AcroPDF.PDF.1”, ByteBuffer);

This might be good for an image or something small but not the PDF file. So I want to embed it and just show an icon, so I can click the icon and open the file. I have attached two files.

I like to share that the red image you are observing in generated presentation for Ole frame is actually default image of Ole frame in deactivated state and is not an issue with Aspose.Slides. Please visit this link for your reference. Once the Ole frame is activated that image is replaced by ole frame content. I also like to share that currently the requirement of attaching PDF file in presentation and then double clicking that to get that opened in PDF viewer is not available. However, the support for adding PDF as Ole frame is available. Whenever, the Ole frame will be double clicked the PDF will get opened in slide rather than PDF viewer. I have also shared the code snippet where I have set the image of Ole frame as PDF file. There is issue while opening the PDF Ole frame in PowerPoint and an issue wit ID SLIDESNET-33410 has been created in our issue tracking system to further investigate and resolve the issue.

I hope, I am able to clear the concept and limitation before you and the shared project code exhibits the so for possibilities that can be achieved through Aspose.Slides for .NET.

Many Thanks,

Mussadir,
This is very confusing. Either PDF works or it doesn’t, I’m not sure how there is a third option.

I have tried embedding a PDF and I have tried embedding an Excel sheet. I did them seperately but the code for trying each was similar:

OOF = sld.getShapes().addOleObjectFrame(0,0, 50, 50,“AcroPDF.PDF.1”, ByteBuffer);
OOF.setObjectProgId(“AcroPDF.PDF.1”);
OOF.setObjectIcon(true);

This doesnt work, I get the powerpoint error: the server application, source file, or item cannot be found, or returned an unknown error. You may need to reinstall the server application. This happens if I try to use an icon or just embed it. The same thing happens with excel.

OOF = sld.getShapes().addOleObjectFrame(100,250, 100, 200,“Excel.Sheet.12”, ByteBuffer);
OOF.setObjectProgId(“Excel.Sheet.12”);
OOF.setObjectIcon(true);

I tried using setProgramId(), I have tried the code from the examples I have found. I cannot get the file to open. I know that it is embedded, based on the original file size of the PPTX and XLSX or PDF.

I can embed but once embedded the file cannot be retrieved. I should say that if i open the PPTX manually embed the PDF or XLSX, it works just fine, but with the Aspose.Slides library it does not work. It may be something i am doing wrong but I have also taken the same iostream and wrote it to a file directly and it is fine ie: open xlsx, stream save.

Hi Keivn,


I like to suggest a small correction before you that my name is Mudassir instead of Mussadir. :slight_smile:

I also like to share that there is no third option. You can add the PDF as Ole frame in your presentation but presently there is some issue with adding PDF as Ole frame and that is why you are getting the issue. Yes, adding excel file as Ole frame is working fine as compared to PDF. That is why, I have created an issue with ID SLIDESNET-33410 to investigate and resolve this issue. I also like to share that the class name that is added while creating Ole frame depends on the type of file that you are trying to embed as Ole frame. On my end, the PDF that is added has class name, “AcroExch.Document.7”. If you are sure that the if the class name of the PDF file that you are trying to add on your end is, “AcroPDF.PDF.1”. Then you can persist with it. I will share the further information with you as soon as the issue will be investigate and scheduled for resolution by our development team.

Many Thanks,

Sorry Mudassir no offense was intended.

I will keep trying to see why I can’t seem to embed the file and get it to open (excel). Is there a list of the OLE class names somewhere.

Thanks

Mudassir

I wanted to include the code I wrote to embed the xlsx file. Just in case you see something missing which is causing the library to not work as advertised. I am not sure what else to try, I have tries setting the program id, not setting it, using it as an icon, not using it as an icon. As you can see there is a file embedded in the pptx but it does not open. Let me know if it opens for you. Thanks for checking into this, if I can’t get this to work this week, I can’t back the product and the company will not purchase it. It is a nice library but still needs some work. Thank again.


//Paths/////////////////////////////////////////////////////////////////////////////////
filePath = GetCurrentTemplatePath();
thisPath = ExpandPath(".");
cfserver = CGI.SERVER_NAME&":8500";
cfwebpath = ListDeleteAt(CGI.SCRIPT_NAME, ListLen(CGI.SCRIPT_NAME,"/"), “/”);
CFURL = “http://”&cfserver&cfwebpath;
//File Names////////////////////////////////////////////////////////////////////////////
demoPPTX = thisPath&“template.pptx”;
xlsxFile = thisPath&“test.xlsx”;
UfName = CreateUUID();
newpptfile = thisPath&UfName&".pptx";
newFile = thisPath&UfName&".xlsx";
//Java libs/////////////////////////////////////////////////////////////////////////////
imgIO = CreateObject(“java”,“javax.imageio.ImageIO”);
URLobj = CreateObject(“java”,“java.net.URL”).init(CFURL&"/Chart.jpg");
image = imgIO.read(URLobj);
//Java libs files///////////////////////////////////////////////////////////////////////
jFile = CreateObject(“java”,“java.io.File”).init(demoPPTX);
jPDFFile = CreateObject(“java”,“java.io.File”).init(xlsxFile);
jFileIOS = CreateObject(“java”,“java.io.FileInputStream”).init(jFile);
jPDFFileIOS = CreateObject(“java”,“java.io.FileInputStream”).init(jPDFFile); //IO Stream takes File
jNewFileOOS = CreateObject(“java”,“java.io.FileOutputStream”).init(newpptfile); //OO Stream makes new File
jNewFileOPS = CreateObject(“java”,“java.io.FileOutputStream”).init(newfile);
OPStream = CreateObject(“java”,“java.io.OutputStream”);
OPStream = jNewFileOPS;
length = jPDFFile.length();
ByteBuffer = RepeatString( “12345”, length ).GetBytes();
data = jPDFFileIOS.read(ByteBuffer, 0, JavaCast(“int”,length));
OPStream.write(ByteBuffer, 0, JavaCast(“int”,length));
//Create presentation////////////////////////////////////////////////////////////////////
pres = CreateObject(“java”,“com.aspose.slides.pptx.PresentationEx”).init(jFileIOS);
sld = pres.getSlides().get(2);
DX = pres.getSlideSize();
DIM = DX.getSize();
OOF = sld.getShapes().addOleObjectFrame(100,250, 100, 200,“Excel.Sheet.12”, ByteBuffer);
OOF.setObjectProgId(“Excel.Sheet.12”);
OOF.setObjectIcon(true);
OOF.setObjectData(ByteBuffer);

//Write PPTX to Disk
//
pres.write(jNewFileOOS);
jFileIOS.close();
jPDFFileIOS.close();
jNewFileOOS.close();
jNewFileOPS.close();


Hi Keivn,


I am sorry for the delayed response. I have observed the code shared by you and it seems you are using the cold fusion on your end. Unfortunately, I don’t posses the environment on my end presently to reproduce the issue. Can you please share the details about the cold fusion environment that you are using on your end. I have used Aspose.Slides for Java 2.9.2 on my end and worked over this example in JDK 1.6. The presentation generated is fine and has no issues. I suggest that you may please use the specified product version for your investigation. If there is still an issue then please share the complete Cold Fusion environment details on your end along with sample project. I will try to reproduce the same on my end. Hopefully, the issue will be resolved with use of specified version.

Many Thanks,

Mudassir,
I am using ColdFusion 9 which runs on java 1.6. I am using the Aspose Slides 2.91, that is what was available when i downloaded the library. The code I sent is using Java, you should see it, there are just some slight differences. I will try using the aspose 2.92 library

Mudassir,
It seems that it is a problem with the library trying to write XLSX files. It works with using xls file (97-2003) but not the newer XLSX files.

Also, is there any fix to the icon problem with the library. In other words, setting the image that says “Embedded OLE Frame” to show up as an icon, instead of that bad picture. Or is there a work around where I can attcah something that looks professional, for the customer to click on to open the excel file.

In other words, the image that is red text that says “OLE embedded Object” is not professional and a customer would consider that an error or problem. Is there anyway to show a nice image or icon instead of that picture.

After we purchase the library. Can I just make my own png image that isn’t the big red text and then recompile the JAR? I can make a nice File Icon and replace that png, then just remake the jar.

Hi Keivn,


I regret to share that unfortunately, I don’t possess the ColdFusion environment on my end. I am working over setting up environment for your convenience. As soon as I have the environment setup I will perform my verifications to help you out further. I will really appreciate your cooperation in this regard.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-33410) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

A post was split to a new topic: How to Add an Image to a Placeholder Using Aspose.Slides for Java?