We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get Count of Pages Sections Variables in RTF File using Java | Group Shapes in Document Header


I have an RTF document that is throwing an Exception when we try to convert to PDF. After doing some research, I can get the Exception to happen simply by trying to get a page count:

public void testDocument() throws Exception {
    String rtfName = "/some/path/bad-page.rtf";
    String pdfName = "/some/path/bad-page.pdf";
    Document document = new Document(rtfName);
    System.out.println("section count: " + document.getSections().getCount());
    System.out.println("variable count: " + document.getVariables().getCount());
    System.out.println("page count: " + document.getPageCount());
    document.save(pdfName, SaveFormat.PDF);

It will throw an Exception on the 6th line of the method. If you remove that line you get the same Exception when trying to do a save to PDF.

I am uploading a zipped sample RTF document.

What can I do to the RTF document to allow Aspose.Words to convert this RTF to PDF without errors?


Ken Kennedy

bad-page.rtf.zip (10.2 KB)


While using the latest version of Aspose.Words, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-20588. Your thread has been linked to this issue and you will be notified as soon as it will get resolved in future. Sorry for the inconvenience.

Thanks for the reply Awais.

While we wait on the fix in a newer release, what can we do to the original RTF document that will allow it to be converted into PDF using the current Aspose.Words?


As shown in this screenshot (groupshapes causing problem.png (10.1 KB)), if you remove these two GroupShape objects from the header of source RTF by using MS Word, the current version of Aspose.Words will then be able to process this RTF correctly. I have attached the modified RTF document here for your reference:

The issues you have found earlier (filed as WORDSNET-20588) have been fixed in this Aspose.Words for .NET 20.8 update and this Aspose.Words for Java 20.8 update.