Free Support Forum - aspose.com

Set Page Break Before of TableStart Merge Field Regions Paragraph for Pagination

Hi again

Sorry about the all questions lately. Once I got it all working I will stop hassling you.

Today’s subject is to making sure I get a new page at the end of a mail merge with regions.

I have attached (my usual document) which contains two tables. One called Base and a child table. I want the mail merge to start a new page every time it comes to «TableEnd:Base».

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

The only way I can get that working is by putting a page break after «TableEnd:Base» but that obviously leaves an empty page at the end of the merged document.

I have read this:

but I am none the wiser unfortunately. The Page Setup / Layout / Section Start: is already set to ‘New Page’ but it still won’t work. Maybe that is only for non-region merging?

I am at a loss, what do I do?

As always, grateful for any help.

Regards,

!Rob

Hi

Thanks for your request. I think in your case, you should simply set “Page Break Before” option for a paragraph that contains a TableStart:Base merge field. Please see the attached modified tempalte.

Hope this helps.

Best regards,

Hello

Thanks for your help, but unforutnately it made no difference. I can see that you have set the break for the paragraph to 'Page Break Before'. But it did not make any difference.

I am starting to worry now. I have just spent a fair bit of money on the Developer OEM license and to me this must be one of the most basic things people are using the product for. Is it not?

!Rob

Further to this

Realising I might get some help from the demos I looked at the 'Sales Invoice Demo' which is pretty much what I am trying to accomplish.

I note that there is a page break before the «TableEnd:Orders» in that template. And consequently it produces an empty page at the end!

I suppose this means that there is no way to produce such reports without either having an empty page at the end, or having the next invoice start at the same page as the last one ended. This disappoints me a bit.

However, one solution might be to simply programmatically remove the last page after the .ExecuteWithRegions() call.

Before I start on a mission to find out how to do that. Are you able to advise me if that is in fact the only way to do it. If so, if it can be done and maybe even a couple of code lines to show me how?

Gratefully,

!Rob

Hi Rob,


Thanks for this additional information.

Everything works fine on my side using Alexey’s template. By any chance are you setting RemoveEmptyParagraphs to true? In this case the region paragraph with the page break will be removed automatically during mail merge which would be why there is no page break.

If this is the case then instead try moving the TableStart field onto the same line as the first field of the region and make sure the combined paragraph has page break before set as in your previous template. This should make the page break before every region work properly.

Please let us know if this solves the issue for you.

Thanks,

Hi Adam

Yes, you were right. I had set the:
MailMerge.RemoveEmptyParagraphs
to true.

When I removed that line Alexey's version worked perfectly. Thanks both of you!

Despite having looked at the doco I get a little confused about RemoveEmptyParagraphs.

In my code I first read all merge fields from the document, then I build the dataset based on which merge fields are present in the document. This way all merge fields will be present in my dataset (although some of the values may be DBNull). Using this approach, does this mean that I should never set RemoveEmptyParagraphs to true?

Regards,

!Rob

Hi Rob,


I will try to improve that part of the documentation with an example. Also I will add some details regarding why it did not work in your situation.

Regarding your query, when you merge a merge field with a null value it will remove the field but an empty paragraph will remain. You should set RemoveEmptyParagraphs to true in order to remove such paragraphs from the document during mail merge.

However in your case, it won’t make much difference in your template as all of your merge fields are in cells. Even if a field is merged with empty data and the paragraph removed, the cell would still remain. So in your case I think you can do without using RemoveEmptyRegions

Thanks,

Sounds good Adam, thanks!

And now I understand how RemoveEmptyRegions work as well.

Thanks,

!Rob