Strange beahviour with paragraphs (PPTX)

Last post 02-02-2012, 3:49 AM by hassan.farrukh. 3 replies.
Sort Posts: Previous Next
  •  02-01-2012, 6:57 AM 358639

    Strange beahviour with paragraphs (PPTX) Java

    Hello,

    I have a string containing newlines (\n) and the following code:

    String text = "abc\ndef\nghi\njkl";
    TextFrame tf = ( (AutoShapeEx) slide.findShapeByAltText(altText)).getTextFrame();
    tf.setText(text);

    System.out.println(tf.getParagraphs().size());

    No matter how many \n's are in the string - what I get is always exactly two paragraphs; one containing all of the string up to the last \n (in the above example: "abc\ndef\nghi"), and one containing the rest ("jkl").

    However I would expect either that each substring (abc, def, ghi, jkl) will get its own paragraph, or that the whole string is added to one single paragraph.

    What I need is to have each substring in its own paragraph, so that I can decide whether it gets a bullet point or not, e.g.

    * abc
    def
    gji
    * jkl


    I managed to do it by setting each substring in a new paragraph using tf.getParagraphs().add(newParagraph). However the behaviour described above seems very strange to me so I wanted to report it.


    Kind regards
    Stefan
     
  •  02-01-2012, 10:19 AM 358702 in reply to 358639

    Re: Strange beahviour with paragraphs (PPTX) Java

    Hi Stefan,

    Thanks for you inquiry.

    I have used the following code snippet and able to resolve the issue which you were facing.
    Note:  I am using latest version of Aspose.Slides for Java which can be found here.
          public static void para(){
                try{
                      //Instantiate a PresentationEx class that represents a PPTX file
                      PresentationEx pres = new PresentationEx();

                      //Accessing first slide
                      SlideEx slide = pres.getSlides().get(0);

                      //Add an AutoShape of Rectangle type
                      int idx = slide.getShapes().addAutoShape(ShapeTypeEx.RECTANGLE, 50, 150, 300, 150);
                      AutoShapeEx ashp = (AutoShapeEx)slide.getShapes().get(idx);
                      //Access TextFrame of the AutoShape
                      String text = "abc\ndef\nghi\njkl";
                      TextFrameEx tf = ashp.getTextFrame();
                      tf.setText(text);
                      //Write PPTX to Disk                   pres.write("D:\\Assignments\\Aspose.Slides\\Java\\Queries\\ParaTest.pptx");             }catch (IOException e) {                   // TODO Auto-generated catch block                   e.printStackTrace();             }       }

    Many Thanks.

    Best Regards

    Hassan Farrukh
    Support Developer
    Aspose Sialkot Team

    Aspose - The .NET and Java Component Publisher
     
  •  02-02-2012, 1:35 AM 358859 in reply to 358702

    Re: Strange beahviour with paragraphs (PPTX)

    Hello Hassan,

    thank you very much for your help.

    Kind regards
    Stefan
     
  •  02-02-2012, 3:49 AM 358895 in reply to 358859

    Re: Strange beahviour with paragraphs (PPTX)

    Hi Stefan,

    Thanks for appreciation,

    If you require any further information, please feel free to contact us.

    Best Regards
    Best Regards

    Hassan Farrukh
    Support Developer
    Aspose Sialkot Team

    Aspose - The .NET and Java Component Publisher
     
View as RSS news feed in XML