Intersoft ClientUI 8 > ClientUI Fundamentals > Document Framework Overview > How-to: Use Custom Paginator in FixedDocument |
This example shows how apply a custom paginator while printing a FixedDocument.
PrintDocument class will use the Print method to print the document. Print method needs two parameters, DocumentPaginator object and the document name. DocumentPaginator is an abstract base class that supports creation of multiple-page elements from a single document. By default, each FixedDocument has DocumentPaginator property that contain DocumentPaginator object for the fixed document.
Additionally, you can specify a custom paginator class to add custom elements for printing purpose only, such as header or footer.
The following code shows how to add header and footer element in a FixedDocument for printing purpose.
XAML |
Copy Code
|
---|---|
<UserControl x:Class="IntersoftDocumentPaginator.CustomPrint" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Button Content="Print Books" Click="Button_Click" VerticalAlignment="Top"/> </Grid> </UserControl> |
CS |
Copy Code
|
---|---|
public partial class CustomPrint : UserControl { private List<Book> Books; public CustomPrint() { InitializeComponent(); this.Books = new List<Book>(); } private void Button_Click(object sender, RoutedEventArgs e) { FixedDocument doc = this.CreateFixedDocument(); PrintDocument pd = new PrintDocument(); DocumentPaginator paginator = new BookPaginator(doc.DocumentPaginator, doc.DocumentPaginator.PageSize); pd.Print(paginator, "Books"); } private FixedDocument CreateFixedDocument() { this.LoadBooks(); FixedDocument doc = new FixedDocument(); PageContent pc = new PageContent(); doc.Pages.Add(pc); FixedPage page = new FixedPage(); pc.Content = page; StackPanel panel = new StackPanel(); page.Children.Add(panel); foreach (Book book in this.Books) { TextBlock tb = new TextBlock(); tb.Text = book.Title; tb.Margin = new Thickness(10); panel.Children.Add(tb); } return doc; } private void LoadBooks() { // loads book data from xml file StreamResourceInfo resource = System.Windows.Application.GetResourceStream( new Uri("Data/BookDataSource.xml", UriKind.Relative)); XDocument doc = XDocument.Load(resource.Stream); var books = from x in doc.Descendants("Book") select new Book(x); foreach (Book book in books) this.Books.Add(book); resource.Stream.Close(); } } |