【发布时间】:2012-07-16 19:09:05
【问题描述】:
我正在尝试打印 WPF FlowDocument。版面需要采用每页4个文档的形式,布局如下:
Doc1 | Doc2
-------------
Doc3 | Doc4
(抱歉,我想不出更好的方式来说明布局)。
页面需要填满,所以如果Doc1&2是空白或者只有一两个字符,它仍然需要打印和Doc3&4一样的大小。
我正在使用的代码如下(对不起,它很长,我已尝试在可行的情况下进行删节):
PrintDialog printDialog = new PrintDialog();
if ((bool)printDialog.ShowDialog().GetValueOrDefault())
{
FlowDocument flowDocument = new FlowDocument();
flowDocument.PageHeight = printDialog.PrintableAreaHeight;
flowDocument.PageWidth = printDialog.PrintableAreaWidth;
flowDocument.PagePadding = new Thickness(25);
flowDocument.ColumnGap = 0;
flowDocument.ColumnWidth = (flowDocument.PageWidth -
flowDocument.ColumnGap -
flowDocument.PagePadding.Left -
flowDocument.PagePadding.Right);
Table myTable = new Table();
myTable.BorderThickness = new Thickness(3);
AddCols(myTable); // Add 2 cols
TableRowGroup rg = new TableRowGroup();
TableRow row = new TableRow();
AddRows(myTable); // Adds 2 rows
TableCell cell = new TableCell(new Paragraph(new Run("Doc1")));
cell.BorderThickness = new Thickness(1);
cell.BorderBrush = Brushes.Black;
// Repeat 4 times
row.Cells.Add(cell);
myTable.RowGroups.Add(rg);
doc.Blocks.Add(myTable);
....
我遇到的问题是,尽管确实可以打印,但它并没有尝试将其放入上述页面。我正在尝试的方法是否可行?如果可以,如何实现?
编辑:
从here看,我相信我真正需要的是一种计算段落高度的方法,这样我就可以设置Padding属性。不幸的是,此链接中提出的解决方案不起作用!
【问题讨论】:
标签: c# .net wpf printing flowdocument