2

I have a question about multipage FixedPage. I have a Grid created programmatically and the Grid exceeds one A4 page. Now I want to print the Grid in several FixedPage with print margin. But on my way, I create the Grid repeatedly and offset the LeftTop point in the fixedPage Arrange function. I meet a problem that I cannot set print margin in fixedPage, because I set the print margin to the fixedPage and then the first page will have print margin and the next pages will be blank.

How do print multipage of FixedDocument for a large grid want to print?

PrintDialog pd = new System.Windows.Controls.PrintDialog(); 
if (pd.ShowDialog() == false) 
{ 
    return; 
} 

var pageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight); 
var document = new FixedDocument(); 
document.DocumentPaginator.PageSize = pageSize; 

for (int nPage = 0; nPage < MaxPage; nPage++) 
{ 
    Grid tempGrid = LoadControlMotherInit(); 

    tempGrid.Width = GridWidth; 
    tempGrid.Height = GridActualHeight; 

    Point leftTop = new Point(); 

    leftTop.X = 10; 
    leftTop.Y = -nPage * pageSize.Height; 

    // Create FixedPage 
    var fixedPage = new FixedPage(); 
    fixedPage.Width = pageSize.Width; 
    fixedPage.Height = pageSize.Height; 

    fixedPage.Margin = new Thickness(0, 0, 0, 96); 

    fixedPage.Children.Add((UIElement)tempGrid); 
    fixedPage.Measure(pageSize); 
    fixedPage.Arrange(new Rect(leftTop, pageSize)); 

    fixedPage.UpdateLayout(); 

    // Add page to document 
    var pageContent = new PageContent(); 
    ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); 
    document.Pages.Add(pageContent); 
} 

pd.PrintDocument(document.DocumentPaginator, "My Document"); 
Akira Chen
  • 69
  • 10

1 Answers1

0

From looking at your example, PrintDialog.PrintDocument method takes in a DocumentPaginator, which could come from a multitude of source.

that being said, you can inherit from DocumentPaginator and take control of everything from PageSize, PageCount to the actual DocumentPage being returned.

Imagine your DocumentPage as a sliding window over your UIElement; but instead of sliding your DocumentPage, you slide your UIElement using its RenderTransform.

Mr. Kone
  • 49
  • 3