Hi,
I think you have confused rectangular color box with text.
Hi Avinash,
Please try using following code snippet. For your reference, I have also attached the output generated over my end.
In case I have not properly understood the requirement or you have any further query, please feel free to contact.
[C#]
Document pdfDocument = new Document();
Page pdfPage = pdfDocument.Pages.Add();
Table table = new Table();
table.Margin = new MarginInfo { Left = 20, Right = 20, Top = 10, Bottom = 0 };
table.Border = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LawnGreen);
table.DefaultCellBorder = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LightBlue);
pdfPage.Paragraphs.Add(table);
table.ColumnWidths = "150 150";
Row row = table.Rows.Add();
Cell cell1 = row.Cells.Add();
cell1.Paragraphs.Add(new TextFragment("yellow_color_rect_box"));
cell1.DefaultCellTextState.ForegroundColor = Aspose.Pdf.Color.Yellow;
Cell cell2 = row.Cells.Add();
cell2.Paragraphs.Add(new TextFragment("Red_color_rect_box"));
cell2.DefaultCellTextState.ForegroundColor = Aspose.Pdf.Color.Red;
pdfDocument.Save("c:/pdftest/TableOutput.pdf");
Hi,
Hi Avinash,
Thanks for sharing the details.
Do you think following code snippet can fulfill your requirement.
[C#]
Document pdfDocument = new Document();
Page pdfPage = pdfDocument.Pages.Add();
Table table = new Table();
table.Margin = new MarginInfo { Left = 20, Right = 20, Top = 10, Bottom = 0 };
// table.Border = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LawnGreen);
// table.DefaultCellBorder = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LightBlue);
pdfPage.Paragraphs.Add(table);
table.ColumnWidths = "100 100";
Row row = table.Rows.Add();
Cell cell1 = row.Cells.Add();
cell1.BackgroundColor = Aspose.Pdf.Color.Yellow;
Cell cell2 = row.Cells.Add();
cell2.Paragraphs.Add(new TextFragment("Yellow Label"));
Row row2 = table.Rows.Add();
Cell row2_cell1 = row2.Cells.Add();
row2_cell1.BackgroundColor = Aspose.Pdf.Color.Green;
Cell row2_cell2 = row2.Cells.Add();
row2_cell2.Paragraphs.Add(new TextFragment("Green Label"));
pdfDocument.Save("c:/pdftest/TableOutput.pdf");
No no no.
Hi Avinash,
Thanks for sharing the details.
The reasons I have used TextFragment is to indicate on how to add some label with colored rectangles. However, if you do not want to render TextFragment, you can comment out the code line where TextFragment is being added to table cell.
Please take a look over following code snippet which generates exact output as specified in earlier shared image.
[C#]
Document pdfDocument = new Document();
Page pdfPage = pdfDocument.Pages.Add();
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.Margin = new Aspose.Pdf.MarginInfo { Left = 20, Right = 20, Top = 10, Bottom = 0 };
// table.Border = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LawnGreen);
// table.DefaultCellBorder = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.LightBlue);
table.DefaultCellPadding = new Aspose.Pdf.MarginInfo(5, 5, 5, 5);
pdfPage.Paragraphs.Add(table);
table.ColumnWidths = "50 50";
Aspose.Pdf.Row row2 = table.Rows.Add();
row2.FixedRowHeight = 20;
Aspose.Pdf.Cell row2_cell1 = row2.Cells.Add();
row2_cell1.BackgroundColor = Aspose.Pdf.Color.Green;
Aspose.Pdf.Cell row2_cell2 = row2.Cells.Add();
row2_cell2.Paragraphs.Add(new TextFragment("ABC"));
// add blank row for spacing
Aspose.Pdf.Row row_blank = table.Rows.Add();
row_blank.Cells.Add();
Aspose.Pdf.Row row = table.Rows.Add();
row.FixedRowHeight = 20;
Aspose.Pdf.Cell cell1 = row.Cells.Add();
cell1.BackgroundColor = Aspose.Pdf.Color.Yellow;
Aspose.Pdf.Cell cell2 = row.Cells.Add();
cell2.Paragraphs.Add(new TextFragment("XYZ"));
pdfDocument.Save(“c:/pdftest/TableOutput_New.pdf”);