How to convert email to pdf using android java sdk?

How to convert email to pdf using android java sdk? Both msg and eml formats are compatible. I wrote this code in the conversion of eml pdf can not open? Ask a community technician to help me

    public static void email2PDF(String inpath){
        try {
            License license = new License();
            InputStream open = new FileInputStream(new File("/data/data/com.example.wordpdf2/test/Aspose.Total.Product.Family.lic"));
            license.setLicense(open);

            MailMessage mailMessage = MailMessage.load(inpath);
            mailMessage.save(mailMessage+".pdf");

            open.close();
        }catch (Throwable throwable){
            throwable.printStackTrace();
        }

    }

Hello @wangyiqun,

Welcome to our support forum!

Unfortunately, Aspose.Email does not support direct conversion from eml to pdf. You should save eml to intermediate MHT format and then use Aspose.Words to save it to pdf:

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
LoadOptions lo = new LoadOptions();

lo.setLoadFormat(LoadFormat.MHTML);

Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);

//Save to pdf
doc.save("About Aspose.Pdf", SaveFormat.PDF);

I tried your code, but didn’t convert email file successully. Here is my input and output.
inputAndoutput.zip (6.8 KB)

Hello @wangyiqun ,

Could you please share with us the original EML or MSG file for testing the conversion issue?
Please also specify the version of the Aspose.Email you are using. Please add more information about the Android environment you are working in.