Reputation:
I am using MigraDoc do generate a PDF document, I would like to create a new page so first data get displayed in first page, second data get displayed in second page etc... this is how I am creating my page:
List<SIP_ImprovementPlans> s = db.MName.ToList();
MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
Section section = document.AddSection();
section.PageSetup.TopMargin = Unit.FromCentimeter(4);
Paragraph paragraph = new Paragraph();
var heading1= paragraph = section.AddParagraph("heading1");
document.AddSection();
var heading2= paragraph = section.AddParagraph("heading2");
document.AddSection();
Heading3 etc....
Now to create a new page I can do this: section.AddPage();
I have also tried document.AddPage();
But I get error in line AddPage(); why is that? the error says Error 1 'MigraDoc.DocumentObjectModel.Document' does not contain a definition for 'AddPage' and no extension method 'AddPage' accepting a first argument of type 'MigraDoc.DocumentObjectModel.Document'
If I do document.AddSection();
it creates the new page but I want heading 1 to be in first page, heading two in second page etc... currently its placing heading1 heading2 etc... in one page and creates a new page.
Upvotes: 2
Views: 4216
Reputation: 21689
To start a new page, simply call section.AddPageBreak();
document.AddSection();
returns the new section. To add text to the new section, call AddParagraph() for this new section. Your code creates three sections, but adds all headings to the first section.
Upvotes: 5