From 4a72fc9d40d346a8266de9c0a12847b9d62047d8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:41:47 +0300 Subject: [PATCH] Added new kb article grid-pdf-export-page-break-on-group (#608) * Added new kb article grid-pdf-export-page-break-on-group * adjust description and slug --------- Co-authored-by: KB Bot Co-authored-by: Attila Antal --- .../grid-pdf-export-page-break-on-group.md | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 knowledge-base/grid-pdf-export-page-break-on-group.md diff --git a/knowledge-base/grid-pdf-export-page-break-on-group.md b/knowledge-base/grid-pdf-export-page-break-on-group.md new file mode 100644 index 000000000..0b235b8fd --- /dev/null +++ b/knowledge-base/grid-pdf-export-page-break-on-group.md @@ -0,0 +1,77 @@ +--- +title: Add Page Breaks Between Groups in RadGrid PDF Export +description: Learn how to insert page breaks in RadGrid to ensure each group starts on a new page when exported to PDF. +type: how-to +page_title: Add Page Breaks Between Groups in RadGrid PDF Export +slug: grid-add-page-breaks-between-groups-in-pdf-export +tags: radgrid, export, pdf, group, page-break, asp.net ajax +res_type: kb +ticketid: 1667087 +--- + +## Environment + + + + + + + + + + + + +
ProductRadGrid for ASP.NET AJAX
Version2024.3.805
+ +## Description + +When exporting a [RadGrid](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/overview) to PDF, it's required to start each group on a new page. To achieve this, a page break needs to be inserted after each group's end. This KB article also answers the following questions: +- How can I ensure each group in RadGrid starts on a new page when exporting to PDF? +- Is it possible to insert page breaks in RadGrid's PDF export based on the group change? +- How to customize RadGrid's PDF export to have each group on separate pages? + +## Solution + +To insert a page break on each group change when exporting RadGrid to PDF, follow these steps: + +1. **Enable the Group Footer** in the `MasterTableView` by setting the `ShowGroupFooter` property to `true`. + + ````ASPX + + ```` + +2. **Inject the Page Break into the Footer of Each Group**. In the `PreRender` event of RadGrid, iterate through the Group Footer items and add the page break into their cells. + + ````C# + protected void RadGrid1_PreRender(object sender, EventArgs e) + { + // Get all GroupFooter items + GridItem[] groupFooterItems = RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter); + + // Iterate through all except the last + for (int i = 0; i < groupFooterItems.Length - 1; i++) + { + // Inject the page break into the first cell of the Group Footer + groupFooterItems[i].Cells[0].Text = ""; + } + } + ```` + +3. **Optional: Hide the Group Footer**. If you do not wish to display the Group Footer in the exported PDF, use CSS to target the Footer element and hide it. + + ````CSS + + ```` + +This setup ensures that each group in the RadGrid starts on a new page in the exported PDF by utilizing a hard page break at the end of each group. + +## See Also + +- [RadGrid Export to PDF Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/export-formats/export-to-pdf) +- [RadGrid Grouping Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/grouping/grouping) +- [Customizing RadGrid PDF Export](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/export-to-pdf/pdf-export-customization)