ASPOSE.SLIDES for Java - ColdFusion

Hi,

Our company has been using your product for close to 14 years and has legacy applications. The system we have is built on ColdFusion and works very well with ASPOSE.SLIDES for Java. Do you still support ColdFusion?

We are upgrading our application and need help in your Find and Replace functionality. We’ve seen a Java and Python examples in some threads. Can you please help. Based on the example you have, we’ve put the below together. But doesn’t work

` pres = CreateObject(“java”, “com.aspose.slides.Presentation”).init("#variables.TargettedPresentation#");
pres.JoinPortionsWithSameFormatting();// To make sure formatting is not lost when replacing text
SlideUtil = CreateObject(“Java”, “com.aspose.slides.SlideUtil”);
textFrames = SlideUtil.getAllTextFrames(pres, true);

strToReplace = "Replaced";
strToFind = "test";

for(textFrame in textFrames)
{
  for (ipParagraph in textFrame.getParagraphs())
   {
       for (iPortion in ipParagraph.getPortions()) //Error happens here because ipParagraph does not have access to getPortions() methods.
       {
          if(find(iPortion.getText(),"#strToFind#"))
          {
              iPortion.setText("#strToReplace#");
          }
          else
          {
              writeOutput('Nothing happening here');
          }
        }   
    }
   
}
//Write the presentation as a PPTX file
saveFormat=CreateObject("java", "com.aspose.slides.SaveFormat");
//Write the presentation to disk
pres.save("#TargettedPresentation#", saveFormat.Pptx);`

@JediJide,

I have observed the requirements shared by you and like to share that Aspose.Slides for Java does support ColdFusion. I suggest you to please try using latest Aspose.Slides for Java 18.8 on your end first. As far as your suspected code line is concerned, I see no issue in that as every paragraph has collection of Portions inside it. Can you please make this sure by accessing a simple presentation that has one shape and with some text inside that. You can access that to see if the code sample still gives error on the suspected line. Please also consider commenting following line your code as well for testing.

pres.JoinPortionsWithSameFormatting();

1 Like

Thanks for your response. I have now commented pres.JoinPortionsWithSameFormatting(); as required, it is to make sure the PPTX formatting is maintained after text replacement. I’ll try with a simple PPTX to make sure all is well.

I have ASPOSE 18.8, but will now try with a simple PPTX. **NB, when I debug ipParagraph in textFrame.getParagraphs(), it does not display or show the getPortions() methods, getPortions() is in the com.aspose.slides.IParagraph" class and getParagraphs is in the "com.aspose.slides.SlideUtil" class. Two separate and different classes. That is why when I call the getPortions() which is a method in com.aspose.slides.IParagraph" class, I get the error.

The challenge for me is how to access that method (getPortions()) in what is really a com.aspose.slides.IParagraph" class.

Thanks

Please see the attached, they are the debugged paragraph methods. Please note that the getPostions() method is not there, that is why I cannot access it. Thanks.

paragraphMethods.jpg (311.1 KB)

@JediJide,

I have observed the image shared by you. You are referring to IParagraphCollection (which is collection of IParagraph) here rather than IParagraph. The IParagraphCollection does not have any collection of Portions. The IParagraph has collection of Portion and getPortions() method inside that. I hope the shared information will be helpful.

1 Like

Ok, I’ll take a look and let you know. Thanks.

@mudassir.fayyaz - I do not see this working in any other code apart from Java. The inheritance from one class to the other is compiled in Java so I cannot jump from Class CreateObject("Java", "com.aspose.slides.SlideUtil") to CreateObject("Java", "com.aspose.slides.IParagraph"). Can you please give any more pointers because I am stumped :thinking: .

I know that I need to use IParagraph but how?

Thanks

@JediJide,

I am checking details and will get back to you with feedback ASAP.

1 Like

@mudassir.fayyaz,

I appreciate it.

@JediJide,

Can you please provide the complete code example that you are using on your end as it may be helpful to investigate the issue.

@mudassir.fayyaz - Please see the complete code below:

`pres = CreateObject(“java”, “com.aspose.slides.Presentation”).init("#variables.TargettedPresentation#"); pres.JoinPortionsWithSameFormatting();// To make sure formatting is not lost when replacing text SlideUtil = CreateObject(“Java”, “com.aspose.slides.SlideUtil”); textFrames = SlideUtil.getAllTextFrames(pres, true);.`

`strToReplace = “Replaced”;
strToFind = “test”;

for(textFrame in textFrames)
{
for (ipParagraph in textFrame.getParagraphs())
{
for (iPortion in ipParagraph.getPortions()) //Error happens here because ipParagraph does not have access to getPortions() methods.
{
if(findNoCase(iPortion.getText(),"#strToFind#"))
{
iPortion.setText("#strToReplace#");
}
else
{
writeOutput(‘Nothing happening here’);
}
}
}

}
//Write the presentation as a PPTX file
saveFormat=CreateObject(“java”, “com.aspose.slides.SaveFormat”);
//Write the presentation to disk
pres.save("#TargettedPresentation#", saveFormat.Pptx);</cfscript>

@JediJide,

I have worked over your requirements and have created following sample code that you may verify on your end.

Class CreateObject("Java", "com.aspose.slides.SlideUtil") to CreateObject("Java", "com.aspose.slides.IParagraph")

`pres = CreateObject(“java”, “com.aspose.slides.Presentation”).init("#variables.TargettedPresentation#"); 

pres.JoinPortionsWithSameFormatting();
// To make sure formatting is not lost when replacing text SlideUtil = CreateObject(“Java”, “com.aspose.slides.SlideUtil”); textFrames = SlideUtil.getAllTextFrames(pres, true);.`

`strToReplace = “Replaced”;
strToFind = “test”;

for(textFrame in textFrames)
{
	ParaCollection=CreateObject("Java", "com.aspose.slides.IParagraphCollection");
	ParaCollection=textFrame.getParagraphs();
	ParaCount=ParaCollection.getCount();
	
	Para=CreateObject("Java", "com.aspose.slides.IParagraph");

      	
        for ( i = 0 ; i <ParaCount ; i++ )
	{
	
		Para=ParaCollection.get_Item(i);
	
		PortCollection=CreateObject("Java", "com.aspose.slides.IPortionCollection");
		Port=CreateObject("Java", "com.aspose.slides.IPortion");

		PortCollection=Para.getPortions();
		PortCount=PortCollection.getCount();
		
		for (j = 0 ; j <PortCount ; j++)
		{	
			Port=PortCollection.get_Item(j);
			if(findNoCase(Port.getText(),"#strToFind#"))
			{
				Port.setText("#strToReplace#");
			}
			else
			{
				writeOutput(‘Nothing happening here’);
			}
		}
	}

}
//Write the presentation as a PPTX file
saveFormat=CreateObject(“java”, “com.aspose.slides.SaveFormat”);
//Write the presentation to disk
pres.save("#TargettedPresentation#", saveFormat.Pptx);</cfscript>

You may observe the different class objects that I have created. Moreover, it also entail the hierarchy of the different objects as well.

1 Like

@mudassir.fayyaz,

Please ignore my last post. This works perfectly. I really appreciate your time on this.