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

Free Support Forum - aspose.com

Different margin on last page

Hi,

Currently I am working on setting different margin on last page only. When I use below code then it changes the margin of all pages.

builder.MoveToDocumentEnd();
PageSetup ps = builder.CurrentSection.PageSetup;
ps.TopMargin = ConvertUtil.InchToPoint(3); //Currently it sets margin to all pages


What about changing margin per pages?

I have attached the code? Could you please look into it.

Thank you,
Lakpa Sherpa



Hi Lakpa,


Thanks for your inquiry. Please note there is no page concept in Microsoft Word documents; pages are created by Microsoft Word on the fly and unfortunately there is no direct method you can use to achieve what you need. However, you may split your Document in separate pages using DocumentPageSplitter class from PageSplitter project and create a document with different sections, each page as a separate section. Later you can set page margins of any desired section as following.

You can find PageSplitter project in Aspose.Words for .NET examples repository at GitHub.

Document doc = new
Document(“Test.doc”);<o:p></o:p>

// Create and attach collector to the document before page layout is built.

LayoutCollector layoutCollector = new LayoutCollector(doc);

// This will build layout model and collect necessary information.

doc.UpdatePageLayout();

// Split nodes in the document into separate pages.

DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

// Create a new document to add each page as a separate section.

Document document = splitter.GetDocumentOfPage(1);

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

{

Aspose.Words.Document dstDoc = splitter.GetDocumentOfPage(i);

document.AppendDocument(dstDoc, ImportFormatMode.UseDestinationStyles);

}

//Set margin settings of last section

PageSetup lastpageSetup = document.LastSection.PageSetup;

lastpageSetup.TopMargin = ConvertUtil.InchToPoint(3);

lastpageSetup.LeftMargin = ConvertUtil.InchToPoint(2);

document.Save("Test_out.doc");


Best Regards,

Hi Tilal,

Thank you for above code. I downloaded the remaining code from the GitHub link you provided.

The code seems to corrupt the file. The first pages are getting repeated and the page number aren’t properly set.

Since Page concept isn’t available
* Firstly I save the file to “d:\savedoc”, the pages are OK too.
* After that I load that file to Aspose.words.Document
* Put your above changes
* Download, then the pages are corrupted

I have attached the code, please do check.

Thank you,
Lakpa Sherpa

Hi Lakpa,


Thanks for sharing additional information. We have tested the scenario with your shared document and noticed the reported issue, so logged a ticket WORDSNET-15140 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

Hi Tilal,

Is there any progress on above issue, as my project is on halt due to it. I would be very grateful if you can provide me the time estimate.

Is there any quick fix for it?

Thanking you,
Lakpa Sherpa

Hi Lakpa,


Thanks for your inquiry. I am afraid the issue is still pending for investigation as we have recently noticed the issue. We will be in a good position to share an ETA with you, as soon as the issue investigation is completed.

Thanks for your patience and cooperation.

Best Regards,

Hi Tilal,

Sorry for interrupting again. I was wondering if any progress is made in this issue.

Thanking you,
Lakpa Sherpa

Hi Lakpa,


Thanks for your inquiry. Please not initial analysis of the issue is completed and now our product team will schedule its fix as per their plans. We will notify you as soon as we get some further update.

Thanks for your patience and cooperation.

Best Regards,

Hi Tilal,
Its been like 4 months already. Could you please provide an update on it, as our project is on halt because of this issue.

Thanking you,
Lakpa Sherpa

@Lakpa_Sherpa

Thanks for your inquiry. I am afraid your reported issue is still not resolved. As our product team is busy in resolving other issues in the queue, reported earlier. However, we have recorded your concern and requested our product team to share an update. We will notify you as soon as we get a feedback.