Free Support Forum - aspose.com

Issue inserting bulleted paragraph to a shape

Hi,

I am having a problem trying to achieve required styling for paragraphs added to our presentations.
This is my goal:
- I need to add a bulleted paragraph
- If there is a master slide styling defined for various levels of bulleted paragraphs, I need to use that
- If there is not a master slide styling available with bullets, I need to add a default symbol bullet to my paragraph.

Now, see the attached para-styling.pttx file. It has 3 shapes. One with master slide styles defined, and 2 without. With these 2 without master slide styling, one has a paragraph with a bullet, one has a paragraph without a bullet.

Now see the code snippet below. I am adding 2 paragraphs to each shape. For the first one, I set only the depth. For the second one, I set also the bullet style.

The problem I am having is that when I am trying to find out if my added paragraph has a bullet, I get a “Not Defined” as a bullet type for either a paragraph with a bullet or without. Similarly, indent, left <span style=“font-size:10.0pt;font-family:“Tahoma”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>margin <!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–> and other paragraph styling properties come out as NaN.

So when you run the following code, you can see, that when the first paragraph is added, it is added as a bulleted one in the first shape, not bulleted one in the second shape and bulleted one in the third shape. I am happy with the output for the first and third shape, but I need to have a bullet in my second shape as well.

So when I try to set a bullet type to a paragraph, as I do for my last paragraph added, I do get bullets in all my shapes, however, styling on the bullet in the first shape is not taken from the master slide styles anymore, it is overridden, which is not desired outcome.

So the question: is there a way for me to find out if the paragraph I added to a shape has a bullet from the master slide styles or I need to manually assign a bullet type.

Here is the code snippet used:

FileInputStream fileInput = new FileInputStream( “c:/para-styling.pptx”);
Presentation pres = new Presentation( fileInput );

ISlide slide = pres.getSlides().get_Item(0);
IAutoShape aShp = null;
ITextFrame txtFrm = null;
Integer i = 0;

while( i < slide.getShapes().size() )
{
aShp = (IAutoShape) slide.getShapes().get_Item(i);
txtFrm = aShp.getTextFrame();
i = i + 1;
Paragraph originalPara = (Paragraph) txtFrm.getParagraphs().get_Item(0);
String longText = "This is a long line. This is a long line. This is a long line. ";
Paragraph para2 = new Paragraph( originalPara );
para2.getParagraphFormat().setDepth((short) 1);
para2.setText(longText);
txtFrm.getParagraphs().add(para2);

Paragraph para3 = new Paragraph( originalPara );
para3.getParagraphFormat().getBullet().setType(BulletType.Symbol);
para3.getParagraphFormat().setDepth((short) 1);
para3.setText(longText);
txtFrm.getParagraphs().add(para3);
}

FileOutputStream fileOutput = new FileOutputStream( “c:/output.pptx”);
pres.save( fileOutput, SaveFormat.PPTX );


Thanks!

Natasa

PS: we are using Aspose Slides for Java 14.6.0

Hi Natasa,


I have observed the requirements shared by you and request you to please provide working sample application with us that I may use on my end to serve your needs. Please also share the output presentation that you are getting and output presentation that is desired. I will try my best to help you further in this regard.

Many Thanks,

Hi,

I have attached 3 pptx documents:

  • outputBullets.pptx is actual outcome when running the code above. I have manually underlined the paragraphs that display desired outcome. As you can see, it is paragraph 2 in shape 1 and paragraph 3 in shape 2.
  • para-styling-do1.pptx
  • para-styling-do2.pptx
    these 2 documents represent the desired outcome. It has to be a paragraph with a bullet. Can be depth 0 or depth 1
Basically the desired outcome is what you get when you open a PowerPoint and manually add a new paragraph in each shape and make it bullet (using the para-styling.pptx document I attached previously):
  1. If a shape has a master slide styles defined, the bullet style is same as there. (shape 1 (left hand side) in para-styling.pptx)
  2. If there is not master slide shape styling, and the actual shape
    does not define paragraph bullet style, then I need to set a default
    bullet type. (shape 2 (top right hand side) in para-styling.pptx)
  3. If there is not master slide shape styling, but the actual shape has a paragraph with a bullet somehow styled, that’s the bullet style used in another paragraph. (shape 3 (bottom right hand side) in para-styling.pptx)

