Convert Email File to MHTML, EML to PDF/A | Retain From Email Address & Set Sender Time Format using Aspose Java Code

While trying to deal with conversion with Aspose.TOTAL java API, from any message to PDF/A-2, we notice the below discrepancies and issues -

  1. The sender from section contains only, the sender name and the sender email address does not appear in the converted PDF.

  2. The time-zone gets converted from a 12-hour time format to 24-hours format while conversion to PDF.

Can you please let us know how to preserve -

  1. the displaying of email address also in from section, after conversion to pdf.
  2. preserve the same time-format while conversion to pdf. If the time format is 12 hour in the input email, then PDF should display the time in 12-hour format as well.

Thanks a lot in advance for all your feedback and support into the same.

Below is the code snippet we use for the same.



ByteArrayOutputStream stream = new ByteArrayOutputStream();
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_A_1_B);
try {
InputStream docStream = new FileInputStream(new File(“D:\temp\input.eml”));
MailMessage eml = MailMessage.load(docStream);

		// Save the Message to output stream in MHTML format
		ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
		eml.save(emlStream, com.aspose.email.SaveOptions.getDefaultMhtml());
		//eml.save(emlStream, saveOptions);
		//eml.save(emlStream);
		// Load the stream in Word document
		LoadOptions loadOptions = new LoadOptions();
		
		// lo.setFontSettings(msDocFontsSettings);
		loadOptions.setLoadFormat(LoadFormat.MHTML);
		Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), loadOptions);
		// or Save to stream
		doc.save(stream, options);
	} catch (Exception e) {
		e.printStackTrace();
	}

convertPDFToPDFA2(new ByteArrayInputStream(stream.toByteArray()));

private static void convertPDFToPDFA2(ByteArrayInputStream byteArrayInputStream) {
try {
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(byteArrayInputStream);
pdfDocument.convert(“pdfConversion_log.xml”, PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);
pdfDocument.save(“D:\temp\output.pdf”);

		System.out.println("conversion complete.");

	} catch (Exception e) {
		e.printStackTrace();
	}

}<a class="attachment" href="/uploads/default/43352">AsposeEmailSMimeToPdf.zip</a> (1.4 KB)

@jitendriya.dash,

Please ZIP and attach the following resources here for testing:

As soon as you get these pieces of information ready, we will start further investigation into your particular scenario/issue and provide you more information.

Thanks, at the moment, we are able to deal with a technique to set the from email adresses explicitly to the email object by using eml.setFrom(MailAddress mailAddress) where we get this from email object first, get the email address only and set them back.

On the auto-conversion to 24-hour clock for the date format from 12-hour format, it is accepted by the business. Hence nothing to be done here.

Thanks for all your support. You can close this case.

@jitendriya.dash,

It is great that you were able to workaround/fix these problems on your end. Please let us know any time you may have any further queries in future.