Error trying to create a Portion within a Paragraph


#1

Sample Code :

IPortion p = new Portion();
p.setText(“Hello Aloha!”);
p.getPortionFormat().setFontHeight(10);

Version - 17.10

Error :
java.lang.ExceptionInInitializerError
at com.aspose.slides.nb.(Unknown Source)
at com.aspose.slides.nd.(Unknown Source)
at com.aspose.slides.ax.(Unknown Source)
at com.aspose.slides.y4.(Unknown Source)
at com.aspose.slides.y4.(Unknown Source)
at com.aspose.slides.BasePortionFormat.setFontHeight(Unknown Source)

Version - 18.6
Error :
java.lang.NoClassDefFoundError: Could not initialize class com.aspose.slides.z8
at com.aspose.slides.BasePortionFormat.setFontHeight(Unknown Source)


This Topic is created by sohail.aspose using the Email to Topic plugin.


#2

@kaushikranjan.___,

I have observed the information shared by you and suggest you to please try using Aspose.Slides for Java 18.6 on your end. If there is still an issue then please provide a working sample project, source presentation, Java details and Operating System details on your end. We will be able to investigate the issue further on our end on provision of requested information.


#3

@mudassir.fayyaz
I have tried out both v17 and v18. The error persists in both.
Take a look at the errors in both versions, as mentioned in the issue.

There is no source presentation. I am creating it from scratch and writing it to a file.
(Having said that, how does it matter - reading from a source ppt or creating one in memory ? )

System Config - Java v8, Ubuntu OS.


#4

@kaushikranjan,

Thank you for sharing the information. As requested earlier, please provide a working sample project reproducing the issue. The piece of code that you have shared in your above post is not complete and cannot be used to investigate the issue properly on our end. Please provide a complete working sample code that we may test on our end and try reproducing it.


#5

@mudassir.fayyaz

That is the complete code.
Using Aspose Slides Java, I am trying to create a portion, which I then plan to add to a Paragraph.

Creating a new portion, works fine. So does, adding text.
But the moment I start to make changes to the portionFormat, it starts throwing null-pointer exception.

Essentially, what I am looking for is :
If I have a text-frame, and I need to add a BRAND NEW paragraph to it with say two portions {one portion has bold text, the other has italic} - how am I supposed to do it in Java?

I will share the a sample code, by eod.


#6

@kaushikranjan,

I suggest you to please visit this documentation link for your convenience that contain the exact working sample example having multiple paragraphs and portions as per your requirement. Please feel free to share if you still have issues.


#7

@mudassir.fayyaz

Where can I find the actual Java implementation for this.

image.png (65.1 KB)


#8

@mudassir.fayyaz

If i just create try to run the following code :

   Paragraph para0 = new Paragraph();
    Portion port01 = new Portion("hello");
    port01.getPortionFormat().setFontHeight(12);
    port01.getPortionFormat().setFontBold(NullableBool.True);

    Portion port02 = new Portion("world");
    port02.getPortionFormat().setFontHeight(12);
    port02.getPortionFormat().setFontItalic(NullableBool.True);


    para0.getPortions().add(port01);
    para0.getPortions().add(port02);

I get an error :

java.lang.ExceptionInInitializerError
at com.aspose.slides.n2.(Unknown Source)
at com.aspose.slides.n4.(Unknown Source)
at com.aspose.slides.a4.(Unknown Source)
at com.aspose.slides.z8.(Unknown Source)
at com.aspose.slides.z8.(Unknown Source)
at com.aspose.slides.BasePortionFormat.setFontHeight(Unknown Source)


But if I run

   **Presentation pres = new Presentation();**
   Paragraph para0 = new Paragraph();
    Portion port01 = new Portion("hello");
    port01.getPortionFormat().setFontHeight(12);
    port01.getPortionFormat().setFontBold(NullableBool.True);

    Portion port02 = new Portion("world");
    port02.getPortionFormat().setFontHeight(12);
    port02.getPortionFormat().setFontItalic(NullableBool.True);


    para0.getPortions().add(port01);
    para0.getPortions().add(port02);

Everything runs fine.
Looks like creating a portion, is somehow search the code block for a Presentation class!!
Doesn’t make any sense to me!


#9

Also, I have examples on setting the text color.
But how can i set the background color for text in a Portion?


#10

@kaushikranjan,

I request you to please visit this documentation link again for your convenience. I have generated following presentation by using the shared sample code which involve adding portions in paragraphs.

multiParaPort.zip (20.3 KB)