我正在尝试将带有FlowDocument
的{{1}}打印到XPS文件中。生成的打印内容仅显示在XPS页面的一半上,而不是页面的整个宽度。以下是Windows XPS查看器中生成的XPS文档的示例:
(注意:如果我用普通8x11打印纸上的打印机打印它看起来完全相同)
这是我用来打印此文档的代码:
PrintDialog
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;
}
816.0 且pageWidth
1056.0 ,应该更多而不是足以容纳我的文本。可能出现什么问题?
编辑:以下是我尝试过的其他一些事情:
pageHeight
中的StackPanel
添加宽度较大的Paragraph
。文字只是在整个页面的中途被切断了。FlowDocument
分配给较大的宽度。同样,文本在页面的中间位置被切断了。答案 0 :(得分:13)
尝试将ColumnWidth
的{{1}}属性设置为FlowDocument
- 应该修复它。