我正在尝试打印FlowDocument。在花了大量时间尝试多个页面后,我失败并选择了更简单的东西,但我现在无法解释文本何时没有输出到页面。这一定是我想到的雪盲。下面有两个表,在两个显示器上放置一个转换器,通过FlowDocument的DataContext填充值。
<Table>
<Table.Columns>
<TableColumn Width="Auto"/>
<TableColumn Width="34"/>
<TableColumn Width="Auto"/>
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell>
<Paragraph>
<Image Source="{Binding Icon,Converter={StaticResource IconConverter},ConverterParameter=32}" Width="32" Height="32"/>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock Text="{Binding Name,Converter={StaticResource dbg}}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" FontSize="18" Foreground="Black" />
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<TextBlock Text="Static text works fine" TextAlignment="Right" />
<TextBlock Text="Static text works here too fine" TextAlignment="Right" />
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
<BlockUIContainer>
<Line Stretch="Fill" Stroke="DarkBlue" X2="1"/>
</BlockUIContainer>
使用以下方式打印文档:
PrintDialog dlg = new PrintDialog();
if(dlg.ShowDialog() == true) {
int margin = 5;
Size pageSize = new Size(dlg.PrintableAreaWidth - margin * 2, dlg.PrintableAreaHeight - margin * 2);
FlowDocument document = WPFUtils.LoadFlowDocument(System.IO.Path.Combine(Utils.GetApplicationPath(), "AccountPrintView.xaml"), account); // loads the document from a XAML file
IDocumentPaginatorSource paginator = document as IDocumentPaginatorSource;
paginator.DocumentPaginator.PageSize = pageSize;
dlg.PrintDocument(paginator.DocumentPaginator, "Print output");
}
我有点想到这个,我看不出问题。如果有人能说清楚的话,我真的很感激。
答案 0 :(得分:1)
这本身并不是一个真正的答案,但您是否可以使用FlowDocumentReader?它已经在Ctrl-P上预先连接了打印内容(并公开了“打印”方法)......说,您可以试试这个:Printing a Windows Foundation Presentation FlowDocument