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

Free Support Forum - aspose.com

Setting the Margin info for version 11.7.0.0 on either Word or Pdf

Hi,

I’m working on a project where we need to create a .tif file from HTML. Currently we are using the Word dll and having trouble with the margins being to big.

We are using the .net version 11.7.0.0 of Aspose Word. My company has a long term plan to upgrade because we really need the new CSS/Html support in the PDF DLL. For the short term though how would I set the Margin information on a Word document? None of the example code seems to work because its all for a newer version.

The closest I could get was to try using the PDF dll where I found a PageInfo object, but I can’t figure out where to plug that into the PDF document because I can’t find any sections on it like the documentation says there should be.

How would I set this margin information for either Word or Pdf?

Thank you for your help

Just figured it out for the document. I needed to use the DocumentBuilder object then I was able to set the margin properties:

var options = new LoadOptions { LoadFormat = LoadFormat.Html, }; 
var document = new Aspose.Words.Document(stream, options); 
var docBuilder = new DocumentBuilder(document); 
docBuilder.PageSetup.BottomMargin = docBuilder.PageSetup.TopMargin = docBuilder.PageSetup.RightMargin = docBuilder.PageSetup.LeftMargin = 5; 
document = docBuilder.Document;

Hi Steven,

Thanks for your inquiry. It is nice to hear from you that you have found the solution of your query. You can also achieve your requirements by iterating through all sections of document and set page margins. Please check the following code snippet.

Document doc = new Document(MyDir + "in.html");
foreach (Section section in doc.Sections)
{
    section.PageSetup.LeftMargin = 5;
    section.PageSetup.TopMargin = 5;
    section.PageSetup.RightMargin = 5;
    section.PageSetup.BottomMargin = 5;
}

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

Thank you for showing an alternative way to do it.

Follow up question what would the equivalent code be for the PDF document for this same code version?

Thank you

Hi Steven,

Thanks for your inquiry. You can use the same code for input Word and html documents. Please read about Aspose.Words Load Formats from here:
https://reference.aspose.com/words/net/aspose.words/loadformat/

If you want to use Pdf file as input and resize page content, please read following documentation link. Hope this helps you.
https://docs.aspose.com/pdf/net/working-with-pages/

Aspose.Pdf for .NET is a PDF document creation component that enables your .NET applications to read, write and manipulate PDF documents without using Adobe Acrobat. Please post your queries related to Aspose.Pdf in Aspose.Pdf forum.