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

Free Support Forum - aspose.com

Different Margin for First and Last Page in DOC file

Aspose_DiffMargin.zip (9.4 MB)
Hi,
There seems to be a problem when setting different margin for First and Last page. When the first page content goes to second page, then the margin of first page is similar to second page. Similar question was asked in 2013, Specify page margins when printing , but the suggested solution ( reduce the text font size, increase the Section height or may be reduce vertical spacing ) is not acceptable in our case.

Aspose version: 18.6

Is there an alternative solution to it. Please check the attached code for the issue.

Thanking you,
Lakpa Sherpa

@Lakpa_Sherpa,

Please see Generated-Docs.zip (22.4 KB)

What problems do you see in attached final.doc? From this final.doc, please create your expected document by using Microsoft Word. We will investigate the structure of your expected document as to how you want your final output be generated like.

Hi,
Please see modified Generated-Docs.zip (43.0 KB) . final-Needed.doc is the format that I want.

When a page splits into two pages, I want margin to be applied only to first one, not both of them.

@Lakpa_Sherpa,

We are checking this scenario and will get back to you soon.

@Lakpa_Sherpa,

I think, you can implement the following workflow to get the desired output:

1- Use the following code to convert each page of input Word document (generated in STEP1) to a separate PDF file (this is because PageSplitter utility does not produce expected results)

Document doc = new Document(@"D:\Temp\intermediate.doc");

int pageCount = doc.PageCount;
PdfSaveOptions opts = new PdfSaveOptions();
opts.PageCount = 1;
for (int i = 0; i < pageCount; i++)
{
    opts.PageIndex = i;
    doc.Save(MyDir + @"18.6-" + i + ".pdf", opts);
}

2- Use Aspose.PDF for .NET to convert each one Page PDF to separate Word documents:
Convert PDF to DOC or DOCX format

3- Adjusting Top margin with Aspose.Words on first-page Word document will push some content to second page. You then need to repeat 1) and 2) for this document. This will again result in two word documents.

4- Similarly, adjusting the Top margin on last-page Word document will push some content to second page. You then need to repeat 1) and 2) for this document as well. This will again result in two (or more) word documents.

5- For the documents produced in 3) and 4), use Aspose.Words to just remove Top margins from all documents other than the documents corresponding to first and last pages.

6- Append all Word documents in correct order by using Aspose.Words for .NET.

Hi,
I followed your steps but I landed in different issue. I found out that those DOC aren’t editable friendly and instead of splitting the pages its overlaps at the end of page. Please see the ReadMe.docx for further details.

Test.zip (808.2 KB)

Thanking you,
Lakpa Sherpa

@Lakpa_Sherpa,

I am afraid, the PageSplitter utility is quite complex. It works for simple documents but cannot always produce expected results.

In Aspose.Words for .NET, we can use built-in FixedPageSaveOptions.PageIndex and FixedPageSaveOptions.PageCount properties together to correctly Save each page of Word document into separate fixed-page format file (PDF etc).

Similarly, we have logged an issue in our issue tracking system (ID: WORDSNET-16228) to provide built-in ability to do the same for flow formats (DOCX, DOC, RTF etc). These properties would then be moved in SaveOptions base class.

We are currently able to convert any Page in Word document to PDF, and after the resolution of WORDSNET-16228, it should also be possible to correctly save a page to DOCX, DOC, RTF formats by using the built-in properties of Aspose.Words. In that case, we would not need PageSplitter utility.

We will inform you via this thread as soon as this issue (WORDSNET-16228) is resolved. We apologize for any inconvenience.

The issues you have found earlier (filed as WORDSNET-16228) have been fixed in this Aspose.Words for .NET 20.10 update and this Aspose.Words for Java 20.10 update.