We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Outlook msg file to tiff image

Hi Team,

I am trying to convert an outlook msg file to tiff images.
But the image in the email body is showing only half…
i am using the following code to convert.

 public static string ConvertMSGToTiff(string OutputFolder, string FullInputFileName)
{
MemoryStream msgStream = null;
MailMessage msg = null;
Document msgDocument = null;
MhtMessageFormatter mailFormat = new MhtMessageFormatter();
        <span style="color:#2b91af;">MultiPageTiffConverterUtil</span> m = <span style="color:blue;">new</span> <span style="color:#2b91af;">MultiPageTiffConverterUtil</span>();
        <span style="color:blue;">string</span> TiffFileName = <span style="color:blue;">string</span>.Empty;
      



        <span style="color:blue;">try</span>
        {

           

            <span style="color:blue;">string</span> FullconvertedMultiTiffName = <span style="color:blue;">string</span>.Empty;
          
            <span style="color:green;">// load the MSG file using Aspose.Network for .NET</span>
            msg = <span style="color:#2b91af;">MailMessage</span>.Load(FullInputFileName, <span style="color:#2b91af;">MessageFormat</span>.Msg);<span style="color:green;">//.Msg</span>
          
            msgStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();               
            msg.Save(msgStream,<span style="color:#2b91af;">MailMessageSaveType</span>.MHtmlFromat);
            
            FullconvertedMultiTiffName = <span style="color:#2b91af;">Path</span>.Combine(OutputFolder, <span style="color:#a31515;">"MSGFile.tiff"</span>);
            msgStream.Position = 0;
            <span style="color:green;">// load the MHTML stream using Aspose.Words for .NET</span>
            <span style="color:#2b91af;">LoadOptions</span> opt = <span style="color:blue;">new</span> <span style="color:#2b91af;">LoadOptions</span>();
            opt.LoadFormat = <span style="color:#2b91af;">LoadFormat</span>.Mhtml;
            
            msgDocument = <span style="color:blue;">new</span> <span style="color:#2b91af;">Document</span>(msgStream);
          
            <span style="color:#2b91af;">ImageSaveOptions</span> options = <span style="color:blue;">new</span> <span style="color:#2b91af;">ImageSaveOptions</span>(Aspose.Words.<span style="color:#2b91af;">SaveFormat</span>.Tiff);
            <span style="color:green;">//options.ImageColorMode = ImageColorMode.BlackAndWhite;</span>
            options.ImageColorMode = <span style="color:#2b91af;">ImageColorMode</span>.None;
            options.PageIndex = 0;
            options.Resolution = 300;
            options.PageCount = msgDocument.PageCount;
            
            options.ImageBrightness = .40f;
            <span style="color:green;">//options.TiffCompression = TiffCompression.Ccitt4;</span>
            options.TiffCompression = <span style="color:#2b91af;">TiffCompression</span>.None;
           
            msgDocument.Save((<span style="color:#2b91af;">Path</span>.Combine(OutputFolder, <span style="color:#a31515;">"MSGFile.tiff"</span>)),options);
           
         

            <span style="color:blue;">return</span> FullconvertedMultiTiffName;

        }
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
        {

            <span style="color:blue;">throw</span> ex;

        }<br>}<br><br>here i am attaching the msg file and the converted file.<br>Can you please help me?<br>Regards<br>Anish<br></pre><br>

Hi Anish,


Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behaviour as MS Word do. If you open the exported MHTML file into MS Word and try to save it into fixed file format e.g Pdf, you will get the same output.

Please use the following code snippet to achieve you requirement. Hope this helps you. Please let us know if you have any more queries.


Document msgDocument = new Document(MyDir
  • “in.mhtml”);

foreach (Shape shape in msgDocument.GetChildNodes(NodeType.Shape, true))

{

ResizeLargeImage(shape);

}

ImageSaveOptions options = new ImageSaveOptions(Aspose.Words.SaveFormat.Tiff);

