Is It Possible to Get Details of a Particular Part of Text Placeholder in Java?

Hi,

I want to fetch details like (X,Y,Height,Width,Color, etc) recursively from one text placeholder’s text which is encapsulated in “{{ }}” curly bracket.

For example in below zip there is one screenshot of a layout’s placeholder “{{ client name }} and {{dynamic field}}”. I want to store styling details separately for “{{client name}}” and a “{{dynamic field}}” variable data in array of object. I want X, width, colour of a “{{dynamic field}}” as Y will be same as placeholder’s Y position but the X position will be different.

Please let me know is this possible with aspose slide java?

Below zip contains :

  1. Screen Shot of a layout
  2. Theme file for better understanding.

assets.zip (61.6 KB)

Thanks.

@saquibs,
I would sagest you to solve the issue as follows:

  1. You should write a simple text parser that would be able to analyze the text by your syntax rules (wrapped text in curly brackets, for example).
  2. Then you can get a position and size from Portion objects. The text color can be extracted from PortionFormat objects.

API Reference: IParagraph interface, IPortion interface.

Thanks for the reply.

I am not able to get the proper information can you please able to provide some code demonstration or code snippet for better understanding.

Thanks in advance.

@saquibs,
The text parser has to be your own component for the text analysis. It doesn’t depend on Aspose.Slides library.
Text portion size, position, and color can be obtained as below:

// shape is IAutoShape here

// get the first paragraph, for example
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);

// get the first text portion, for example
IPortion portion = paragraph.getPortions().get_Item(0);

Rectangle2D portionRectangle = portion.getRect();
Color portionColor = portion.getPortionFormat().getEffective().getFillFormat().getSolidFillColor();

@Andrey_Potapov

Thanks, I did that but there is a case where I am having a single paragraph and single portion now I have to get X and Width of “{{dynamic field}}” word.

Is it possible in that case?

Thanks.

@saquibs,
In that case, I would suggest you the next workaround:

  1. Split the text into elements: “{{”, “dynamic field”, “}}”.
  2. Create an empty paragraph based on the paragraph that contains the text “{{dynamic field}}”.
  3. Add text elements to the new paragraph as single portions.
  4. Now you can get the position, size, and color of the portion with the text “dynamic field”.