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

Free Support Forum - aspose.com

Preserve Top Margin Vertical Spacing during Converting DOCX OpenXML Document to PDF using C# .NET | Section Page Breaks

I have attached a very simple test document. Containing 2 pages with 1 line of text on each page. Between the pages a page break is inserted.

If I convert the sample document from docx to PDF. The second page will have more top spacing before the text than the first page.

Is there a way to make sure that the page break doesn’t add more spacing at the top of the second page?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for reporting this problem to us. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.

Best regards,

Thank you for your response. Can you maybe give me a bold estimate when a solution is expected?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Currently I cannot provide you any reliable estimate regarding this issue. You will be notified as soon as it is resolved.

But you can use a very simple workaround. It seems DOCX allows insert page break in sequence on the same row with paragraph break. However, if you try to save this document in DOC format using MS Words, you will see that paragraph break will be moved to the next row and you will get the same result as Aspose.Words returns.

As a workaround, you can try using Section Break (Next Page) instead of Page Break.

The modified document is attached.

Best regards.

Thank you for the workarounds.

However, saving as DOC is not an option because everything is based on the OpenXML standard of DocX. The SectionBreak isn’t really an option to implement at high volume because it also defines other things like header / footer heights.

So for now we wait till the fix.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I have one more way to work this problem around. You can try using ParagraphFormat.PageBreakBefore. Please see the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("This is the First page");

builder.CurrentParagraph.ParagraphFormat.PageBreakBefore = true;

builder.Writeln("This is the second page");

builder.CurrentParagraph.ParagraphFormat.PageBreakBefore = false;


Best regards,

Thank you for the work around. However the documents are constructed in Word and merged using OpenXML. We use Aspose.Words for the PDF conversion. We don’t build documents from scratch in Aspose.Words

I tested the “save as doc” behavior and it does the same thing as Aspose.Words does. After that I can remove the “extra” added paragraph and everything is correct. If I save that back to .docx it is still correct.

I noticed the PageBreak covers a full line in this case. In the regular docx behavior it is followed by a paragraph sign. So instead of using a section break, I can use a regular page break and remove the paragraph sign after the page break. This will give the correct behavior. I think the code you gave me creates the same construction. See Attachments. This is a workable solution until the fix is ready.



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can set PageBreakBeforet in MS Word. Please see the attached screenshot.

Best regards,

I see, that generates the same behavior as your code. That gives me enough work arounds for now.

Thank you!

The issues you have found earlier (filed as 18462) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I have the exact same problem, but it’s for converting html to pdf, using #$NP. Do you have a work around for me? Thank you.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach your input and output documents here for testing? I will investigate the issue and provide you more information.

Best regards,