I generating an exam document as a PDF file. Questions are always a paragraph, and in some cases the answers are multiple choices presented in a 4x4 table.
Using KeepTogether and KeepWith I've been able to not get page breaks inside a question or inside a table. However I can't find how to force the paragraph and table to keep together. Of course I never want a page break between the question and the choices table. What to do?
Code:
Document document = new Document();
Section s = document.AddSection();
Paragraph p;
foreach (Question q in sortedTest)
{
p = s.AddParagraph();
p.Format.KeepTogether = true;
p.AddFormattedText(counter.ToString() + ". " + q.QuestionText, TextFormat.Bold);
var table = new MigraDoc.DocumentObjectModel.Tables.Table();
...
Column column = table.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(3.6));
...
row = table.AddRow();
if (choiceCounter == 0)
{
row.KeepWith = 3;
}
...
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();