Hi,
I Follow Embed a Grid into a Grid Cell in PDF in C# post and I want the embedded grid to be full width .How do I do this?
//Create a pdf document
PdfDocument pdf = new PdfDocument();
//Add a page
PdfPageBase page = pdf.Pages.Add();
//Create a pdf grid
PdfGrid grid = new PdfGrid();
//Add two rows
PdfGridRow row1 = grid.Rows.Add();
PdfGridRow row2 = grid.Rows.Add();
//Set Top and Bottom cell padding of the grid
grid.Style.CellPadding.Top = 5f;
grid.Style.CellPadding.Bottom = 5f;
//Add two columns
grid.Columns.Add(2);
//Set the columns’ width
grid.Columns[0].Width = 120f;
grid.Columns[1].Width = 120f;
//Create another grid to embed
PdfGrid embedGrid = new PdfGrid();
//Add a row
PdfGridRow newRow = embedGrid.Rows.Add();
//Add two columns
embedGrid.Columns.Add(2);
//set the column width to 60f
embedGrid.Columns[0].Width = 60f;
embedGrid.Columns[1].Width = 60f;
//Create a PDFStringFormat instance
PdfStringFormat stringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
//Assign values to the cells of the embedGrid and set formatting
newRow.Cells[0].Value = "Spire.Doc";
newRow.Cells[0].StringFormat = stringFormat;
newRow.Cells[1].Value = "Spire.PDF";
newRow.Cells[1].StringFormat = stringFormat;
//Assign values to the cells of the grid and set formatting
row1.Cells[0].Value = "Customer's Name";
row1.Cells[0].StringFormat = stringFormat;
row1.Cells[0].Style.BackgroundBrush = PdfBrushes.Gray;
row1.Cells[1].Value = "Product(s)";
row1.Cells[1].StringFormat = stringFormat;
row1.Cells[1].Style.BackgroundBrush = PdfBrushes.Gray;
row2.Cells[0].Value = "Michael";
row2.Cells[0].StringFormat = stringFormat;
//Assign the embedGrid to the cell of the grid
row2.Cells[1].Value = embedGrid;
row2.Cells[1].StringFormat = stringFormat;
//Draw the grid to the new added page
grid.Draw(page, new PointF(0f, 50f));
//Save the pdf document
pdf.SaveToFile("EmbedGridInCell.pdf");
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
PdfGrid grid = new PdfGrid();
grid.Columns.Add(2);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
grid.Columns[0].Width = width * 0.50f;
grid.Columns[1].Width = width * 0.50f;
PdfGridRow pdfGridRow = grid.Rows.Add();
pdfGridRow.Height = 25;
pdfGridRow.Cells[0].Value = "Sample Text";
PdfGrid embedgrid = new PdfGrid();
embedgrid.Columns.Add(3);
PdfGridRow pdfembedGridRow = embedgrid.Rows.Add();
pdfembedGridRow.Cells[0].Value = "Embed Row1 Col1";
pdfembedGridRow.Cells[1].Value = "Embed Row1 Col2";
pdfembedGridRow.Cells[2].Value = "Embed Row1 Col3";
pdfembedGridRow = embedgrid.Rows.Add();
pdfembedGridRow.Cells[0].Value = "Embed Row2 Col1";
pdfembedGridRow.Cells[1].Value = "Embed Row2 Col2";
pdfembedGridRow.Cells[2].Value = "Embed Row2 Col3";
pdfGridRow.Cells[1].Value = embedgrid;
PdfLayoutResult result = grid.Draw(page, new PointF(0, 10));
Spire.Pdf.Exceptions.PdfException: 'Can't draw one or more inner grids, no enough space available for it.'