Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to customize a Document Map at runtime

$
0
0

This example demonstrates how to customize a report's document map at runtime. For demonstration purposes, I created a hierarchical tree of bookmarks and make some bookmarks of the first level repeated multiple times (since the control is repeatedly printed on different pages). This solution illustrates how to keep only one bookmark for this control. To do so, adjust the bookmark collection (accessed via the XtraReport.PrintingSystem.Document.BookmarkNodes property) after a report has been generated. 

 

Note
With version 15.1, we have added a BookmarkDuplicateSuppress property to the XtraReport, ScriptingReportBase, and PrintingDocument classes. This property defines whether to suppress duplicated bookmarks in a final document.

Moreover, the default value of this property is true, which means that duplicated bookmarks are always suppressed by default. To return to the old behavior, set BookmarkDuplicateSuppress to false. See Bookmarks - Add the XRControl.SuppressDuplicateBookmarks property to avoid adding multiple bookmarks with the same name when a control is printed several times on different pages for further information.

See also: How to customize a Document Map at runtime.

Question Comments

Added By: Conrad Akunga at: 5/21/2013 3:21:36 AM    

Here's a somewhat simpler solution.

Create an extension method like so:

 public static void MergeBookmarks(this XtraReport rpt)
        {
            var ToRemove = new List<int>();
            var prior = "";
            //
            // Loop through all the nodes, detecting which are duplicates
            //
            for (int i = 0; i < rpt.PrintingSystem.Document.BookmarkNodes.Count; i++)
            {
                var current = rpt.PrintingSystem.Document.BookmarkNodes[i].Text;
                if (prior == current)
                {
                    ToRemove.Add(i);
                }
                prior = current;
            }
            //
            // Now remove the duplicate bookmarks
            //
            if (ToRemove.Count > 0)
            {
                // Reverse the list to get the indexes in descending order; we are modifying the collection
                ToRemove.Reverse();
                foreach (var i in ToRemove)
                {
                    rpt.PrintingSystem.Document.BookmarkNodes.RemoveAt(i);
                }
            }
        }

Then in the report itself, call the method in the AfterPrint event

Added By: Miles at: 8/28/2013 10:59:23 AM    

I like your implementation, Conrad; however, it doesn't work for nested bookmarks.

Added By: Conrad Akunga at: 4/17/2014 5:03:10 AM    

@Miles ... for my needs I only needed it one level deep. Let me see if I can modify it to serve multiple levels


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>