Email to PDF: image attachment in mail body

test.zip (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.email.MailMessage;
import com.aspose.email.SaveOptions;
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();
    eml.save( baos, SaveOptions.getDefaultMhtml() );

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

@depi

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 );
eml.save( baos, so );

This fixes our problem!

@depi

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.