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

Free Support Forum - aspose.com

Margins in conversion from mht to pdf

I am evaluating Aspose.Words for conversion of .mht to .pdf. We get the mht from a service in a stream. I am converting using VB10 now, but for production the Java version needs to be used.

I have added by conversion steps in the attached ConvertAspose.txt file. It contains a line to set the LeftMargin to -2. With this value (or with value 2) the text is moved 2 inch to the left. With zero there is no left margin.

Being a new user, there might be some optimalization possible (can I do conversion without writing the mht file??). I have also added an mht file that represents the content we need to convert.

I'm using Aspose .Net 2.0 library in a .Net 4.0 application in my VB evaluation.

Hi Adrie,

Thanks for your inquiry.


there might be some optimalization possible (can I do conversion without writing the mht file??).

Yes, you can load the mhtml file from stream into Aspose.Words DOM. Please read following documentation link.

Please also check the Document’s constructors from here:

Regarding MHTML to PDF conversion issue with left margin, please note that Aspose.Words mimics the same behavior as MS Word does. Please load your mhtml file into Aspose.Words, set the left margin and convert it to Pdf, you will get the same output.

The reason of this behaviour is that the width of first table in mhtml file is greater then the width of A4 size. I suggest you following two solutions for this case.

1) Set the page orientation as landscape or 2) set the page width as 794 (same width of table).

Hope this helps you. Please let us know if you have any more queries.

section.PageSetup.Orientation = Aspose.Words.Orientation.Portrait

section.PageSetup.PaperSize = PaperSize.A4

section.PageSetup.LeftMargin = -2

section.PageSetup.PageWidth = 794

section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape

section.PageSetup.PaperSize = PaperSize.A4

section.PageSetup.LeftMargin = -2

Thanks, got things solved. Used MemoryStream instead of FileStream to solve the exstra file problem. Works as we want it now.

Hi Adrie,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.