I started to build a word document using the Document object. I’m almost finnished
and everything seems to be working except inserting page breaks.
When I searched for how I could insert them I found out that the DocumentBuilder had a method for it.
I have not used the DocumentBuilder in any of my code so far and if I try to use it all my pagebreaks will be put at the top of the DocumentBuilder? Is this because I have used the Document object everywhere else?
Hello!
Thank you for your inquiry.
You can achieve the same effect by adding a run of text with ControlChar.PageBreak to the document: https://reference.aspose.com/words/net/aspose.words/controlchar/pagebreak/
There is no difference whether you are using DocumentBuilder or doing the same without it while you’re doing everything correctly. DocumentBuilder is a helper class that simplifies operations on Document. There is no reason to start using it at this point where you are almost finished but need a page break.
Regards,
Thanks a lot for your fast reply!
I will give it a try. I have one more question. Why does the pagebreaks get first in the document when I’m trying to use the DocumentBuilder? Is it because I have used Document to create the rest of the document?
Hi again.
Without looking your code I can suspect that your DocumentBuilder is improperly positioned. It has an internal cursor that is set by MoveToXXX methods. Recommendations depend on where you need a page break. If you’d like to put it at the end of some paragraph just pass it to this simple method:
Hi
Thanks for your request. This occurs because when you create DocumentBuilder the cursor is placed at the beginning of document. You can try using the following code:
// Here is your code that you are using fo document generation
// Then you create DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(doc);
// Move cursor to the end of document
builder.MoveToDocumentEnd();
// And insert page break
builder.InsertBreak(BreakType.PageBreak);
Thanks a lot!
Now I understand more how I should work with the DocumentBuilder if I need to do something more. Maybe change some things.
Right now I created a Run with the ControlChar.PageBreak constant and it worked out very well!
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.