Adding notes to slide - NullPointerException

Hi,


I’m using aspose for slides 15.1.0 and have problem with adding notes to slide like this:

IParagraphCollection paragraphs = slide.getNotesSlide().getNotesTextFrame().getParagraphs();
paragraphs.addFromHtml(“my note”);
It works fine but I have one specific situation when code
slide.getNotesSlide().getNotesTextFrame() returns NULL.
To reproduce this you have to open presentation in PowerPoint and in “View->Notes Page” remove frame with notes. To understand it better i’ve attached image with screen from PowerPoint.
Do you know how to create this section(notesTextFrame) in Java if it is not available?

Hi Tomasz,

I have observed your requirement and suggest you to please try using the following sample code to add slide notes on your end. I hope this will be helpful. Please share, if I may help you further in this regard.

public static void addSlideNotes()
{
Presentation pres = new Presentation();

//Access the first slide

ISlide sld = pres.getSlides().get_Item(0);

//MUST: Creating Slide note instance
INotesSlide note = sld.addNotesSlide();

//Casting to autoshape
IAutoShape shp1 = (IAutoShape)note.getShapes().get_Item(1);

//Accessing autoshape’s text frame
if(shp1.getTextFrame()==null)
shp1.addTextFrame("");

ITextFrame txt1 = shp1.getTextFrame();

IParagraph par=txt1.getParagraphs().get_Item(0);

IPortion portion=par.getPortions().get_Item(0);

par.setText(“Hello World”);

pres.save(“D://Aspose Data//notext.pptx”,SaveFormat.Pptx);
}
Many Thanks,

when there is not noteTextFrame I have only one shape in notes


note.getShapes().size() == 1

and note.getShapes().get_Item(1) throws error

When i change to note.getShapes().get_Item(0) then everything is OK but my note is not added to slide.

Hi Tomasz,

I have tried to observe the issue shared by you and have not been completely able to understand that. Have you tried using the sample code shared by me on your end. It works on my end. I suggest you to please try using the same. If there is still an issue then please share the working sample code as shared by me that is reproducing the issue along with complete issue statement so that I may help you further on my end.

Many Thanks,

Hi,


I’ve created working maven project with 5 tests to help you understand my problem(example project is in attachment - aspose-test.zip).
There are two presentations (one with notesTextFrame, second without).
Runing those test you can reproduce this issue.

This is content of one test from attached project

@Test
public void should_add_note_forum_example_without_textFrame_adding_to_second_shape() throws IOException {
Presentation p = readPresentation(PRESENTATION_WITHOUT_NOTES_FRAME_PPTX);
final ISlide slide = p.getSlides().get_Item(0);
INotesSlide note = slide.addNotesSlide();

IAutoShape shp1 = (IAutoShape) note.getShapes().get_Item(1); //here exception because there is only 1 shape

if (shp1.getTextFrame() == null)
shp1.addTextFrame("");

ITextFrame txt1 = shp1.getTextFrame();
IParagraph par = txt1.getParagraphs().get_Item(0);
par.setText(“Hello world”);

p.save(“target/” + “presentation_forum_without_textFrame_adding_to_second_shape.pptx”, SaveFormat.Pptx);
}

Hi Tomasz,

I have observed the shared java file and working over that and will share the feedback with you ASAP. As a workaround can you please try loading the presentation directly from disk without using file stream as in past days I have encountered a some what similar issue if not exact.

Many Thanks,

Hi Tomasz,

I have observed the methods shared by you. In one of the methods you are trying to access the shape at index 1 which does not exist as there is only one shape that is at index 0. I have attached the modified java file for your reference and you may please try using it on your end as it works without issue on my end.

Many Thanks,

Hi, thx for response


Your code generates PPTX, but without note…

In below line expression always returns false because shp1 type in my case is PlaceholderType.SlideImage and code which is adding note is never executed.
if (shp1.getPlaceholder().getType() == PlaceholderType.Body)

Example code:
@Test
public void shold_add_note() throws IOException {
Presentation p = new Presentation(path + PRESENTATION_WITHOUT_NOTES_FRAME_PPTX);
final ISlide slide = p.getSlides().get_Item(0);
INotesSlide note = slide.addNotesSlide();

int countx = note.getShapes().size();
for (int i = 0; i < note.getShapes().size(); i++) {
IShape shape = note.getShapes().get_Item(i);
if (shape instanceof IAutoShape) {
IAutoShape shp1 = (IAutoShape) note.getShapes().get_Item(0);
int placeType = shp1.getPlaceholder().getType();
if (shp1.getPlaceholder().getType() == PlaceholderType.Body) {
if (shp1.getPlaceholder() != null) {

if (shp1.getTextFrame() == null)
shp1.addTextFrame("");

ITextFrame txt1 = shp1.getTextFrame();
IParagraph par = txt1.getParagraphs().get_Item(0);
par.setText(“Hello world”);
}
}
}
}
p.save(path + “generated_presentation.pptx”, SaveFormat.Pptx);
}

Hi Tomasz,

I have further investigated the issue and agree with your point of view. It seems to be an issue and I have added a ticket with ID SLIDESJAVA-34762 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

Hi,


Can you check this issue status?

Hi Tomasz,

I have verified from our issue tracking system and like to share that issues shared has been marked as resolved in upcoming Aspose.Slides for Java 15.4.0. We will share the feedback with you as soon as the product will be released online during May 2015.

Many Thanks,

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


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