Intersoft ClientUI 8 > ClientUI Fundamentals > Document Framework Overview > How-to: Use Custom Paginator In UXDocumentViewer |
This example shows how use custom paginator in UXDocumentViewer.
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. In UXDocumentViewer, simply specify set CustomPaginator property of the fixed document to the custom paginator object. You might need to handle the EndPrint event to remove the header and footer element added for the printing purpose.
The following code shows how to add header and footer element in a FixedDocument for printing purpose.
CS |
Copy Code
|
---|---|
public class BookPaginator : DocumentPaginator { DocumentPaginator _paginator; public BookPaginator(DocumentPaginator paginator, Size pageSize) { _paginator = paginator; _paginator.PageSize = pageSize; } public override DocumentPage GetPage(int pageNumber) { DocumentPage page = _paginator.GetPage(pageNumber); StackPanel panel = (page.Visual as Canvas).Children[0] as StackPanel; //add header element TextBlock tb = new TextBlock(); tb.Text = "Book List"; tb.FontSize = 24; tb.Margin = new Thickness(10, 0, 0, 15); panel.Children.Insert(0, tb); //add footer element TextBlock footer = new TextBlock(); footer.Text = "Copyright © My Publisher Corp 2011."; footer.HorizontalAlignment = HorizontalAlignment.Center; panel.Children.Add(footer); page.Visual.Measure(_paginator.PageSize); page.Visual.Arrange(new Rect(new Point(0, 0), _paginator.PageSize)); return new DocumentPage(page.Visual, _paginator.PageSize, page.BleedBox, page.ContentBox); } public override bool IsPageCountValid { get { return _paginator.IsPageCountValid; } } public override int PageCount { get { return _paginator.PageCount; } } public override Size PageSize { get { return _paginator.PageSize; } set { _paginator.PageSize = value; } } public override IDocumentPaginatorSource Source { get { return _paginator.Source; } } } |
XAML |
Copy Code
|
---|---|
<UserControl x:Class="IntersoftDocumentPaginator.DocViewer" 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" xmlns:Intersoft="http://intersoft.clientui.com/schemas" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"> <Grid x:Name="LayoutRoot" Background="White"> <Intersoft:UXDocumentViewer x:Name="DocViewer1" Width="800" Height="600" EndPrint="DocViewer1_EndPrint"> <Intersoft:FixedDocument x:Name="FixedDocument1"> <Intersoft:PageContent> <Intersoft:FixedPage Width="816" Height="1056"> <StackPanel Margin="10"> <StackPanel Orientation="Horizontal" Margin="5"> <Image Source="Images/Books/Application_and_Software_1.jpg" Width="75" Height="75"/> <StackPanel VerticalAlignment="Center"> <TextBlock Text="Excel 2007 For Dummies" FontSize="12"/> <TextBlock Text="Greg Harvey, PhD" VerticalAlignment="Center" FontSize="10"/> </StackPanel> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Image Source="Images/Books/CC_and_Training_1.jpg" Width="75" Height="75"/> <StackPanel VerticalAlignment="Center"> <TextBlock Text="CCNA Official Exam Certification Library" FontSize="12"/> <TextBlock Text="Wendell Odom" VerticalAlignment="Center" FontSize="10"/> </StackPanel> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Image Source="Images/Books/Computer_science_1.jpg" Width="75" Height="75"/> <StackPanel VerticalAlignment="Center"> <TextBlock Text="Computer Science: An Overview" FontSize="12"/> <TextBlock Text="J. Glenn Brookshear" VerticalAlignment="Center" FontSize="10"/> </StackPanel> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Image Source="Images/Books/Database_management_1.jpg" Width="75" Height="75"/> <StackPanel VerticalAlignment="Center"> <TextBlock Text="Microsoft Office Access 2007" FontSize="12"/> <TextBlock Text="Virginia Andersen" VerticalAlignment="Center" FontSize="10"/> </StackPanel> </StackPanel> <StackPanel Orientation="Horizontal" Margin="5"> <Image Source="Images/Books/Ec_system_1.jpg" Width="75" Height="75"/> <StackPanel VerticalAlignment="Center"> <TextBlock Text="Competing on Analytics: The New Science of Winning" FontSize="12"/> <TextBlock Text="Thomas H. Davenport, Jeanne G. Harris" VerticalAlignment="Center" FontSize="10"/> </StackPanel> </StackPanel> </StackPanel> </Intersoft:FixedPage> </Intersoft:PageContent> </Intersoft:FixedDocument> </Intersoft:UXDocumentViewer> </Grid> </UserControl> |
CS |
Copy Code
|
---|---|
public partial class DocViewer : UserControl { public DocViewer() { InitializeComponent(); DocumentPaginator paginator = new BookPaginator(this.FixedDocument1.DocumentPaginator, this.FixedDocument1.DocumentPaginator.PageSize); FixedDocument1.CustomPaginator = paginator; } private void DocViewer1_EndPrint(object sender, Intersoft.Client.UI.DocumentViewers.DocumentViewerEndPrintEventArgs e) { UXDocumentViewer viewer = sender as UXDocumentViewer; foreach (PageContent pc in viewer.Document.Pages) { FixedPage page = pc.Content as FixedPage; StackPanel panel = page.Children[0] as StackPanel; panel.Children.RemoveAt(0); } } } |