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

Free Support Forum - aspose.com

How Do I Move to the Next Page After Printing the Previous Page

I thought this was going to be easy but I’m completely lost. I cannot figure out how to move to the nextpage and write. Right now everything that I want printed on the first page is printing on the second page. It goes something like this:

builder.MoveToBookMark(“First_Line”);
builder.Write(someString);

builder.MoveToBookMark("First_Line);
builder.InsertBreak(BreakType.PageBreak);
builder.Write(someString);

The first line gets printed on the second page, even though I executed a pagebreak and nothing gets printed on the first page.

Does anybody know how you successfully print everything on the first page and then move to the second page?

Thanks!

Hi David,

Thanks for your inquiry. Yes this is the correct behaviour. Let me clarify quickly for you what is happening.

All nodes/text are inserted using the Document Builder are inserted into the front of the current position. So by default the text is being added to the front of the bookmark (and also by default inside the bookmark itself). This means the new text is appearing inside the bookmark, so when you move to the start of the bookmark again it will move all the way to the front of the newly inserted text. Adding a page break will then insert it before the text which causes the entire content move to the next page.

To achieve what you are trying to do, you should specify the cursor to move to after the bookmark before inserting the page break. Please see the modified code below.

builder.MoveToBookmark("First_Line");

builder.Write(string);

builder.MoveToBookmark("First_Line", false, true);

builder.InsertBreak(BreakType.PageBreak);

builder.Write(string);

Thanks,

Thank you so much. This worked. I tweaked it slightly by moving to the very last bookmark on the page and then executing the pagebreak.

Now I finally know what the two boolean conditions at the end of the MoveToBookmark method mean. :)

Hi David,

It's great that it worked. If you need any further assitance please feel free to ask

Thanks,