options.ImageColorMode = ImageColorMode.None;

options.PageIndex = 0;

options.Resolution = 300;

options.PageCount = msgDocument.PageCount;

options.ImageBrightness = .40f;

options.TiffCompression = TiffCompression.None;

msgDocument.Save(MyDir + "out.tiff");

public static void ResizeLargeImage(Shape image)

{

// Return if this shape is not an image.

if (!image.HasImage)

return;

// Calculate the free space based on an inline or floating image. If inline we must take the page margins into account.

PageSetup ps = image.ParentParagraph.ParentSection.PageSetup;

double freePageWidth = image.IsInline ? ps.PageWidth - ps.LeftMargin - ps.RightMargin : ps.PageWidth;

double freePageHeight = image.IsInline ? ps.PageHeight - ps.TopMargin - ps.BottomMargin : ps.PageHeight;

ImageSize size = image.ImageData.ImageSize;

Boolean exceedsMaxPageSize = size.WidthPoints > freePageWidth || size.HeightPoints > freePageHeight;

if (exceedsMaxPageSize)

{

// Calculate the ratio to fit the page size based on which side is longer.

Boolean widthLonger = (size.WidthPoints > size.HeightPoints);

double ratio = widthLonger ? freePageWidth / size.WidthPoints : freePageHeight / size.HeightPoints;

// Set the new size.

image.Width = size.WidthPoints * ratio;

image.Height = size.HeightPoints * ratio;

}

}

Hi,
Thanks for your help,

