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

Free Support Forum - aspose.com

Converting MSG with PDF attachments to PDF is incorrect

I’ve been testing Aspose.Total for Java. When converting MSG file with PDF attachments to PDF I used the following code:

// Load MSG in Aspose.Email for Java
String input = ...; // input file path
FileInputStream inputStream = new FileInputStream(input);
com.aspose.email.MailMessage eml = com.aspose.email.MailMessage.load(inputStream);

// Save the Message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();

com.aspose.email.MhtSaveOptions saveOptions = com.aspose.email.SaveOptions.getDefaultMhtml();
saveOptions.setSaveAttachments(true);

eml.save(emlStream, saveOptions);

// Load the stream in Word document with Aspose.Words for Java
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);

// Save to disc
String output = ...; // output file path
doc.save(output, com.aspose.words.SaveFormat.PDF);

System.out.println("\nEmail file converted to PDF successfully.\nFile saved at " + output);

All I got was the email without attachments. What went wrong?

Are PDF attachments not supported by Aspose.Email for Java, Aspose.Words for Java or both?
What formats of attachments in MSG are supported?
What are alternative actions in Aspose.Total for Java to handle this case?

I was using Aspose.Email for Java 21.5, Aspose.Words for Java 21.6 and JDK 1.8.

@rpAspose,
Welcome to our community! Thank you for the issue description. Please check the problem with the latest version of Aspose.Email. If the issue persists, please share the following:

  • input MSG file
  • output PDF file
  • screenshot demonstrating the problem

Hi Andrey, I’ve tried latest Aspose.Email for Java (21.6) and Aspose.Words for Java (21.7) and still PDF attachment in MSG file is not added to PDF output (ie. output contains only mail). I have attached both input and output file in the following ZIP.

TestMSG2PDF.zip (160.2 KB)

I’ve also tried to use BMP attachment instead of PDF and the output contained both email and BMP. So this lets me think that either there is a bug when PDF attachments are added or PDF attachments are not supported attachment format in one of the Aspose module. If the later is true, is there another way with Aspose.Total for Java to achieve desired result?

@rpAspose,
Far as I know, Aspose.Email does not restrict attachment types. PDF attachments must be supported. I reproduced the problem and logged the issue with ID EMAILJAVA-34923 in our tracking system. Our development team will investigate this case. I will inform you of any progress.

I have saved email and PDF attachment separately with Aspose.Email for Java to MHTML and PDF respectively and then used Aspose.Words for Java to join the two files with com.aspose.words.Document class constructor (MHTML) and appendDocument() method (PDF). I got this error when trying to append PDF:

Error:com.aspose.words.UnsupportedFileFormatException:Pdf format is not supported on this platform. Use .NET Standard or .NET 4.6.1 version of Aspose.Words for loading Pdf documents.

I guess this is the reason PDF was not included with the initial code? I gather that until PDF is supported on Java we would probably need Aspose.PDF for Java to join email and PDF attachments?

@rpAspose,
It seems that this error is not related to Aspose.Email. Aspose.Email does not change the content or data of attachments while extracting them. But you can describe this case on Aspose.Words Product Family forum if you can isolate it from Aspose.Email. We need some time to investigate the initial issue.

@rpAspose,
If you save the MSG file as an MHTML file, you can see that the PDF attachment is inside the MHTML file attachment_internal.png (60.3 KB). Unlike images, PDF attachments in MHTML files are not displayed, for example, by browsers attachment.png (16.0 KB). Therefore, the PDF attachment is not displayed in the PDF output file either.