One of the key new features of PageBuilder 4 is the ability to automatically split item groups for
single products across multiple columns or pages in a catalog. The PageBuilder plug-in for InDesign allows you
to specify which boxes in your templates are suitable locations for breaking up the design and which text
boxes can be split up when the layout demands it:

You can also specify that a certain box in your design template should be repeated on the next
page or column whenever an item group is split up. This way you can ensure that each column or page
starts with a product title or identifier to provide additional context while browsing the catalog.
You may want to add an ellipsis or other suffix to repeated product headers to distinguish them from the initial
product headers. In this blog post we show how to achieve this with just a few lines of custom code.
The most straightforward place to add our suffix to the repeated product headers is in the OnPlaced
method of a custom RecordPaginateAction. This method is called whenever the elements of an item group
have been placed in the catalog. The placed elements, which may be split across multiple pages or columns, are passed to
the method through the PlaceTarget argument. The code below shows how to iterate over the elements
and add a suffix to each repeated product header:
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using System.Collections.Generic;
using System.Linq;
using Adam.Core;
using Adam.DocMaker.Core;
using Adam.PageBuilder.Core.Build;
using Adam.PageBuilder.Core.Paginate;
class CustomRepeatBoxCatalogBuilder : CatalogBuilder
{
public CustomRepeatBoxCatalogBuilder(Application application) : base(application)
{
RecordPaginateAction = new CustomRecordPaginateAction(application);
}
}
class CustomRecordPaginateAction : RecordPaginateAction
{
private const string _suffix = " […]";
public CustomRecordPaginateAction(Application application) : base(application)
{
}
protected override void OnPlaced(PlaceTarget placeTarget)
{
IEnumerable<Element> elements = placeTarget.Elements;
foreach (TextElement element in elements.OfType<TextElement>().Where(e => e.IsRepeatBox(elements)))
{
Run lastRun = element.Story.Paragraphs.Last().Items.OfType<Run>().Last();
lastRun.Value += _suffix;
}
}
}
|
This code sample uses a hardcoded suffix string, but you could also use the Tag property of the
CatalogBuilder to pass the suffix from the PageBuilder Studio UI to the custom code, yielding
a more flexible solution for the end user.
Checking whether a text element is a repeated product header is done through an extension method that looks for
another element in the item group with the same content and a preceding position (either on a previous page or
in a previous column):
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System.Collections.Generic;
using System.Linq;
using Adam.DocMaker.Core;
static class ElementExtensions
{
public static bool IsRepeatBox(this Element element, IEnumerable<Element> referenceElements)
{
return referenceElements.Any(e => (e.ToText() == element.ToText()) && e.Precedes(element));
}
public static bool Precedes(this Element element, Element referenceElement)
{
return (element.OwnerSpread.Index < referenceElement.OwnerSpread.Index)
|| ((element.OwnerSpread.Index == referenceElement.OwnerSpread.Index)
&& (element.Shape.Bounds.Left < referenceElement.Shape.Bounds.Left));
}
}
|
And that pretty much wraps it for today. Here's what the result might look like:
