Could not Find and Replace text In PPT (Java)

@Adnan.Ahmad
I have used the same code as above, but still am not getting the output. The word, ‘sample’ is not replaced by ‘done’ in my case. Although, the code is exactly the same.
Find the output file here : Output.zip (364.5 KB)

Please guide !

@Kushal.20,

I have checked your output file. I like to inform that you are using Aspose.Slides 19.2 on your end. Please try to use latest version Aspose.Slides 19.5 on your end and share feedback with us if there is still an issue.

@Adnan.Ahmad
Now, I have tried it with 19.5 too, still am not able to resolve this. Please Help !

@Kushal.20,

Can you please share complete environment details with us. As you know i have already shared generated result with you for your kind reference.

@Adnan.Ahmad
I am using Java 1.8 i.e; jre1.8.0_131 and the jars for aspose.slides : 1. aspose-slides-19.5-jdk16.jar and 2. aspose-slides-19.5-javadoc.jar
This is the environment I am working in !

I have tried almost everything. Kindly look into this and let me know where actually the fault is !

@Kushal.20,

I have observed the sample code shared by you. The issue lies in the code where you are trying to replace string with bullet rather than only text. I suggest you to please try using following sample code on your end.

public static void ReplacePresentationText()
{
    String path="C:\\Users\\Muhammad\\Downloads\\samplepptx\\";
    Presentation presentation = new Presentation(path+"samplepptx.pptx");
    presentation.joinPortionsWithSameFormatting();
    String strToReplace = "Done";
    ITextFrame[] tb = SlideUtil.getAllTextFrames(presentation, true);
    String strToFind = "Sample";
    System.out.println("Before for");
    for (int i = 0; i < tb.length; i++)
    {
        for (IParagraph ipParagraph : tb[i].getParagraphs())
        {
            for (IPortion iPortion : ipParagraph.getPortions())
            {
                if (iPortion.getText().toLowerCase().contains(strToFind.toLowerCase()))
                {
                    iPortion.setText(iPortion.getText().toLowerCase().replaceAll(strToFind, strToReplace));
                    System.out.println("replaced");
                }
            }
        }
    }
    presentation.save(path+"Output.pptx",SaveFormat.Pptx);
}

Output.zip (362.4 KB)

@mudassir.fayyaz, thanks for your continued support !
But, I am still getting the same unchanged output.

I am getting this, but after this, it’s not going inside the for loop , as previously said ! :confused:

@Kushal.20,

Are you using licensed version of Aspose.Slide for Java or using without license. If you are using without license then in unlicensed version there is limit to access all paragraphs portions inside text frame. Otherwise, there is no issue at and I have already shared the output with you too.

@mudassir.fayyaz
Nope ! Am using the trial version.
But, it should have atleast replaced once, in the trial version ? Or, it won’t ?

yeah,I saw the output you generated, but I am unable to get the result at my end. I have tried everything, neither getting any error/exception !

@Kushal.20,

I like to inform that trial version has some limitations. Please use license version on your end to use this feature.

@Adnan.Ahmad
Okay, i will try using license too ! In fact, I tried !
But, I have been using evaluation version for all other formats, since I am just exploring and testing the API’s, if they are suitable and I could buy them for using, and all of them have been working fine.
For Aspose.Slides, I read following on the official website :

Evaluation Version Limitation

Evaluation version of Aspose.Slides (without a license specified) provides full product functionality except that when you save your presentations using Aspose.Slides, an Evaluation Watermark is injected at the center of each slide as shown in the figure below

Kindly, let me know what the issue is and how to apply license, I tried the way given on the website but am getting the exception, that, LicenseStream is not available for reading. I did not get any license file in the jar folder that I downloaded.

@Kushal.20,

You are right about watermark insertion. However. the evaluation version does impose some limitations like no full access to all paragraphs or portions inside TextFrame (You may have access to few portion of text while using evaluation version but not all if there are many portions. For simple presentation with one or two portions. it may work). There are some limits on some chart features too.

My suggestion to you is to try exploring the API using 30 days free license that you may use on your end to verify the API features.

@mudassir.fayyaz
Finally, am done with this. I followed your suggestion . Thanks buddy ! :slight_smile:

Well, I need another assistance.This is the code that I have used for finding and replacing text :

public static void main(String[]args) {

		com.aspose.slides.License license = new com.aspose.slides.License();
		license.setLicense("xyz");
	
		Presentation presentation = new Presentation("E:\\docs\\samplepptx.pptx");
		presentation.joinPortionsWithSameFormatting();
		String strToReplace = "Done";
		ITextFrame[] tb = SlideUtil.getAllTextFrames(presentation, true);
		//String find = "sample";
		String strToFind= "(?i)\\b"+find+"\\b";
		//System.out.println("Before for :"+strToFind);
		for (int i = 0; i < tb.length; i++)
		{
			for (IParagraph ipParagraph : tb[i].getParagraphs()) 
			{	
				for (IPortion iPortion : ipParagraph.getPortions()) 
				{	
					if(iPortion.getText().toLowerCase().contains(strToFind.toLowerCase()))
					{ 	
						iPortion.setText(iPortion.getText().replaceAll(strToFind, strToReplace));
						System.out.println("replaced");
					}
				}
			}
		}
		presentation.save("E:\\docs\\Output.pptx",SaveFormat.Pptx);
	} 

Here the problem is with CASE. I am unable to pass text as case insensitive.Like for PDF, I used
String strFind = “sample”;
String find = “(?i)\b”+strFind+"\b";
This replaced all the occurrences of the word ‘sample’, be it in LowerCase or UpperCase
But, this isn’t working in this case of slides.
Thanks !

@Kushal.20,

I have worked with sample code and source file shared by you. I have shared my generated result for your kind reference. Can you please check and share if this is acceptable for you.Output.zip (362.4 KB)

@Adnan.Ahmad
Yes, as far as I can check, it’s correct. I want all samples to be replaced with Done, no matter I input sample or Sample.
I guess, this is correct.
Can you please share with me the syntax for case insensitivity with me?

@Kushal.20,

Please check following sample code that i have shared with you. If there is still an issue than please share feedback with us.

Presentation presentation = new Presentation(“samplepptx.pptx”);
presentation.joinPortionsWithSameFormatting();
String strToReplace = “Done”;
ITextFrame[] tb = SlideUtil.getAllTextFrames(presentation, true);
String find = “sample”;
String strToFind= “(?i)\b”+find+"\b";
// System.out.println(“Before for :”+strToFind);
for (int i = 0; i < tb.length; i++)
{
for (IParagraph ipParagraph : tb[i].getParagraphs())
{
for (IPortion iPortion : ipParagraph.getPortions())
{
if(iPortion.getText().toLowerCase().contains(find.toLowerCase()))
{
iPortion.setText(iPortion.getText().replaceAll(strToFind, strToReplace));
System.out.println(“replaced”);
}
}
}
}
presentation.save(“Output.pptx”,SaveFormat.Pptx);

@Adnan.Ahmad
Thanks!
But, It’s not working still. Output is same as before.
Only ‘sample’ is getting replaced and not ‘Sample’.
Please find the attached output file. Output.zip (361.7 KB)

Also, here is the input file : samplepptx.zip (395.0 KB)

@Kushal.20,

Can you please share if you are using full license or using trial version.

I am using 30 days temporary license, @Adnan.Ahmad , and I guess, it allows 30 days complete usage with no limitations, right ?

@Kushal.20,

The 30 days license is a full working license too. My request to you is to use the sample code that I previously shared with you as it is.

You are using:

String strToFind= “(?i)\b”+find+“\b”;

Please use:

String find = "sample";