Bug 65934 - removed textparagraphs remain visible in slideshow
Summary: removed textparagraphs remain visible in slideshow
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 5.2.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-07 08:27 UTC by bugzilla-apache
Modified: 2022-03-12 10:13 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla-apache 2022-03-07 08:27:44 UTC
When a textparagraph is deleted, programmatically it seems as if the deletion has been applied. However, the textparagraph is still visible in the slide of the slideshow. (The same problem occurs with textruns, cf. another filed bug.)

Steps to reproduce:

  @Test
  void removeTextParagraph() throws IOException {
    final XMLSlideShow ppt = new XMLSlideShow();

    final XSLFSlide slide = ppt.createSlide();;

    final XSLFTextBox textBox = slide.createTextBox();
    textBox.setAnchor(new Rectangle(0, 0, 100, 100));

    textBox.getTextParagraphs().get(0).getTextRuns().get(0).setText("lorem");
    textBox.addNewTextParagraph().addNewTextRun().setText("ipsum");
    textBox.addNewTextParagraph().addNewTextRun().setText("dolor");

    assertEquals(3, textBox.getTextParagraphs().size());
    assertEquals("lorem\nipsum\ndolor", textBox.getText());
    assertEquals("lorem", textBox.getTextParagraphs().get(0).getText());
    assertEquals("ipsum", textBox.getTextParagraphs().get(1).getText());
    assertEquals("dolor", textBox.getTextParagraphs().get(2).getText());

    textBox.getTextParagraphs().remove(textBox.getTextParagraphs().get(1));

    assertEquals(2, textBox.getTextParagraphs().size());
    assertEquals("lorem\ndolor", textBox.getText());
    assertEquals("lorem", textBox.getTextParagraphs().get(0).getText());
    assertEquals("dolor", textBox.getTextParagraphs().get(1).getText());

    String filepath = System.getProperty("java.io.tmpdir") + "tmp.pptx";

    FileOutputStream fos = new FileOutputStream(filepath);
    ppt.write(fos);

    fos.close();

    System.out.println("file written to " + filepath);
  }

see also:

https://user.poi.apache.narkive.com/S6TaNfG4/delete-specific-xslftextparagraph-in-xslfshape
Comment 1 PJ Fanning 2022-03-07 10:33:15 UTC
I added r1898668 - would you be in a position to test this? The problem is that textBox.getTextParagraphs().remove(...) does not remove the underlying XMLBeans data (CTTextParagraph class).

If you want to work around the issue without my change, you can get the CTTextBody for the XSLFTextBox using textBox.getTextBody().getXmlObject(). You can then iterate over the 'p' array to find the right CTTextParagraph to remove.
Comment 2 bugzilla-apache 2022-03-09 10:04:49 UTC
I was able to verify that the change works.

The above test initially failed with an UnsupportedOperationException. Great idea to change the list of textparagraphs to Collections.unmodifiableList. :-)

After replacing the line

  textBox.getTextParagraphs().remove(textBox.getTextParagraphs().get(1));

with

  textBox.removeTextParagraph(textBox.getTextParagraphs().get(1));

the test passed again and the slide finally looks as expected.

Thanks for fixing the issue!