Email headers in our own language when converting to PDF

Hi,


I have a question. We use aspose to convert a email to a pdf. Which is working fine with the exception that we like to have the fields (such as To: From: Subject etc.) in our own language (Dutch). Is that possible?

To convert the email I use the code as given below.

Thanks in advance.
Gerard.


MailMessage eml = MailMessage.load(inputStream);
AttachmentCollection attachments = eml.getAttachments();
// 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);
com.aspose.words.Document doc = new Document(newByteArrayInputStream(emlStream.toByteArray()), lo);
doc.save(fileDest.getAbsolutePath(), SaveFormat.PDF);

Hi Gerard,


Thank you for writing to Aspose Support team.

There is no direct method to set the language of headers. However, you can use the MhtMessageFormatter to specify these fields in your desired language while converting to MHTML. Please give it a try at your end and let us know your feedback.

Sample Code:

<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>MailMessage msg = MailMessage.load(“test.eml”);

MhtMessageFormatter messageformatter = new MhtMessageFormatter();

messageformatter.setFromFormat(messageformatter.getFromFormat().replace(“From:”, “Da:”));

messageformatter.setSentFormat(messageformatter.getSentFormat().replace(“Sent:”, “Inviato:”));

messageformatter.setSubjectFormat(messageformatter.getSubjectFormat().replace(“Subject:”, “Oggetto:”));

messageformatter.setToFormat(messageformatter.getToFormat().replace(“To:”, “A:”));

messageformatter.setCcFormat(messageformatter.getCcFormat().replace("??:", “Cc:”));

messageformatter.setImportanceFormat(messageformatter.getImportanceFormat().replace(“Importance:”, “Importanza:”));

messageformatter.setBccFormat(messageformatter.getBccFormat().replace(“Bcc:”, “Ccn:”));

messageformatter.setAttachmentFormat(messageformatter.getAttachmentFormat().replace(“Attachments:”, “Allegati:”));

messageformatter.format(msg);

Hi Kashif Iqbal,


When I add the suggested code I get the English header and Dutch headers, but I want only the headers with the dutch prefixes.

I assume that the call to mailmessage.format() adds the dutch header to the message and when calling MailMessage.save (as shown in mine code in the first post) the english headers are also added.

How can I get the mailmessage with only dutch prefix? The API is very bad documented so I can not find how to solve this problem.

With kind regards,

Gerard.

Hi Gerard,


We are sorry for the inconvenience you have faced.

Please use the MhtSaveOptions in order to avoid writing the original header in the output MHTML as shown in the following code sample. Please let us know if you need any further assistance in this regard.

Sample Code:

<pre style=“font-family: “Courier New”; font-size: 9pt;”><pre style=“font-family: “Courier New”; font-size: 9pt;”>messageformatter.format(msg);

MhtSaveOptions saveOptions =
new MhtSaveOptions();
saveOptions.setMhtFormatOptions(MhtFormatOptions.None);
msg.save(
“800295\test.mhtml”,saveOptions);