WPF固定文档的多页打印(Visual C#2010)

WPF固定文档的多页打印(Visual C#2010),wpf,c#-4.0,printing,multipage,Wpf,C# 4.0,Printing,Multipage,我有一个关于多页固定页面的问题。我有一个网格创建的编程和网格超过一个A4页。现在我想打印网格在几个固定的页面与打印边距。但在我的方法中,我重复创建网格,并在fixedPage排列函数中偏移左顶点。我遇到一个无法在fixedPage中设置打印边距的问题,因为我将打印边距设置为fixedPage,然后第一页将具有打印边距,而下一页将为空白 如何打印大网格的多页固定文档 PrintDialog pd = new System.Windows.Controls.PrintDialog(); if (p

我有一个关于多页固定页面的问题。我有一个网格创建的编程和网格超过一个A4页。现在我想打印网格在几个固定的页面与打印边距。但在我的方法中,我重复创建网格,并在fixedPage排列函数中偏移左顶点。我遇到一个无法在fixedPage中设置打印边距的问题,因为我将打印边距设置为fixedPage,然后第一页将具有打印边距,而下一页将为空白

如何打印大网格的多页固定文档

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"); 
PrintDialog pd=new System.Windows.Controls.PrintDialog();
if(pd.ShowDialog()==false)
{ 
返回;
} 
var pageSize=新尺寸(pd.PrintableAreaWidth,pd.PrintableAreaHeight);
var document=新的FixedDocument();
document.DocumentPaginator.PageSize=页面大小;
对于(int-nPage=0;nPage
通过查看您的示例, PrintDialog.PrintDocument方法接受DocumentPaginator,它可能来自多个源

也就是说,您可以继承并控制从PageSize、PageCount到返回的实际DocumentPage的所有内容


将DocumentPage想象为UIElement上的滑动窗口;但是,不是滑动文档页面,而是使用其RenderTransform滑动UIElement。

听起来不是个好主意。。。尝试移动网格,而不是页面。没有任何魔力,只需设置其边距。但网格超过一张A4。我将边距设置为要打印的网格,效果将在第一页和最后一页上生效。Discord,如何设置打印边距?