WPF打印FlowDocuments到XPS:打印内容不跨页面延伸.为什么?

Rob*_*Rob 7 printing wpf .net-3.5

我想打印一个FlowDocument带有PrintDialog一个XPS文件.生成的打印内容仅显示在XPS页面的一半上,而不是页面的整个宽度.以下是Windows 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;
}
Run Code Online (Sandbox Code Playgroud)

pageWidth816.0pageHeight1056.0,这应该是比大到足以容纳我的文字.怎么可能出错?


编辑:以下是我尝试过的其他一些事情:

  • 尝试StackPanel在我的Paragraph中添加一个宽大的宽度FlowDocument.文本只是在页面的中间被切断了.
  • 尝试分配FlowDocument.PageWidth大的宽度.同样,文本在页面的中间位置被切断了.

the*_*ix1 13

尝试将ColumnWidth属性设置FlowDocumentpageWidth- 应该修复它.