Performance concerns regarding RTF to PDF conversion using Aspose.Words

I am using Aspose.words Java for RTF to PDF conversion and there is performance issue due to more time taken by the conversion code. Below is the the code:

Document document = new Document(input);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setUseCoreFonts(true);
document.save(outfile,saveOptions);

Could you please suggest how the performance can be improved?

@GurdeepRallan

We suggest you please try the latest version of Aspose.Words for Java 19.7. Hope this helps you.

If you still face problem, please attach your input RTF document here for testing. We will investigate the issue on our side and provide you more information.

aspose.zip (2.6 KB)
Attached zip contains sample RTF documents.

@GurdeepRallan

Thanks for sharing the document. We are investigating this issue and will share our findings soon.

@GurdeepRallan

We have tested the scenario using the latest version of Aspose.Words for Java 19.7 at Windows 10 with Java 8. We have not found the shared issue. So, please use Aspose.Words for Java 19.7.

Tried 19.7 version aspose-words-19.7-jdk17.jar with Java 8. It is causing below error:

Exception in thread “Thread-1” java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.aspose.words.internal.zzBQ.memberwiseClone(Unknown Source)
at com.aspose.words.internal.zzBQ.zzAn(Unknown Source)
at com.aspose.words.zz6.zzqB(Unknown Source)
at com.aspose.words.zzZ16.zzgI(Unknown Source)
at com.aspose.words.zzZ1R.zzZ(Unknown Source)
at com.aspose.words.zzZ1G.zzZ(Unknown Source)
at com.aspose.words.zzZ07.zz9(Unknown Source)
at com.aspose.words.zzZ07.zz8(Unknown Source)
at com.aspose.words.zzZ07.zzT(Unknown Source)
at com.aspose.words.zzZ07.read(Unknown Source)
at com.aspose.words.Document.zzY(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at AsposeRtfToPdf$ProducerThread.run(AsposeRtfToPdf.java:69)
at java.lang.Thread.run(Unknown Source)

No such error with aspose-words-19.6-jdk17.jar

With aspose-words-19.6-jdk17.jar, the conversion of RTF to PDF is taking approximately 4200 ms on windows with Java 1.8.
Using same RTF samples shared earlier. We have the performance issues with more time taken by conversion.

@GurdeepRallan

In your case, we suggest you please increase the heap size at your side to avoid this issue. Hope this helps you.

Heap size increase in case of which version of aspose? 19.6 or 19.7?

@GurdeepRallan

Please use the latest version of Aspose.Words for Java 19.7.

What should be the minimum heap size ?

@GurdeepRallan

The heap size depends on your requirement. Please note that performance and memory usage all depend on complexity and size of the documents you are generating.

Sometimes Aspose.Words for Java throws OutOfMemoryError on Java. This is because the default Java heap space might not be enough for high memory spikes when processing some documents. In this case, the easy way to workaround is to increase the heap space for the JVM.

Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

aspose-words-19.7-jdk17.jar gives OOM with heap size 12 GB and RTF documents size 5-6 kb (shared earlier).
Below is the code:
Document document = new Document(input);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setUseCoreFonts(true);
document.save(outfile,saveOptions);

@GurdeepRallan

We tested the scenario using Intellij IDE and did not face this issue. Could you please share the steps that you are using to reproduce this issue at our end? Please also share the IDE that you are using.

On Linux:
Java version 1.8
Aspose version 19.7
Heap Size 12 GB
Compile and run the code using
javac -cp aspose-words-19.7-jdk17.jar AsposeRtfToPdf.java
java -cp aspose-words-19.7-jdk17.jar AsposeRtfToPdf

Document document = new Document(input);             // input is ByteArrayInputStream
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setUseCoreFonts(true);
    document.save(outfile,saveOptions);                                  // outfile is ByteArrayOutputStream

On windows:
IDE: Eclipse
Java version 1.8
Aspose version 19.7
Run as java application to run the java code in eclipse.
Increased heap size in run configuration arguments.

The issue is on linux and windows both.

Could you please share your code sample?

@GurdeepRallan

We have tested the scenario again using Eclipse IDE and have not faced any issue.

We have used the same code as of yours to test this case.

The input document has size 6KB and its content is only text. So, OutOfMemoryError should not be thrown. Please make sure that you are using the same input RTF.

Moreover, please export some different documents to PDF at your end and let us know if you still face the same issue.

Same issue with different RTF documents. Attached is my complete code.RTFCode.zip (14.9 KB)

RTF document is base64 string which is decoded and passed as ByteArrayInputStream to the conversion code.

If I give path of RTF document, it works without any issues.

Document document = new Document(“test.rtf”);

Issue is in case of ByteArrayInputStream.

Document document = new Document(input); //input is ByteArrayInputStream

@GurdeepRallan

Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.