WPF:打印流程文档
我正在尝试打印 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这本身并不是一个真正的答案,但您是否可以使用 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