Free Support Forum - aspose.com

MSG to PDF: set font in text only mails

Hi,

if you convert text-only-mails from msg to pdf, a serif font is used in pdf. Outlook uses sans-serif font on our environment. Is there a possibility to set a standard-font for conversion?

Best regards,

Josef

@dvtdaten,

Thank you for contacting Aspose support team.

We are gathering information in this regard and request you to spare us little tile for sharing our feedback.

@dvtdaten,

We have logged this enhancement request under Id:EMAILNET-39008 in our issue tracking system. We will write back here as soon as some feedback is ready to share.

@dvtdaten,

Could you please share how messages are generated in this case? We need some sample message files and the method with which you are creating these to further workout any such implementation.

Hello,

see attached example: example.zip (70.7 KB)

Output Aspose: Serif Font
Output Outlook: Non Serif Font

It would be great to set the font which is used converting the mail.

Code:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
ByteArrayInputStream bais = null;
MhtSaveOptions mhtmlSaveOptions = SaveOptions.getDefaultMhtml();
mhtmlSaveOptions.setMhtFormatOptions(0);
mapiMessage.save(baos, mhtmlSaveOptions);
bais = new ByteArrayInputStream(baos.toByteArray());
Document doc = new Document(bais, getDocLoadOptions());
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_A_1_B);
options.setOptimizeOutput(true);
doc.save(baos2, options);
return baos2.toByteArray();

Thanks in advance.

@dvtdaten,

Many thanks for the update. We’ll look into it further.

The issues you have found earlier (filed as EMAILNET-39008) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal

How can we use the new feature setting the font for text only?

@dvtdaten,

You can use it as shown in the following sample code.

MhtSaveOptions options = SaveOptions.DefaultMhtml;
int cssInsertPos = options.CssStyles.LastIndexOf("</style>");
options.CssStyles = options.CssStyles.Insert(cssInsertPos,
	".PlainText{" +
	"    font-family: sans-serif;" +
	"}"
	);

msg.Save("message.mhtml", options);

The solution in version 18.7 isn’t useful without this example :wink: - maybe you add it to the hints for using Aspose.Email.

Thanks for help.

If I do not display your Headers, it does not work.

For example if I set
mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.HideExtraPrintHeader);

or

mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.None);

Why?

@dvtdaten,

We have reopened this issue for further consideration at our end and will let you know about any further updates in this regard.

The issue is resolved again? In which version it will be fixed (java)?

@dvtdaten,

We were unable to reproduce the issue using the latest version Aspose.Email for Java API. We generated two PDF files by manually setting the font to serif and sans-serif. The generated output files are attached. The code used to generate these output files is given below.

sansSerifMessage.pdf (18.4 KB)
serifMessage.pdf (21.0 KB)

MapiMessage mapiMessage = new MapiMessage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = null;
MhtSaveOptions mhtmlSaveOptions = SaveOptions.getDefaultMhtml();
mhtmlSaveOptions.setMhtFormatOptions(MhtFormatOptions.None);
mhtmlSaveOptions.setCssStyles("<style>.PlainText{" +
    "    font-family: sans-serif;" +
    "       color: red;" +
     "} </style>");
mhtmlSaveOptions.setMhtFormatOptions(0);
mapiMessage.setBody("TEST Message");
mapiMessage.save(baos, mhtmlSaveOptions);
bais = new ByteArrayInputStream(baos.toByteArray());
Document doc = new Document(bais);
PdfSaveOptions poptions = new PdfSaveOptions();
poptions.setCompliance(PdfCompliance.PDF_A_1_B);
poptions.setOptimizeOutput(true);
doc.save("FileName", poptions); 

We hope that this resolved the issue you were facing. Please feel free to contact us if additional information is required.

I cannot view the pdf’s: “Sorry, this file is private. Only visible to topic owner and staff members.”

I will try again, but it did not work the last time without displaying headers.

@dvtdaten,

I have uploaded the files to dropbox. You may download these files using the links given below.

Thanks, it works with the newest version. I could not find any info in release notes about that.

@dvtdaten,

It is good to know that your issue has been resolved. If additional information is required, please free to contact us. We will be more than happy to assist you further.