Creating a pptx file using aspose slides and php/java bridge

Hello

I have been trying to create a powerpoint using php/Java bridge.

So far I have been able to create a empty presentation but unable to create a slide in it.

Any docs or suggestions is really helpfull.

Hi Anup,

Aspose.Slides offer you to add slides of any layout in a presentation. Please visit this documentation link to serve the purpose on your end.

Many Thanks,

I dont know java but i am good at php.
So i was using php/java bridge and i did not find any document for creating a presentation from scratch.

Hi Anup,


I have shared the guideline file with you that will help in developing wrapper for PHP using Aspose.Slides for Java. I have also added a sample example for your kind reference in this regard.

Many Thanks,

I am able to create pptx file but i am getting repair error while opening the file.

I am using PowerPoint 2010

Its working now by changing the save format from 2 to 3.

Thanks a lot for the help.

Hi Anup,

That is good to know that things are working on your end. Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,

After pptx creation i have been working on many thing but im facing issue in finding a specific text in slide and replacing it.

Im able to replace all text in slide with same value.

I want to check the variable and replace accordingly.
Here is my code
$slide1 = $ppt->getSlides()->get_Item(0);

$count = $slide1->getShapes()->size();

for ($i=0;$i<=$count;$i++){

$shp = $slide1->getShapes()->get_Item($i);
//Check if shape holds a textholder
if ($shp->getPlaceholder() != null && $shp->isTextHolder() == true){
$shp->getTextFrame()->setText($Name);
}
}

If you have any idea Please share.

Thanks

Hi Anup,


I have observed the requirement shared by you and like to share that I can only help you in perspective of Aspose.Slides for Java for required feature and you need to build your own wrapper in this regard to port that sample to PHP to serve the purpose on your end by following the guideline document shared by me.

Aspose.Slides offers the feature of finding shapes by using Alternative Text property, you set the name for target shape in slide using PowerPoint. You then find that shape using Aspose.Slides and then you can set or reset the text for that shape as per your convenience. I request you to please visit the following links for your kind reference.


Many Thanks,

Hi there,


What if I just want to replace all occurences of the word “BOOT” with the word “SHOE” throughout the presentation, not knowing how it is structured.

How would i do that best / smartest?

Thank you!

Hi Anup,

I have observed your requirement. In order to achieve your goal, you actually will be needed to traverse through every slide text frame in presentation and look for the desired text. Once your find the text, you can replace that with your string. You need to visit this article and port to PHP on your end. The article is about extracting the text from every text frame inside presentation slide. You can refer this and in the end only make comparison of your desired string and make the replacement.

Many Thanks,

Hi Mudaassir,

Thank you for the link you posted to fetch all textframes from presentation.

But i am unable to fetch text. Here is my code

$pptx = new Java(“com.aspose.slides.Presentation”,getcwd()."/Master template PPT dk.pptx");

$slideUtils = new Java(“com.aspose.slides.SlideUtil”);

$textFramesPPTX = $slideUtils->getAllTextFrames($pptx, true);

try{
$totalSlides = count($textFramesPPTX,1);

for ($i=0;$i<=$totalSlides;$i++){

$paras = $textFramesPPTX[$i]->getParagraphs();

$paraCount = $paras->getCount();
for ($j=0;$j<=$paraCount;$j++){
$port = $paras->get_Item($j)->getPortions();

$portCount = $port->getCount();

if($port != NULL){
for ($k=0;$k<=$portCount;$k++){
$text = $port->get_Item($k)->getText();
}
}
}

}

$pptx->save(getcwd()."/phppresentation.pptx",3);
}
catch(JavaException $ex)
{

echo $ex;
}

Can you please check and let me know the issue.
I am not able to get count of total slides also.

Thanks

Hi Anup,

I have observed the sample code shared by you and as far as code understanding is concerned it is right. Can you please share what issue you are dealing with when extracting the text. Also, in the above example there is no method to get the slide count. In order to get the slides count, you can port the following Java code to PHP. Also, please try using the sample code link shared by me in pure java console application on your end and verify if the text is extracted correctly for your presentation in Java. If it is good there then you need to visit the Php code on your end to serve the purpose.

Presentation pres=new Presentation(“Test.pptx”);
int slidecount=pres.getSlides().size();

Many Thanks,

Hi Mudassir,

Thank you for replying, the article which you have posted contains

//Get an Array of ITextFrame objects from all slides in the PPTX

ITextFrame[] textFramesPPTX = SlideUtil.getAllTextFrames(pptxPresentation, true);

This is to fetch all text frames in the presentation but in php when i try this i am getting no response, here is my code

$pptx = new Java(“com.aspose.slides.Presentation”,getcwd()."/Master template PPT dk.pptx");

$slideUtils = new Java(“com.aspose.slides.SlideUtil”);

$textFramesPPTX = $slideUtils->getAllTextFrames($pptx, true);

and also the count is 0

$count = count($textFramesPPTX);

Hi Anup,


We have investigated the code on our end. There seems to be ab issue with a loop condition.

j<=$paraCount; and $k<=$portCount must be replaced with j<$paraCount; and $k<$portCount

Many Thanks,

Hi Mudassir,

Thanks for the help its working but i got 2 issues.

1. I am not able to get the count of all textframes, i tried

$pptx = new Java(“com.aspose.slides.Presentation”,getcwd()."/Master template PPT dk.pptx");

$slideUtils = new Java(“com.aspose.slides.SlideUtil”);

$textFramesPPTX = $slideUtils->getAllTextFrames($pptx, true);

//here i am getting object not getting the count of all text frames.
$totaltextframes = count($textFramesPPTX,1);

2. In the loop i want to check if the text is “HI” then i want it to be replaced with “HELLO” , if text is “BAD” then i want it to replace it with "GOOD"

I have tried this java code

for(IPortion port : para.getPortions()){
port.getText()
}

In php

for ($k=0;$k<$portCount;$k++){
//but here i am getting object not the exact text
$text = $port->get_Item($k)->getText();

//I want here if $text = “Hi” then i will set it to “Hello”

//here i am able to replace all text in ppt with “Hello”
//$port->get_Item($k)->setText(‘Hello’);
}

I am able to replace all text in ppt but i cannot compare the text

Any assistance would be helpful.

Thank you very much for replying.


Hi Anup,

I am sorry for your inconvenience. I can share the the Java sample code for getting the text frame count by using following sample code. You can use the equivalent implementation in Php for that on your end.

//Count of frames
int Icount=textFramesSlideOne.length;

Secondly, for string comparison from portion in PHP, I like to share that you can find some help for string comparison by surfing over internet. At present, I don’t possess the PHP environment on my end and I may set it up over weekend on my end for further future references.

We are sorry for your inconvenience,

Hi Mudassir,

I managed to get text but i am not getting fulltext value here is what i get the respone

"$Comp… text has been truncated due to evaluation version limitation."

Actually the word i was looking for is “$Companyname” but instead i get the above line
5 actuall letters “$Comp” and then "… text has been truncated due to evaluation version limitation."

Any Ideas ?

Thanks

Hi Anup,

The message that you have shared is due to missing Aspose.Slides license in your application. You need to use and call Aspose.Slides license in your application to serve the purpose. Please visit this documentation link for your further kind reference in this regard.

Many Thanks,

Hi Mudassir,

First i need to thank you for all the support. After applying the license everything is working fine :).

Is there a way to access a particular chart and modify it

I got the link for java

Here i am not able to get chart data

//Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = (IChart)sld.getShapes().get_Item(0);

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

chart.getChartData() there is no such method exeception.

Is chart a instance of individual shape which contains chart in it?

Thank you.