Presentation Throws a PptxException when Saving as PDF in Java

The exception thrown is"com.aspose.slides.PptxException: Can’t assign string which contains paragraph break character"
Saving the ppt as pptx everything works as expected.
I will attach the presentation together with a Java code example to reproduce the issue:L
PptWithComment.zip (32,2 KB)

@Tim49,

Thanks for the template PowerPoint presentation file.

After initial testing, I was able to reproduce the issue as you mentioned by using your sample PowerPoint presentation file and sample code snippet. I found an exception “com.aspose.slides.PptxException: Can’t assign string which contains paragraph break character”.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39557

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Tim49,

We evaluated your issue in details. The exception occurs because the text contains line break character. This usually means that the text was not formed correctly. To fix this exception please use the following code snippet:

final String PPT_WITH_COMMENT = folderPath + "PptWithComment.ppt";

Presentation presentation = null;
try {
    presentation = new Presentation(PPT_WITH_COMMENT);

    replaceLineBreakInComments(presentation);

    HandoutLayoutingOptions handoutLayoutingOptions = new HandoutLayoutingOptions();
    handoutLayoutingOptions.setHandout(HandoutType.Handouts3); // Default value is
    // <b>HandoutType.Handouts6Horizontal</b>.
    handoutLayoutingOptions.setPrintComments(true); // Default value is <b>false</b>. but true is
    // needed if comments shall be printed. See
    // comment at the end of the file
    handoutLayoutingOptions.setPrintFrameSlide(true); // Default value is <b>true</b>.
    handoutLayoutingOptions.setPrintSlideNumbers(true); // Default value is <b>true</b>.

    NotesCommentsLayoutingOptions commentsLayoutingOptions = new NotesCommentsLayoutingOptions();
    commentsLayoutingOptions.setCommentsPosition(CommentsPositions.Bottom);
    // commentsLayoutingOptions applies only if comments are displayed on the right)
    // commentsLayoutingOptions.setCommentsAreaWidth(150);
    commentsLayoutingOptions.setShowCommentsByNoAuthor(true);

    PdfOptions pdfSaveOptions = new PdfOptions();
    // comment layout options must be set before the handout layout options
    pdfSaveOptions.setSlidesLayoutOptions(commentsLayoutingOptions);
    pdfSaveOptions.setSlidesLayoutOptions(handoutLayoutingOptions);

    presentation.save(folderPath + "PptWithComment.pdf", com.aspose.slides.SaveFormat.Pdf, pdfSaveOptions);
    System.out.println("Saved PptWithComment.pdf");
} catch (Exception e) {
    System.err.println("Could not process " + PPT_WITH_COMMENT + ": " + e.getClass()+ ": " + e.getMessage());
} finally {
    if (presentation != null) {
        presentation.dispose();
    }
}

static void replaceLineBreakInComments(Presentation presentation)
{
    for (ICommentAuthor commentAuthor : presentation.getCommentAuthors())
    {
        CommentAuthor author = (CommentAuthor) commentAuthor;
        for (IComment comment1 : author.getComments())
        {
            Comment comment = (Comment) comment1;

            if (comment.getText() != null && !"".equals(comment.getText()))
            {
                if (comment.getText().contains("\r"))
                {
                    comment.setText(comment.getText().replace("\r", ""));
                }
            }
        }
    }
}

Let us know your feedback.

Hi amjad.sahi,
as you pointed out calling the method replaceLineBreakInComments(presentation) you provided did solve the problem. The presentation can now be saved as PDF without a problem. Thanks!

But in my oppinion this is just a workaround. Do you plan to fix the issue in future, so that the workaround will be obsolete than?

@Tim49,

It is good to hear that your problem has been resolved by utilizing the recommended sample code.

We will evaluate it and get back to you with updates on it.

@Tim49,

According to the logic of the PowerPoint, each such break should be presented as a separate portion of text. But as we can see in the provided presentation, this is not the case. This is an incorrectly created portion of text and it is simply impossible to foresee all such erroneous combinations of characters in portion and create a universal handler. That’s why, you have to use the workaround to figure your issue out.