Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 1038

Table with Rounded Corners and Cell Background

$
0
0

Hi all,

i put a border to my table and set CornerRadius to 15. After this i added 2 rows with 1 cell per row.                      

private static void CreatePdf()        {            // Instantiate Pdf object            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();            //Create the section in the Pdf object            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();            //Instantiate a table object            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();            tab1.FixedHeight = 200;            //Add the table in paragraphs collection of the desired section            sec1.Paragraphs.Add(tab1);            //Set with column widths of the table            tab1.ColumnWidths = "200";            //create a blank BorderInfo object            Aspose.Pdf.Generator.BorderInfo bInfo = new Aspose.Pdf.Generator.BorderInfo();            // create a GraphInfo object without any argument to its constructor            Aspose.Pdf.Generator.GraphInfo gInfo = new Aspose.Pdf.Generator.GraphInfo();            // set the corner radius for GraphInfo            gInfo.CornerRadius = 15F;            // specify the line color information             gInfo.Color = new Aspose.Pdf.Generator.Color("Red");            // set the rounded corner table border            bInfo.Round = gInfo;            // specify the Corner style for table border as Round            tab1.CornerStyle = Aspose.Pdf.Generator.BorderCornerStyle.Round;            // set the table border information            tab1.Border = bInfo;            //Create rows in the table and then cells in the rows            // Set Default border To Cells                         var row1 = tab1.Rows.Add();            var row2 = tab1.Rows.Add();            row2.Cells.Add("Hello World...");            row2.Cells[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Green");            // add sample string to paragraphs collection of table cell            row1.Cells.Add("Hello World...");            // set the vertical alignment of text as center aligned            row1.Cells[0].DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;            row1.Cells[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Blue");            // set the horizontal alignment of text as center aligned             row1.Cells[0].VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;            //Save the Pdf            //Dokument ausgeben            pdf1.Save(@"C:\temp\test.pdf");        }
 

The result is that i get a Table with rounded Corners. But alle Cells have the same Border. Now i tried to put a other Border without CornerRadius to my Cells.        

        private static void CreatePdf()        {            // Instantiate Pdf object            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();            //Create the section in the Pdf object            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();            //Instantiate a table object            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();            tab1.FixedHeight = 200;            //Add the table in paragraphs collection of the desired section            sec1.Paragraphs.Add(tab1);            //Set with column widths of the table            tab1.ColumnWidths = "200";            //create a blank BorderInfo object            Aspose.Pdf.Generator.BorderInfo bInfo = new Aspose.Pdf.Generator.BorderInfo();            // create a GraphInfo object without any argument to its constructor            Aspose.Pdf.Generator.GraphInfo gInfo = new Aspose.Pdf.Generator.GraphInfo();            // set the corner radius for GraphInfo            gInfo.CornerRadius = 15F;            // specify the line color information             gInfo.Color = new Aspose.Pdf.Generator.Color("Red");            // set the rounded corner table border            bInfo.Round = gInfo;            // specify the Corner style for table border as Round            tab1.CornerStyle = Aspose.Pdf.Generator.BorderCornerStyle.Round;            // set the table border information            tab1.Border = bInfo;            //Create rows in the table and then cells in the rows            // Set Default border To Cells            SetCellBorderInfo(tab1);            var row1 = tab1.Rows.Add();            var row2 = tab1.Rows.Add();            row2.Cells.Add("Hello World...");            row2.Cells[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Green");            // add sample string to paragraphs collection of table cell            row1.Cells.Add("Hello World...");            // set the vertical alignment of text as center aligned            row1.Cells[0].DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;            row1.Cells[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Blue");            // set the horizontal alignment of text as center aligned             row1.Cells[0].VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;            //Save the Pdf            //Dokument ausgeben            pdf1.Save(@"C:\temp\test.pdf");        }        private static void SetCellBorderInfo(Aspose.Pdf.Generator.Table table)        {            //create a blank BorderInfo object            Aspose.Pdf.Generator.BorderInfo bInfo = new Aspose.Pdf.Generator.BorderInfo();            // create a GraphInfo object without any argument to its constructor            Aspose.Pdf.Generator.GraphInfo gInfo = new Aspose.Pdf.Generator.GraphInfo();            // set the corner radius for GraphInfo            gInfo.CornerRadius = 0;            // specify the line color information             gInfo.Color = new Aspose.Pdf.Generator.Color("Red");            // set the rounded corner table border            bInfo.Round = gInfo;            // specify the Corner style for table border as Round            table.CornerStyle = Aspose.Pdf.Generator.BorderCornerStyle.None;            // set the table border information            table.DefaultCellBorder = bInfo;        }
Now is the result that the cells have no corner Radius. But they are overlaying 
the rounded Corners of the Table. Is there any way to clip the cells to the table?
 
Thank you in advance!

Viewing all articles
Browse latest Browse all 1038

Trending Articles