Very oddly, every time I use grid.Draw I am unable to add text or grids to this page. It is not about x/y placement. For example, I may have text up to y-position 30 and create a grid. Then try to render text at 250 and will not see the text (though my grid ends at y position 70).
If I reverse the order, add text at position 250, then create my grid, I will see the grid above the text. Change the order again so that I add the text AFTER grid.Draw, and the text is missing.
I am also able to add text to page 2 after adding a grid to page 1. So, to summarize, as soon as I use grid.Draw, I am unable to add any content to current page. If I add text lower down in the page before using grid.Draw, this will succeed. If I create a new page, I will be able to add content to new page. Here is my code for grid generation
- Code: Select all
PdfGrid grid = new PdfGrid();
PdfGridRow row;
PdfLayoutResult result;
grid.Columns.Add(1);
grid.Columns[0].Width = page.Canvas.ClientSize.Width - 70;
PdfBorders noBorder = new PdfBorders();
noBorder.All = new PdfPen(new PdfTilingBrush(new SizeF(0, 0)), 0);
foreach (var objective in newResume.objectives)
{
row = grid.Rows.Add();
row.Cells[0].Style.Borders = noBorder;
text = String.Format("{0} ", objective.description);
row.Cells[0].Value = text;
}
//grid.Style.BorderOverlapStyle = PdfBorderOverlapStyle.Inside;
//grid.Style.BackgroundBrush = new PdfSolidBrush(Color.FromArgb(220, 220, 220)); //Color.FromArgb(220, 220, 220);
//grid.Style.CellPadding.All = 20f;
result = grid.Draw(page, new PointF(30, y));
y += result.Bounds.Height + 40f;
// does not render
text = String.Format("{0} {1} {2}", newResume.contactInfo.firstName, newResume.contactInfo.middleName, newResume.contactInfo.lastName);
page.Canvas.DrawString(text, nameTrueTypeFont, blueBrush,
pageWidth / 2, 250, formatCenter);
page = doc.Pages.Add(PdfPageSize.A4);
y = 30;
// renders
text = String.Format("{0} {1} {2}", newResume.contactInfo.firstName, newResume.contactInfo.middleName, newResume.contactInfo.lastName);
page.Canvas.DrawString(text, nameTrueTypeFont, blueBrush,
pageWidth / 2, 250, formatCenter);