when i use the above code to convert msg file to tiff, the special characters like (<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–><span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;color:#1F497D;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>apostrophes) are showing as question mark.

Can you please help me on this?

Regards
Anish

Hi Anish,


Thanks for your inquiry. I have tested the scenario with shared .msg file and have not found any issue while using latest version of Aspose.Words and Aspose.Email. I suggest you please use the latest version of Aspose.Words for .NET 13.5.0 and Aspose.Email for .NET 3.0.0. I have attached the output Tiff and Mhtml file with this post for your kind reference.

Hi Tahir Manzoor,

I have downloaded both the of Aspose.Words for .NET 13.5.0 and Aspose.Email for .NET 3.0.0.
And included in my application. But still special character is coming as question mark.
Please find the attached zip file. Which is having msg file and converted tif file. If you compare both the original and the converted file , you can see the question mark.

See the below code which i am using to convert .msg file to tiff.



 public static string ConvertMSGToTiff(string OutputFolder, string FullInputFileName)
{
MemoryStream msgStream = null;
MailMessage msg = null;
Document msgDocument = null;
MhtMessageFormatter mailFormat = new MhtMessageFormatter();
        <span style="color:#2b91af;">MultiPageTiffConverterUtil</span> m = <span style="color:blue;">new</span> <span style="color:#2b91af;">MultiPageTiffConverterUtil</span>();
        <span style="color:blue;">string</span> TiffFileName = <span style="color:blue;">string</span>.Empty;
      



        <span style="color:blue;">try</span>
        {

            <span style="color:blue;">string</span> FullconvertedMultiTiffName = <span style="color:blue;">string</span>.Empty;
          
            <span style="color:green;">// load the MSG file using Aspose.Network for .NET</span>
            msg = <span style="color:#2b91af;">MailMessage</span>.Load(FullInputFileName, <span style="color:#2b91af;">MessageFormat</span>.Msg);<span style="color:green;">//.Msg</span>
          
            msgStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();               
            msg.Save(msgStream,<span style="color:#2b91af;">MailMessageSaveType</span>.MHtmlFromat);
            
            FullconvertedMultiTiffName = <span style="color:#2b91af;">Path</span>.Combine(OutputFolder, <span style="color:#a31515;">"MSGFile.tiff"</span>);
            msgStream.Position = 0;
            <span style="color:green;">// load the MHTML stream using Aspose.Words for .NET</span>
            <span style="color:#2b91af;">LoadOptions</span> opt = <span style="color:blue;">new</span> <span style="color:#2b91af;">LoadOptions</span>();
            opt.LoadFormat = <span style="color:#2b91af;">LoadFormat</span>.Mhtml;
            
            msgDocument = <span style="color:blue;">new</span> <span style="color:#2b91af;">Document</span>(msgStream);

            <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">Shape</span> shape <span style="color:blue;">in</span> msgDocument.GetChildNodes(<span style="color:#2b91af;">NodeType</span>.Shape, <span style="color:blue;">true</span>))
            {

                ResizeLargeImage(shape);

            }
          
            <span style="color:#2b91af;">ImageSaveOptions</span> options = <span style="color:blue;">new</span> <span style="color:#2b91af;">ImageSaveOptions</span>(Aspose.Words.<span style="color:#2b91af;">SaveFormat</span>.Tiff);
            <span style="color:green;">//options.ImageColorMode = ImageColorMode.BlackAndWhite;</span>
            options.ImageColorMode = <span style="color:#2b91af;">ImageColorMode</span>.None;
            options.PageIndex = 0;
            options.Resolution = 300;
            options.PageCount = msgDocument.PageCount;
            
            options.ImageBrightness = .40f;
            <span style="color:green;">//options.TiffCompression = TiffCompression.Ccitt4;</span>
            options.TiffCompression = <span style="color:#2b91af;">TiffCompression</span>.None;
           
            msgDocument.Save((<span style="color:#2b91af;">Path</span>.Combine(OutputFolder, <span style="color:#a31515;">"MSGFile.tiff"</span>)),options);
           
         

            <span style="color:blue;">return</span> FullconvertedMultiTiffName;

        }
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
        {

            <span style="color:blue;">throw</span> ex;

        }<br>     }<br></pre>Can you please check this and give me a solution.<br><br>Regards<br>Anish<br>

Hi Anish,

Thanks for your inquiry. I have tested the scenario and have not found the shared issue. Please see the attached output Tiff file. Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats. I would suggest you please read the following article:

If the problem still remains, please share following detail for investigation purpose.

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • .NET Framework version

Hi Tahir,
Still this issue is not fixed for me.
Please see the below details:

  • OS - Windows XP
  • Architecture - 32 bit
  • .NET Framework version - 4.0

What i need to fix this issue in my code. Please help me.


Regards

Anish


Hi Anish,


Thanks for sharing the detail. I have tested the scenario at Windows XP (32 bit), .NET framework 4.0 and have not found the shared issue. Please find the output Tiff file in attachment. Please make sure that you are using the latest version of Aspose.Words.

Could you please convert .MSG file into MHTML and check this issue (apostrophes mark) exists in MHTML file or not? Please let us know about your findings and share the output MHTML file here for our reference.

Hi Tahir,
I am using the latest version of aspose.Words dll V13.5
Please see the attached screenshot for mhtml file.
It is also having apostrophes mark coming as question mark.

Regards
Anish

Hi Anish,


Thanks for your feedback. You have attached the screen shot of mhtml file. It would be great if you please share the output mhtml file here for our reference. This issue is related to Aspose.Email. The mhtml file is generated from .msg file by using Aspose.Email.

I am moving this forum thread to Aspose.Total forum. My colleagues from Aspose.Email will reply you shortly.

Hi Anish,


I am representative of Aspose.Email.

I converted your sample message to TIFF and MHTML and am afraid to inform that I could not re-produce the issue of question mark in place of apostrophe.

I used following code for the conversion. Sample output is attached here for your reference.

MapiMessage mapi = MapiMessage.FromFile(“E20130620000001.MSG”);
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapi.MessageClass);
MailMessage eml = mi.Interpret(mapi);
MailPrinter printer = new MailPrinter();
printer.Print(eml, “E20130620000001.tiff”, Aspose.Email.Printing.PrintFormat.Tiff);
eml.Save(“E20130620000001.mht”, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht);

Please feel free to write us back if you have any other query in this regard.