How to format paragraph using C#

Hello.
I’m trying to insert the alt text on a Shape.
The shape itself is being inserted and I am able to change colors and all, but the only issue is that I can’t make the title to show up.
Here’s the portion of the code:

I’ve inserted a Console.WriteLine just to make sure that the variable is returning what’s expected.

            private void DrawGeneralGradeChart(string fieldName, DocumentBuilder mBuilder, List<Tuple<double, double, double, string>> Data, ImageFieldMergingArgs args)
            {
                if (args.FieldValue != null)
                {
                    mBuilder.MoveToField(args.Field, true);
                    var total_itens = 100;

                    var colors = new Dictionary<string, List<int>>();
                    colors.Add("GeneralGrade", new List<int>{73, 190, 136});
                    colors.Add("ClassGrade", new List<int>{35, 125, 200});


                    var gradesRectangle = new Dictionary<string, double>();
                    gradesRectangle.Add("ClassGrade", (total_itens / 100) * Data.Sum(t => (int)t.Item1));
                    gradesRectangle.Add("GeneralGrade", (total_itens / 100) * Data.Sum(t => (int)t.Item2));
                    
                    var grade_total = gradesRectangle[fieldName];
                    
                    Shape gradeRectangle = mBuilder.InsertShape(ShapeType.Rectangle, gradesRectangle[fieldName], 10);
                    Shape totalItensRectangle = mBuilder.InsertShape(ShapeType.Rectangle, total_itens - gradesRectangle[fieldName], 10);
                    totalItensRectangle.FillColor = Color.Gray;
                    totalItensRectangle.Stroked = false;
                    
                    gradeRectangle.Title = $"{gradesRectangle[fieldName]}%";
                    Console.WriteLine($"{gradesRectangle[fieldName]}%");
                    gradeRectangle.FillColor = Color.FromArgb(colors[fieldName][0], colors[fieldName][1], colors[fieldName][2]);
                    gradeRectangle.Stroked = false;
                    args.Field.Remove();
                }
            }

@jonroosevelt

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Ok, there you go.
The template is in Services/Templates/Chart.docx
The Out and ExpectedOut files are in
Services/Out/Out.doc
Services/Out/ExpectedOut.doc
DrawChart.zip (81.3 KB)
Thanks for the prompt reply

@jonroosevelt

In your expected output document, there are two paragraphs with text 30% and 40%. You can achieve this requirement using following code snippet.

String title = $"{chartDict[fieldName]}%";
mBuilder.Writeln(title);
Shape chartRectangle = mBuilder.InsertShape(ShapeType.Rectangle, chartDict[fieldName], 10);
Shape restOfChart = mBuilder.InsertShape(ShapeType.Rectangle, total_itens - chartDict[fieldName], 10);
restOfChart.FillColor = Color.Gray;

I’ve done so. I’ve tried the exact same approach, but I thought that the mBuilder.Writeln is not the right way, since the chart has a title functionality.
I was expecting it to look more united to the chart.
Anyways, how can I format this Writeln text. I mean to centralize it with the chart and maybe change it’s font.

@jonroosevelt

You are working with shapes instead of charts. Please read the following article about formatting paragraphs.
Working with Paragraphs

If you want to work with charts, please read the following article.
Working with Charts

Ohh, ok, my mistake, so anyway, the Shape.Title just doesn’t work or it doesn’t work as I expected?

@jonroosevelt

You can find the shape’s title in its properties as shown in attached image. Shape Title.png (15.6 KB)

Please let us know if you have any more queries.

1 Like