WPF:打印流程文档

发布于 2024-08-16 13:18:09 字数 2546 浏览 6 评论 0原文

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

我对此感到束手无策,我看不出问题所在。如果有人能提供一些线索,我将非常感激。

I'm trying to get a FlowDocument to print. After spending much of the day trying multiple pages I failed and opted for something simpler, but I'm now at a loss to explain when text isn't output to the page. This has to be something I've got snowblind to I think. There are two tables below, placing a converter on both shows that the values are being populated through the DataContext of the FlowDocument.

<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>

The document is printed using:

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");
}

I'm sort of at my wits end with this, I can't see the problem. I'd really appreciate it if anyone could shed some light.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2024-08-23 13:18:09

这本身并不是一个真正的答案,但您是否可以使用 FlowDocumentReader?它已经在 Ctrl-P 上预先连接了打印内容(并公开了“打印”方法)...也就是说,您可以尝试以下操作: 打印 Windows Foundation 演示流程文档

This isn't really an answer per se, but are you in a position to use the FlowDocumentReader? It has the Print stuff already pre-wired on Ctrl-P (and exposes a "Print" method)...that said, you might try this: Printing a Windows Foundation Presentation FlowDocument

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文