Free Support Forum - aspose.com

Shift Paragraphs Down Based on Content

I’m new to Aspose and one of my first tasks is to create some one-line
paragraphs that will be replaced by text as the slide is processed. My
question is: Assume that I have some paragraphs on a slide, like so:

A
B
C

If,
say, paragraph A can be replaced by more than one line of text, how do I
cause the paragraphs below it to shift down so that they don’t overlap,
or go off the bottom of the slide? Thanks.

Dear Ken,

Thanks for your interest in Aspose.Slides.

I have tried to understand your requirement and like to share that you can achieve this using Aspose.Slides. Actually, you need to find the desired key string and replace that with desired text. If the text has more than one line then the next subsequent paragraph will be automatically shifted down. For your kind reference, I have shared the code snippet that will help you achieving the goal.

PresentationEx pres = new PresentationEx("D://Aspose Data//TextReplace.pptx");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

SlideEx slide = pres.Slides[0];

foreach (ShapeEx shp in slide.Shapes)

{

if (shp is AutoShapeEx)

{

AutoShapeEx ashp = (AutoShapeEx)shp;

if (ashp.TextFrame != null)

{

for (int paracount = 0; paracount < ashp.TextFrame.Paragraphs.Count; paracount++)

{

ParagraphEx para = ashp.TextFrame.Paragraphs[paracount];

foreach (PortionEx port in para.Portions)

{

port.Text = ParseValues(port.Text);

}

}

}

}

}

pres.Write("D://Aspose Data//TextReplace_New.pptx");

static string ParseValues(string value)

{

string results = value;

results = results.Replace("A", "Welcome to Aspose.Slides");

results = results.Replace("B", "Hello world");

results = results.Replace("C", "I am Mudassir");

results = results.Replace("D", "This is what i wanted");

return results;

}

Thanks and Regards,

Mudassir,

Thanks for the reply. When I try running the code, I get “java.lang.NoClassDefFoundError: com/aspose/metafiles/MetafilesException”. Perhaps I messed something up when converting the code to Java?

Ken

Dear Ken,

Please follow this link, where I have shared the java code to help you out.

Thanks and Regards,

Mudassir,

That was just the code I came up with in my own conversion, but I’m still getting the
java.lang.NoClassDefFoundError: com/aspose/metafiles/MetafilesException. I should mention also that I will be using .PPT, not .PPTX, and may have to do processing on a slide that I create from scratch.

Ken

Dear Ken,

You may also need to use Aspose.Metafiles for Java in your application and the exception that you are facing is due to missing JAR file reference in your project. Please proceed to this link for downloading Aspose.Metafiles for Java and add its refernce in your project code.

Thanks and Regards,

I checked and indeed, we don’t have the Metafiles jar.

I got the code working with a PPT file. Thanks for the help.

Ken

Oops! Not out of the woods yet. I’m still unclear how to substitute multiple strings for a given paragraph. If I could concatenate the strings and put newlines in between, that would work, but Aspose doesn’t accept strings with newlines.

IOW, I want to start with:
A
B

and get:

Some text in place of A
Some more text in place of A
Perhaps even more in place of A
B

Dear Ken,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

You can replace the character or string with a multi line text in Aspose.Slides. You may need to add soft enter "\u000b" in your replacing string. Please use the following code snippet to accomplish your task.

static String ParseValues(String value)
{
String results = value;
results = results.replace("A", "Welcome to Aspose.Slides \u000b Hello World \u000b Aspose.Slides for Java" );
results = results.replace("B", "Hello world");
results = results.replace("C", "I am Mudassir");
results = results.replace("D", "This is what i wanted");


return results;
}
Thanks and Regards,

Great, thanks!

You’ve probably noticed that I made a new thread about this issue today, as I wasn’t sure whether the old thread was still active. Oops.

Mudassir,

In experimenting with the code you sent me, I came across a problem.

Attached is the slide I’ve been working on. If I substitute a long string for the placeholder [S], it sometimes interleaves with the text for placeholder [A]–see interleaved.ppt. If the string is short enough, no wrap occurs.

Ken

Dear Ken,

I have observed the issue specified by you. Actually, I only shared the text replacement code for particular strings inside the placeholder paragraphs. Your scenario is a bit different where by you have 2 separate placeholders where you want to replace the string. The text wrap bbetween two placeholder is not supported in Aspose.Slides and even not in PowerPoint as well. I suggest you to you use single placeholder and you will not observe this text overlapping issue. Secodnly, if you want to you use multiple placeholders, then you will need to re-adjust the position of second placeholder programmatically based on the new height of placeholder 1( with [s]) string. You may please need to use shape.getHeight() property after the text is replaced in placeholder 1 and then re-adjust the position of second placeholder based on the new height of placeholder 1 by using shape.setX() property.

Thanks and Regards,

I already experimented with getHeight(), but didn’t have much luck. How would I make a single placeholder? Programmatically, I mean.

Dear Ken,

I regret to inform you that Aspose.Slides for Java does not allow to add the placeholder programmatically and you may access them only. You may please add the text frame in rectangle shapes to serve the purpose. Secondly, as I shared earlier that there is no text wrap between two separate placeholders, so I suggest you to use single placeholder as given in the shared presentation file. Hopefully, it will resolve your issue.

Thanks and Regards,

OK. Luckily, we don’t have to produce the slide entirely from scratch, so making a placeholder in a template slide won’t be a problem.

BTW, I posted another question, about the easiest way to surround text with a shape.

Ken

Dear Ken,

I have shared my comments in response to your query about surrounding text with shape over this link.

Thanks and Regards,