How do I create a PDFsharp table with dynamic data?

I am populating a table in PDFsharp to display the chart legend data. I have 14 objects in my list and only 2 are displayed and the colors of their rectangles are identical. Each one has a unique color to use. How can I display them all correctly?

   //Draw the table Row Borders
            xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoColumn); //Use different Color for Colum
            xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoStudentName);

            //Writting Table Header Text
            textformater.DrawString(" Color", tableheader, XBrushes.Black, snoColumn);
            textformater.DrawString(" Subdivision Name", tableheader, XBrushes.Black, snoStudentName);

            foreach (var item in data)
            {
                string colorStr = item.Color;

                Regex regex = new Regex(@"rgb\((?<r>\d{1,3}),(?<g>\d{1,3}),(?<b>\d{1,3})\)");
                Match match = regex.Match(colorStr);
                if (match.Success)
                {
                    int r = int.Parse(match.Groups["r"].Value);
                    int g = int.Parse(match.Groups["g"].Value);
                    int b = int.Parse(match.Groups["b"].Value);

                    y = y + 30;
                    XRect snoColumnVal = new XRect(35, y, 60, 25);
                    XRect snoStudentNameVal = new XRect(100, y, 250, 25);

                    var brush = new XSolidBrush(XColor.FromArgb(r, g, b));
                    xGrap.DrawRectangle(brush, snoColumnVal);
                    textformater.DrawString(item.Name, bodyfont, XBrushes.Black, snoStudentNameVal);

                };
            };

      

List of objects pic

This is the output I am currently getting picture

+3


source to share


1 answer


I think the color string Data [1] contains a space (blue has only two digits). This may be causing the match to fail and the line is skipped.

As a hack, you can try regex.Match(colorStr.Replace(" ", ""));

. Better change regex to allow spaces.



You are not showing the color bar for Savannah.

+2


source







All Articles