Email to PDF: image attachment in mail body (540.7 KB)
When converting an email (msg file) with an image attachment to PDF, the attachement is included in the mail body. Other attachments do not show this behavior

Sample code:

import com.aspose.words.Document;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.PdfSaveOptions;
import com.aspose.words.SaveFormat;

try ( InputStream fis = new FileInputStream( source ) ) {
    // convert to MHTML
    MailMessage eml = MailMessage.load( fis );
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos, SaveOptions.getDefaultMhtml() );

    // convert to PDF
    LoadOptions lo = new LoadOptions();
    lo.setLoadFormat( LoadFormat.MHTML );
    Document doc = new Document( new ByteArrayInputStream( baos.toByteArray() ), lo ); target.getAbsolutePath(), SaveFormat.PDF );


We have tested the scenario and have not found any issue with output PDF. Could you please share some more detail about the issue that you are facing? Please also share your expected output MHTML and PDF. We will then provide you more information about your query.

test-output.pdf (960.7 KB)
output.png (160.4 KB)

We expected that in the PDF only the Mail Body is displayed and not the attachments. This is the case with a picture type.
The mail attachments are converted into an additional step or saved as a PDF attachment.
For images, these are then duplicated.
Can one omit the images?

We can use:
MhtSaveOptions so = SaveOptions.getDefaultMhtml();
so.setSaveAttachments( false ); baos, so );

This fixes our problem!


It is nice to hear from you that your problem has been resolved. Please feel free to ask if you have any question about Aspose APIs, we will be happy to help you.