3

我正在尝试打印 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");
}

我有点不知所措,我看不出问题所在。如果有人能提供一些启示,我将不胜感激。

4

1 回答 1

1

这本身并不是一个真正的答案,但是您可以使用 FlowDocumentReader 吗?它已经在 Ctrl-P 上预先连接了 Print 内容(并公开了“Print”方法)......也就是说,你可以试试这个:Printing a Windows Foundation Presentation FlowDocument

于 2009-12-30T20:49:18.207 回答