如何在 WPF 中打印带有可重复表列标题的 Flowdocument 表?
我看过这个 [ http://www.codeproject.com/KB/WPF/PimpedDocumentPaginator.aspx ] 但它不起作用。
如何在 WPF 中打印带有可重复表列标题的 Flowdocument 表?
我看过这个 [ http://www.codeproject.com/KB/WPF/PimpedDocumentPaginator.aspx ] 但它不起作用。
引用的 CodeProject 存在一些问题,但它几乎可以正常工作,并且我通过以下更改取得了成功:
在 GetPage 中,只需删除引用 Console 的四行。
在定义类中添加
public static Size Subtract( Size s1, Size s2 )
{
return new Size( s1.Width - s2.Width, s1.Height - s2.Height );
}
并将 ContentSize 更改为
return Subtract( PageSize, new Size(
Margins.Left + Margins.Right,
Margins.Top + Margins.Bottom + HeaderHeight + FooterHeight) );
然后,在您自己的代码中,通过单击按钮调用它:- 我不喜欢他的类名 :)
PrintDialog printDialog = new PrintDialog( );
printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
if ( true == printDialog.ShowDialog( ) )
{
MyPaginator.Definition d = new MyPaginator.Definition
{
Header = ( c, b, n ) => c.DrawRectangle( Brushes.Black, null, b ),
Margins = new Thickness( 48 ), // 1/2 inch all around
PageSize = new Size( flowDocument.PageWidth, flowDocument.PageHeight ),
};
DocumentPaginator s = new MyPaginator( flowDocument, d );
printDialog.PrintDocument( s, "Print Job Title" );
}
就我而言,我不需要页脚,但页眉委托(或类似的东西)是必须的。Margins 和 PageSize 将是默认值,但我想要不同的值。
最后,我发现我需要KeepTogether = true
为我的 TableCells 添加到我的段落定义中。
试试这个:WPF Reports
它支持页眉/页脚并有一些不错的功能。祝你好运
您基本上需要自己对文档进行分页,就像您对一段文本进行自动换行一样。检查下一行是否适合,如果不适合则分页,从表格标题开始每一页,并继续附加表格行直到页面已满。
不幸的是,没有一个分页器这样做。