首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于FixedDocument的WPF多页打印(Visual C# 2010)

用于FixedDocument的WPF多页打印(Visual C# 2010)
EN

Stack Overflow用户
提问于 2016-02-27 15:29:28
回答 1查看 1.7K关注 0票数 2

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

如何打印一个大网格的FixedDocument多页打印?

代码语言:javascript
复制
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"); 
EN

回答 1

Stack Overflow用户

发布于 2017-07-25 01:29:28

从您的示例可以看出,PrintDialog.PrintDocument方法接受了一个DocumentPaginator,该your可能来自多种来源。

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

假设您的DocumentPage是UIElement上的一个滑动窗口;但是不是滑动DocumentPage,而是使用UIElement的RenderTransform进行滑动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35667014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档