I hope this will help you.

The code in my original post represents the application portion I am trying to simulate. Please let me know if you have any problem running that code.

Thanks,

Natasa


Hi Natasa,


I am investigating the issue on my end and will get back to you shortly with a feedback as soon as I will complete my investigation. I will really appreciate your patience in this regard.

Many Thanks,

Hi Mudassir,

Please let me know if you had a chance to do any investigation on this issue. It would really help us to know if there is any workaround for this or if there is a chance for a fix.

Please let me know if you have any questions or any problems to replicate the issue I described.

Thanks,

Natasa

Hi Natasa,

I am checking your issue and would like to know if my understanding of your requirement is correct. You need to check whether a shape already has bullet style from the master slide, if so, you need to keep the same bullet style in additional paragraphs in that shape. If the shape doesn’t have a bullet style, you need to add a bullet style of your choice. The issue you are currently facing is regarding checking the bullet type associated with shape from master.

Please let me know if my understanding is correct regarding the issue you are facing. This will help me in further checking your issue.

Thanks & Regards,

Hi Owais,

Thanks for your response. Yes, it is exactly what I need and actually, I was able to figure something out: I have found out that I can access the master slide formatting information (or any inherited formatting data) using createParagraphFormatEffective() method, instead of accessing the paragraph format directly.

Please let me know if this is the way to do it or if there is another way.

If using the createParagraphFormatEffective() is a way to go, I have found one issue with it. This time I am able to get around it, however, it took me a lot of time and confusion to figure out what was going on.

Please see the code snippet below. Also, I have attached StylingPlaceholder1.pptx file, which has one slide with one shape with a place holder.
In the code below, I am trying to add a paragraph to the shape and set the depth to 1, which should result in a paragraph with a bullet, formatted as it is set in its master slide shape.

If the code is used as below, after I set the depth to 1, the output for paragraph.createParagraphFormatEffective().getBullet().getType() (Para Bullet Type After Setting Depth) returns 0, which is no bullet (None). Still when I open the document, the paragraph is set correctly, with the bullet.

If I remove the line that accesses the bullet type information before the depth is set (Para Bullet Type Before Setting Depth), the output after the depth is set (Para Bullet Type After Setting Depth) will be correct, the bullet type will be “Symbol” (value 1).

FileInputStream fileInput = new FileInputStream( “c:/StylingPlaceholder1.pptx”);
Presentation pres = new Presentation( fileInput );

ISlide slide = pres.getSlides().get_Item(0);
IAutoShape aShape = (IAutoShape) slide.findShapeByAltText(“placeholder”);

Paragraph newPara = new Paragraph();
newPara.setText( “New Simple Paragraph” );
aShape.getTextFrame().getParagraphs().add(newPara);

System.out.println(“Para Bullet Type Before Setting Depth:” + newPara.createParagraphFormatEffective().getBullet().getType() );

newPara.getParagraphFormat().setDepth( (short) 1 );

System.out.println(“Para Bullet Type After Setting Depth:” + newPara.createParagraphFormatEffective().getBullet().getType() );

While the actual paragraph in the presentation has the correct styling, it is quite important for us to be able to get this information via API too. As I said I can work around this issue now, but I would appreciate if this can be fixed.

Please let me know if there is a better way to get the information I need.

Thanks,

Natasa

Hi Natasa,

Thank you for the details.

I have added a feature enhancement request in our issue tracking system to support the feature you are interest in. The request has been registered with issue id: SLIDESJAVA-34555. Our development team will further look into the details you shared and check the feasibility of the feature. You will be notified via this forum thread once the feature gets available.

Thanks & Regards,

The issues you have found earlier (filed as SLIDESJAVA-34555) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.