我有一个关于多页FixedPage的问题。我有一个网格以编程方式创建,网格超过一个A4页面。现在我想打印网格在几个FixedPage与打印页边距。但是在我的方法中,我反复创建网格,并在fixedPage排列函数中偏移LeftTop点。我遇到了一个问题,我无法在fixedPage中设置打印页边距,因为我将打印页边距设置为fixedPage,然后第一页将具有打印页边距,而下一页将为空白。
如何打印一个大网格的FixedDocument多页打印?
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"); 发布于 2017-07-25 01:29:28
从您的示例可以看出,PrintDialog.PrintDocument方法接受了一个DocumentPaginator,该your可能来自多种来源。
也就是说,您可以从DocumentPaginator继承并控制从PageSize、PageCount到实际返回的DocumentPage的所有内容。
假设您的DocumentPage是UIElement上的一个滑动窗口;但是不是滑动DocumentPage,而是使用UIElement的RenderTransform进行滑动。
https://stackoverflow.com/questions/35667014
复制相似问题