Saturday, January 07, 2006

Alternate to PDF

Most of the time our client wants report to be light weight and easily opened. If we use PDF, it needs Abode Reader to open PDF documents. So to over come this problem, here is the solution, MHTML. MHTML files store images and text in single file as MS Word does. To Open MHTML files, you need Internet explorer or MS Word 2000 and above.

How to create MHTML?
Easy, Just pass the URL to this method


public static bool SaveWebPageToMHTFile( string url, string filePath)
{
bool result=false;
CDO.Message msg = new CDO.MessageClass();
ADODB.Stream stm=null ;
try
{
msg.MimeFormatted =true;
msg.CreateMHTMLBody(url,CDO.CdoMHTMLFlags.cdoSuppressNone, "" ,"" );
stm = msg.GetStream();
stm.SaveToFile(filePath,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
msg=null;
stm.Close();
result=true;
}
catch
{throw;}
finally
{
//cleanup here
}return result

No comments: