We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add nested Grid in PDF

How to add nested Grid in PDF

 

We can add a nested grid or table in the PDF document. This can be achieved by using the PdfGrid class. Please find the following code sample for achieving this requirement.

            //Create a new PDF document.

            PdfDocument pdfDocument = new PdfDocument();

 

            //Create the page

            PdfPage pdfPage = pdfDocument.Pages.Add();

 

            //Create the parent grid

            PdfGrid parentPdfGrid = new PdfGrid();

 

            //Add the rows

            PdfGridRow row1 = parentPdfGrid.Rows.Add();

            PdfGridRow row2 = parentPdfGrid.Rows.Add();

            row1.Height = 20;

            row2.Height = 58;

 

            //Add the columns

            parentPdfGrid.Columns.Add(3);

 

            //Set the value to the specific cell.

            parentPdfGrid.Rows[0].Cells[0].Value = "Parent Table";

            parentPdfGrid.Rows[0].Cells[1].RowSpan = 2;

            parentPdfGrid.Rows[0].Cells[1].ColumnSpan = 2;

 

            //Create the child table

            PdfGrid childPdfGrid = new PdfGrid();

 

            //Set the column and rows for child grid

            childPdfGrid.Columns.Add(5);

            for (int i = 0; i < 5; i++)

            {

                PdfGridRow row = childPdfGrid.Rows.Add();

                for (int j = 0; j < 5; j++)

                {

                    row.Cells[j].Value = String.Format("Child Cell [{0} {1}]", j, i);

                }

            }

            //Set the value as another PdfGrid in a cell.

            parentPdfGrid.Rows[0].Cells[1].Value = childPdfGrid;

 

            //Specify the style for the PdfGridCell.

            PdfGridCellStyle pdfGridCellStyle = new PdfGridCellStyle();

            pdfGridCellStyle.Borders.All = PdfPens.Red;

            PdfGridCell pdfGridCell = parentPdfGrid.Rows[0].Cells[0];

 

            //Apply style

            pdfGridCell.Style = pdfGridCellStyle;

 

            //Draw the PdfGrid.

            parentPdfGrid.Draw(pdfPage, PointF.Empty);

 

            //Save the document.

            pdfDocument.Save("Output.pdf");

 

            //Close the document

            pdfDocument.Close(true);

 

Article ID: Published Date: Last Revised Date: Platform: Control:
5832 11/30/2015 11/30/2015 WinForms PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon