Aspose Words Save Options PDF

Hi.

I am using Aspose Words aspose-words-17.7-jdk16

I have a large (31MB) file that I am trying to convert to PDF:

var pdfDoc = new com.aspose.words.Document(new java.io.ByteArrayInputStream(qie.base64DecodeToBytes(<Base64RTF>)));
pdfDoc.save(path, com.aspose.words.SaveFormat.PDF);

But I get a Heap Space error. I have tried to use the following code to optimise

PdfSaveOptions = new com.aspose.words.DocSaveOptions();
PdfSaveOptions.setSaveFormat(com.aspose.words.SaveFormat.pdf);
PdfSaveOptions.setTempFolder("C:\Temp");

pdfDoc.save(path, PdfSaveOptions);

However, I now get another error about PDF type not being allowed:

java.lang.IllegalArgumentException: An invalid SaveFormat for this options type was chosen.

Any idea what is wrong?

@swy DocSaveOptions is for DOC format. If you need to save document as PDF, you should use PdfSaveOptions. Please also see our documentation for more information about conversion document to PDF:
https://docs.aspose.com/words/java/convert-a-document-to-pdf/

1 Like

Thank you for pointing out my mistake!!

I no longer get the original error, but now get a HeapSpace error despite the PdfSaveOptions. Is there any way to configure the amount of memory allocated to Aspose?

@swy Aspose.Words always allocates more memory that actual document size. This is expected. Please see our documentation for more information:
https://docs.aspose.com/words/net/memory-requirements/
For reducing memory usage upon processing extremally large documents, you can try using LoadOptions.TempFolder, SaveOptions.TempFolder and SaveOptions.MemoryOptimization properties.
Also, you can try increasing the heap space available in your environment.