我有以下几点:
带有滚动查看器和打印按钮的 wpf 窗口。
我正在尝试使用 PrintDialog 打印滚动查看器的内容,但它仅适用于 xps。如果我选择我的打印机或文档编写器,那么最终结果会很糟糕(半页边距、控件剪切等)。
如何在不调整/缩放滚动查看器内容的情况下解决此问题?
最佳答案
为了在 WPF 中进行体面(且相对简单)的打印,您应该使用 FlowDocumentScrollViewer 而不是 ScrollViewer。在 FlowDocumentScrollViewer 内,您可以放置一个 FlowDocument,其中将包含您要打印的内容。
示例 XAML:
<FlowDocumentScrollViewer>
<FlowDocument PagePadding="48">
<Section>
<Paragraph>
<Run Text="sample"/>
</Paragraph>
</Section>
<Section>
<BlockUIContainer>
<my:myUserControl/>
</BlockUIContainer>
</Section>
</FlowDocument>
</FlowDocumentScrollViewer>
'BlockUIContainer' 对象非常适合用于保存可以包含您需要的任何内容的用户控件。 FlowDocument 的“PagePadding”属性设置边距。 48 相当于 1/2 英寸。 (96 dpi)。
示例打印代码:
Dim pd As New PrintDialog
If pd.ShowDialog Then
Dim fd As FlowDocument = docOutput
Dim pg As DocumentPaginator = CType(fd, IDocumentPaginatorSource).DocumentPaginator
pd.PrintDocument(pg, "my document")
End If
关于wpf - 打印 ScrollViewer 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702924/