Free Support Forum -

Converting Mht to Tiff: how to avoid paging?


I use Aspose.Words .NET 11.8 to convert Mht files to Tiff. Code is the next:

Dim msgDocument As Document

msgDocument = New Document(msgStream)

a.TiffCompression = Saving.TiffCompression.Lzw

a.Resolution = 300

a.PrettyFormat = True

msgDocument.Save(sourceFile & ".tiff", a)

Result Tiff file contains few pages, but I need to convert to single page. Is there any way to skip document paging and save document to one picture? (In other words, make one big picture from document WebLayout?)

Thanks in advance.

WBR Maksim Sterekhov.

Hi Maksim,

Thanks for your inquiry. Please try running the following code snippet which first saves individual pages of Html Document to separate image streams and then combine all those Bitmap objects into one tall Tiff file:

Document doc = new

PageSetup ps = doc.FirstSection.PageSetup;

ps.BottomMargin = 0;

ps.TopMargin = 0;

ps.LeftMargin = 0;

ps.RightMargin = 0;

ps.HeaderDistance = 0;

ps.FooterDistance = 0;

List<Image> images = new List<Image>();

int bigImageWidth = 0;

int bigImageHeight = 0;

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);

options.PageCount = 1;

// Save each page of the Html as Jpeg.

for (int i = 0; i < doc.PageCount; i++)


options.PageIndex = i;

using (MemoryStream imgStream = new MemoryStream())


doc.Save(imgStream, options);

imgStream.Position = 0;

using (Bitmap bmp = new Bitmap(imgStream))


images.Add(new Bitmap(imgStream));

bigImageWidth = (bigImageWidth < bmp.Width) ? bmp.Width : bigImageWidth;

bigImageHeight += bmp.Height;





using (Bitmap bigImage = new Bitmap(bigImageWidth, bigImageHeight))


using (Graphics gfx = Graphics.FromImage(bigImage))


int x = 0;

int y = 0;

foreach (Image img in images)


y += img.Height;

gfx.DrawImage(img, new Point(x, y));




bigImage.Save(@"C:\Temp\out.Tiff", ImageFormat.Tiff);


I hope, this helps.

Best Regards,

I tried your approach, but result is still bad. Please look at sample files in attach.

First of all, there is a big blank space at the top of the Sample.mht.tiff. Second issue: screenshort and the End of message is absent. I added to your code iteration throught Document Sections (I seems like picture is in other document section) but result is actually the same. May be there is sometyhing I missed?

Hi Maksim,

Thanks for your inquiry. I think, in this case, calling Document.UpdatePageLayout method after loading the document into DOM will help. Please use the following line in your code:

Document doc = new


PageSetup ps = doc.FirstSection.PageSetup;



Best regards,

Thanks, this really works. But result image still is not accurate.

I selected big blank spaces on Sample.tiff. I think they appeard due to document was divided on pages. I changed property

Document.DocumeViewOptions.ViewType = Settings.ViewType.Web

And then call Document.UpdatePageLayout but this affects nothing.

Hi Maksim,

Thanks for your inquiry. Well, please note that Html based formats are not paginated. The code, that is suggested in this thread, is simply rendering each page of Word document (i.e. Html loaded into Aspose.Words’ DOM) to individual images and then combining all those images into a one tall image using GDI+. This is the expected behaviour. If we can help you with anything else, please feel free to ask.

Best regards,