The PageLayout class provides the PageSettings property to define the page layout for all pages in a PrintDocument. You can also specify a standard paper size using the PaperKind property of C1PageSettings class.
The GIF image below depicts the use of page layout in document.
The code snippet below depicts the use of C1PageSettings class to define layout on the first page, even or odd pages in the PrintDocument.
C# |
Copy Code
|
---|---|
// define PageLayout for the first page PageLayout pl = new PageLayout(); pl.PageSettings = new C1PageSettings(); pl.PageSettings.PaperKind = PaperKind.Legal; doc.PageLayouts.FirstPage = pl; // define PageLayout for even pages pl = new PageLayout(); pl.PageSettings = new C1PageSettings(); pl.PageSettings.PaperKind = PaperKind.Letter; // create the page header RenderText ph = new RenderText(); ph.Text = "Even page. [PageNo] / [PageCount]"; ph.Style.Borders.All = LineDef.Default; ph.Style.BackColor = Color.Beige; pl.PageHeader = ph; // even pages will have no page footer, set it to an empty object pl.PageFooter = new RenderEmpty(); doc.PageLayouts.EvenPages = pl; // define PageLayout for odd pages pl = new PageLayout(); // odd pages will have 2 columns pl.Columns.Add(); pl.Columns.Add(); pl.PageSettings = new C1PageSettings(); pl.PageSettings.PaperKind = PaperKind.Letter; pl.PageSettings.Landscape = true; // create the page header ph = new RenderText(); ph.Text = "Odd page. [PageNo] / [PageCount]"; ph.Style.Borders.All = LineDef.DefaultBold; ph.Style.BackColor = Color.LightSeaGreen; pl.PageHeader = ph; // create the page footer RenderText pf = new RenderText(); pf.Text = "Footer of odd page. [PageNo] / [PageCount]"; pf.Style.Borders.All = LineDef.DefaultBold; pf.Style.BackColor = Color.SlateGray; pl.PageFooter = pf; doc.PageLayouts.OddPages = pl; // generate the content of document RenderText ro = new RenderText("This is the first page of the document. It has no page header or footer, and has Legal size."); ro.BreakAfter = BreakEnum.Page; doc.Body.Children.Add(ro); |