Table inside of shape problems

Hi,

I am trying to place a table containing some text inside of a shape. I set the width and height of the shape and the row height/cell width to the same values. But the cell still extends pass the boundaries of the shape. I am trying to create a circle with a letter “A” in the center of the shape.

I am using Aspose.Words 9.0.0.0

Thanks.

Here is some sample code:

DocumentBuilder builder = new DocumentBuilder();

builder.StartTable();
Cell cell = builder.InsertCell();
builder.Font.ClearFormatting();
builder.ParagraphFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();

cell.CellFormat.Width = 468;
cell.CellFormat.Shading.BackgroundPatternColor = Color.White;
cell.ParentRow.RowFormat.Height = ConvertUtil.PixelToPoint(520) * .78;

builder.EndRow();

GroupShape group2 = new GroupShape(builder.Document);
group2.Width = 468;
group2.Height = ConvertUtil.PixelToPoint(520) * .78;
group2.CoordOrigin = Point.Empty;
group2.AllowOverlap = false;

cell.FirstParagraph.AppendChild(group2);

Shape shape;
Paragraph p;
Run run;

shape = new Shape(builder.Document, ShapeType.Ellipse);
shape.TextBox.FitShapeToText = false;

shape.AllowOverlap = false;
shape.TextBox.InternalMarginBottom = 0;
shape.TextBox.InternalMarginLeft = 0;
shape.TextBox.InternalMarginRight = 0;
shape.TextBox.InternalMarginTop = 0;

// Determine the size of each part and then translate that to the 1000x1000 coordinate
// plane of the GroupShape object
shape.Left = 6.25;
shape.Top = 386;
shape.Width = 38.75;
shape.Height = 59.61;
shape.CoordOrigin = Point.Empty;

Table table = new Table(builder.Document);
Row row = new Row(builder.Document);
Cell cell2 = new Cell(builder.Document);

group2.AppendChild(shape);

cell2.CellFormat.Width = shape.Width;
cell2.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
row.AppendChild(cell2);

row.RowFormat.Height = shape.Height;
row.RowFormat.HeightRule = HeightRule.Exactly;

table.AppendChild(row);

shape.AppendChild(table);

p = new Paragraph(builder.Document);

cell2.AppendChildº;

run = new Run(builder.Document, "A");
p.AppendChild(run);
p.ParagraphFormat.Alignment = ParagraphAlignment.Center;

builder.Document.SaveToPdf(@"h:\out.pdf");
builder.Document.Save(@"h:\out.doc");

Hi,

Thanks for your request. It’s not clear what you are trying to achieve.
Could you create a sample document in Microsoft Word and attach it here?

Thanks,

Hi,

Here is the output document. As you can see the letter A is not inside of the circle. I created a shape with a certain size. In the shape, I added a table with one cell containing a paragraph with the letter A. I adjusted the cell and row size to be the same dimensions as the shape. In the word document, it is not inside of the shape. If you take a look at the pdf document (highlight everything), you will notice that the letter is actually to the bottom right of the shape.

Thanks.

Hi,
Please see the sample code below. It creates a circle shape with a table inside which has one cell. The cell contains “A” letter which is centered vertically and horizontally. I also attached a document generated by this code. Hope this will help you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
double outerSquareSide = 300;
// Create a circle shape
Shape shape = new Shape(doc, ShapeType.Ellipse);
shape.Width = shape.Height = outerSquareSide;
builder.InsertNode(shape);
// Calculate side of the square inscribed in the circle
double innerSquareSide = outerSquareSide / 2 * Math.Sqrt(2);
Table table = new Table(doc);
shape.AppendChild(table);
Row row = new Row(doc);
row.RowFormat.Height = innerSquareSide;
table.AppendChild(row);
Cell cell = new Cell(doc);
cell.CellFormat.Width = innerSquareSide;
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
row.AppendChild(cell);
Paragraph para = new Paragraph(doc);
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
cell.AppendChild(para);
Run run = new Run(doc, "A");
para.Runs.Add(run);
doc.Save(@"out.doc");

Regards,