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

Free Support Forum - aspose.com

java.lang.IllegalArgumentException is thrown while converting MHTML to PDF using Java

Hi I am trying to convert msg to pdf and i am getting Error Unknown Source .
i refer below mentioned link for code

Code Snippet
static void EmailToPdf(String emailPath) throws Exception

{
	   FileInputStream fstream=new FileInputStream(emailPath);
       MailMessage eml = MailMessage.load(fstream);
       //Save the Message to output stream in MHTML format
       ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
       eml.save(emlStream, SaveOptions.getDefaultMhtml());
       //Load the stream in Word document
       com.aspose.words.LoadOptions loadopt = new com.aspose.words.LoadOptions();
       loadopt.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
       System.out.println("==emlStream==="+emlStream.size());
       Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), loadopt);
      ByteArrayOutputStream foStream = new ByteArrayOutputStream();
       doc.save(foStream, SaveFormat.PDF);

}

=====Code Error===========

java.lang.IllegalArgumentException: Invalid save format requested.
at com.aspose.words.SaveOptions.createSaveOptions(Unknown Source)
at com.aspose.words.Document.zzP(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at topdf.ConvertMsgToPdf.EmailToPdf(ConvertMsgToPdf.java:75)
at topdf.ConvertMsgToPdf.main(ConvertMsgToPdf.java:29)
----Soure Code Attached—
SourceCode_With_Sample_msg_attached.zip (3.0 KB)

@vikas42329

After verifying the issue on our end, the issue seems to be occurring when working with Aspose.Words while working with saved MHTML. I have moved this thread to concerned forum where we will respond to you as soon as possible.

@vikas42329

We have tested the scenario using the latest version of Aspose.Words for Java 20.9 and have not faced the shared exception. So, please use Aspose.Words for Java 20.9.