Rectangle to back

Rectangle to back

Forum member · Oct 6, 2014
is There any way to send a rectangle back? I need to dynamically create the rectangle, once I know the text lines to be filled. Lines content is dynamic and depends on several factors. Unable to make the rectangle first, becasue I do not know how many lines will occupy. It is possible to manipulate the object Page.Elements to swap the positions before adding page to Document? Thanks ims

Re: Rectangle to back

Support · Oct 6, 2014
Hello, Yes, you can set the desired height, width , x and y positions to the Rectangle using its Width, Height, X and Y properties. For example if you are adding dynamic text contents to the PDF using TextArea and want to set the dimensions to the Rectangle as per the TextArea dimensions then you can do it as shown in the below code. Document document = new Document(); Page page = new Page(); string text = "This is to test Rectangle dimensions"; for (int i = 0; i < 5; i++) { text += text; } TextArea area = new TextArea(text, 0, 0, 400, 40); area.Height = area.GetRequiredHeight(); page.Elements.Add(area); //Adding Rectangle with calculated dimension and position. Rectangle rect = new Rectangle(area.X, area.Y, area.Width, area.Height); page.Elements.Add(rect); document.Pages.Add(page); document.Draw(@"C:\Temp\Output.pdf"); Thanks, ceTe Software Support Team.

Re: Rectangle to back

Forum member · Oct 6, 2014
I need to create a rectangle with fillColor. If I first add the texts and next the rectangle, the text is back of rectangle and can't see. The text is contains severals Text Elements, the rectangle heigh is calculate to fill all the elements, but the rectangle with color background cover all the text. ims

Re: Rectangle to back

Support · Oct 7, 2014
Hello, Yes, you can achieve your requirement by creating a Rectangle object with some random dimensions and positions initially and add it to the page. Then you can add the text contents to the PDF using respective page element and change the positions and dimensions of the Rectangle object accordingly. Below is the code sample for it. Document document = new Document(); Page page = new Page(); Rectangle rect = new Rectangle(10, 10, 200, 200); rect.FillColor = RgbColor.BurlyWood; page.Elements.Add(rect); string text = "This is to test Rectangle dimensions"; for (int i = 0; i < 5; i++) { text += text; } TextArea area = new TextArea(text, 0, 0, 400, 40); area.Height = area.GetRequiredHeight(); page.Elements.Add(area); //Setting dimensions and position to the Rectangle. rect.Width = area.Width; rect.Height = area.Height; rect.X = area.X; rect.Y = area.Y; document.Pages.Add(page); document.Draw(@"C:\Temp\Output.pdf"); Thanks, ceTe. Software Support Team.

Re: Rectangle to back

Forum member · Oct 8, 2014
Thanks. It runs right for me. Ims