【发布时间】:2011-06-30 10:57:03
【问题描述】:
我正在尝试将带有PrintDialog 的FlowDocument 打印到XPS 文件中。生成的打印内容似乎只延伸到 XPS 页面的 一半,而不是整个页面的宽度。以下是在 Windows XPS 查看器中生成的 XPS 文档的示例:
(注意:如果我用打印机在普通的 8x11 打印纸上打印它看起来完全一样)
这是我用来打印此文档的代码:
void Print()
{
PrintDialog printDialog = new PrintDialog();
bool? result = printDialog.ShowDialog();
if (!result.HasValue)
return;
if (!result.Value)
return;
double pageWidth = printDialog.PrintableAreaWidth;
double pageHeight = printDialog.PrintableAreaHeight;
FlowDocument flowDocument = CreateFlowDocument(pageWidth, pageHeight);
printDialog.PrintDocument(
((IDocumentPaginatorSource)flowDocument).DocumentPaginator,
"Test print job");
}
FlowDocument CreateFlowDocument(double pageWidth, double pageHeight)
{
FlowDocument flowDocument = new FlowDocument();
flowDocument.PageWidth = pageWidth;
flowDocument.PageHeight = pageHeight;
flowDocument.PagePadding = new Thickness(30.0, 50.0, 20.0, 30.0);
flowDocument.IsOptimalParagraphEnabled = true;
flowDocument.IsHyphenationEnabled = true;
flowDocument.IsColumnWidthFlexible = true;
Paragraph header = new Paragraph();
header.FontSize = 18;
header.Foreground = new SolidColorBrush(Colors.Black);
header.FontWeight = FontWeights.Bold;
header.Inlines.Add(new Run("Title of my document (will be cut off in XPS)";));
flowDocument.Blocks.Add(header);
Paragraph test = new Paragraph();
test.FontSize = 12;
test.Foreground = new SolidColorBrush(Colors.Black);
test.FontWeight = FontWeights.Bold;
test.Inlines.Add(new Run("This text should stretch across the entire width of the page. Let's see if it really does, though."));
flowDocument.Blocks.Add(test);
return flowDocument;
}
pageWidth 是 816.0,pageHeight 是 1056.0,应该更多 足以容纳我的文字。可能出了什么问题?
编辑:以下是我尝试过的其他一些事情:
- 尝试在
FlowDocument中向我的Paragraph添加一个宽大的StackPanel。文本在页面的一半左右被截断。 - 尝试将
FlowDocument.PageWidth分配给较大的宽度。同样,文本在页面的一半左右被截断。
【问题讨论】: